Plugging into Plugins
      Josh Harrison
         @joshh
About Me
I work for 10up working on awesome
WordPress projects

I have a wife and 3 kids.

I live in St. George UT.

I just finished my backyard after working on it
for 4 months.
WordPress Plugins


   What comes to mind?
"Here is something I
    created. Maybe
somebody else will find it
        useful."
Plugins are
 Frameworks
Not Blueprints
It’s not about core
plugins, it’s about
plugin developers
   making better
      plugins.
Make your plugins
extensible and be nice to
    other developers
Use the WordPress Core API.
WordPress Core APIs
●   Database API
●   HTTP API
●   Shortcode API
●   Transients API
●   Shortcode API

And many more....
Create your own actions and filters.
do_action
if ( $valid_request ) {
   if ( $status == 'approve' ) {
       // dev can remove or add to
       do_action( 'new_user_approve_approve_user' );
   } else if ( $status == 'deny' ) {
       do_action( 'new_user_approve_deny_user' );
   }
}
apply_filters
$welcome = sprintf( __( 'Welcome to %s. This
site is accessible to approved users only.
To be approved, you must first register.',
'new_user_approve' ), get_option( 'blogname'
) );

$welcome = apply_filters(
'new_user_approve_welcome_message', $welcome
);
Allow theme developers to override
         plugin templates.
// Include template - can be overriden by a theme!
$template_name = 'wp-core-contributions-widget-template.php';
$path = locate_template( $template_name );
if ( empty( $path ) ) {
   $path = WP_CORE_CONTRIBUTIONS_WIDGET_DIR . 'inc/' .
$template_name;
}
Create template functions.
/**
 * Display the permalink for the current post.
 *
 * @since 1.2.0
 * @uses apply_filters() Calls 'the_permalink' filter on
the permalink string.
 */
function the_permalink() {
    echo apply_filters('the_permalink', get_permalink());
}
Create utility methods.
/**
 * Creates a redirect post, this function will be useful
for import/exports scripts
 * @param string $redirect_from
 * @param string $redirect_to
 * @param int $status_code
 * @since 1.3
 * @uses wp_insert_post, update_post_meta
 * @return int
 */
public function create_redirect( $redirect_from,
$redirect_to, $status_code ) {
    ....
}
Decisions not options.
Actions and filters are even better.
/** If you hardcode a WP.com API key here, all key config
screens will be hidden */
if ( defined('WPCOM_API_KEY') )
   $wpcom_api_key = constant('WPCOM_API_KEY');
else
   $wpcom_api_key = '';
Anything else?
Child Plugins

Plugin Mashups
Caution
You'll have to keep you plugin up to date
Disadvantages
The wordpress.org repository does not support
plugin dependencies

What if a child plugin is installed, should the
parent plugin be installed as well?
What can I do now?
● Update your plugins

● Send an update to plugin authors

● Fork it
Resources
● Pippin Williamson
● Michael Fields
● Brandon Dove - The Pluggable Plugin
● WordPress Plugins as Frameworks

Plugging into plugins

  • 1.
    Plugging into Plugins Josh Harrison @joshh
  • 2.
    About Me I workfor 10up working on awesome WordPress projects I have a wife and 3 kids. I live in St. George UT. I just finished my backyard after working on it for 4 months.
  • 3.
    WordPress Plugins What comes to mind?
  • 6.
    "Here is somethingI created. Maybe somebody else will find it useful."
  • 8.
  • 11.
    It’s not aboutcore plugins, it’s about plugin developers making better plugins.
  • 12.
    Make your plugins extensibleand be nice to other developers
  • 13.
  • 14.
    WordPress Core APIs ● Database API ● HTTP API ● Shortcode API ● Transients API ● Shortcode API And many more....
  • 15.
    Create your ownactions and filters.
  • 16.
    do_action if ( $valid_request) { if ( $status == 'approve' ) { // dev can remove or add to do_action( 'new_user_approve_approve_user' ); } else if ( $status == 'deny' ) { do_action( 'new_user_approve_deny_user' ); } }
  • 17.
    apply_filters $welcome = sprintf(__( 'Welcome to %s. This site is accessible to approved users only. To be approved, you must first register.', 'new_user_approve' ), get_option( 'blogname' ) ); $welcome = apply_filters( 'new_user_approve_welcome_message', $welcome );
  • 18.
    Allow theme developersto override plugin templates.
  • 19.
    // Include template- can be overriden by a theme! $template_name = 'wp-core-contributions-widget-template.php'; $path = locate_template( $template_name ); if ( empty( $path ) ) { $path = WP_CORE_CONTRIBUTIONS_WIDGET_DIR . 'inc/' . $template_name; }
  • 20.
  • 21.
    /** * Displaythe permalink for the current post. * * @since 1.2.0 * @uses apply_filters() Calls 'the_permalink' filter on the permalink string. */ function the_permalink() { echo apply_filters('the_permalink', get_permalink()); }
  • 22.
  • 23.
    /** * Createsa redirect post, this function will be useful for import/exports scripts * @param string $redirect_from * @param string $redirect_to * @param int $status_code * @since 1.3 * @uses wp_insert_post, update_post_meta * @return int */ public function create_redirect( $redirect_from, $redirect_to, $status_code ) { .... }
  • 24.
    Decisions not options. Actionsand filters are even better.
  • 25.
    /** If youhardcode a WP.com API key here, all key config screens will be hidden */ if ( defined('WPCOM_API_KEY') ) $wpcom_api_key = constant('WPCOM_API_KEY'); else $wpcom_api_key = '';
  • 26.
  • 27.
  • 28.
    Caution You'll have tokeep you plugin up to date
  • 29.
    Disadvantages The wordpress.org repositorydoes not support plugin dependencies What if a child plugin is installed, should the parent plugin be installed as well?
  • 30.
    What can Ido now? ● Update your plugins ● Send an update to plugin authors ● Fork it
  • 31.
    Resources ● Pippin Williamson ●Michael Fields ● Brandon Dove - The Pluggable Plugin ● WordPress Plugins as Frameworks