Under the Hood
The entire plugin is wrapped in a class
statement, and requires a __construct()
function to initialize everything.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | function __construct() { add_shortcode( ‘tt’, array( $this, ‘avp_texttoggle_shortcode’ ) ); add_shortcode( ‘tt_all’, array( $this, ‘avp_texttoggle_all_shortcode’ ) ); add_shortcode( ‘tt_part’, array( $this, ‘avp_texttoggle_part_shortcode’ ) ); wp_register_script( ‘avp-texttoggle-js’, ( plugins_url( ‘js/avp-texttoggle-min.js’, __FILE__ ) ), array( ‘jquery’ ) ); wp_register_script( ‘avp-texttoggle-js-all’, ( plugins_url( ‘js/avp-texttoggle-all-min.js’, __FILE__ ) ), array( ‘jquery’ ) ); wp_register_script( ‘avp-texttoggle-js-part’, ( plugins_url( ‘js/avp-texttoggle-part-min.js’, __FILE__ ) ), array( ‘jquery’ ) ); wp_register_style( ‘avp-texttoggle-css’, ( plugins_url( ‘css/avp-texttoggle-min.css’, __FILE__ ) ) ); add_action( ‘admin_init’, array( $this, ‘avp_texttoggle_admin_init’ ) ); } |
The first block of three add_shortcode
function calls define the three shortcodes provided by the plugin.
Each shortcode also has an associated JavaScript / JQuery script file and defined by the wp_register_script
function. Each shortcode also uses the same CSS file as defined by the wp_register_style
function. Note that all JS and CSS files are minimized.
The final statement, add_action
, sets up a routine that adds information to the plugin description on the Plugin admin page. The associated routines are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /* * Add functionality to put the links in the plugin listing entry */ function avp_texttoggle_admin_init() { global $pagenow; /* * Add details to the plugin description * Details only appear when plugin is activated */ if ( in_array( $pagenow, array( ‘plugins.php’, ) ) ) { add_filter( ‘plugin_row_meta’, array( $this, ‘avp_texttoggle_admin_init_meta_links’ ), 10, 2 ); } } /* * Add links to plugin description section */ function avp_texttoggle_admin_init_meta_links( $links, $file ) { /* * Use basename for parent sub-directory name and file name, must be same */ if ( basename( __FILE__ ) == basename( $file ) ) { array_push( $links, ‘<a href=“http://wordpress.org/extend/plugins/texttoggle/”>Download</a>’ ); array_push( $links, ‘<a href=“https://www.paypal.com/cgi-bin/webscr?cmd=s‑xclick&hosted_button_id=THLBLFT4BV7E2”>Donate</a>’ ); } return $links; } |
The short URL of the present article is: http://www.terryobrien.me/kUWob
Personal Links
My Amazon Wishlist
My DeviantArt Gallery
My Facebook Page
My Goodreads Bookshelf
My Smashwords Catalog
My Twitter Feed
My WordPress Profile