Plugging into plugins

31

Click here to load reader

Transcript of Plugging into plugins

Page 1: Plugging into plugins

Plugging into PluginsJosh Harrison

@joshh

Page 2: Plugging into plugins

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.

Page 3: Plugging into plugins

WordPress Plugins

What comes to mind?

Page 4: Plugging into plugins
Page 5: Plugging into plugins
Page 6: Plugging into plugins

"Here is something I created. Maybe

somebody else will find it useful."

Page 7: Plugging into plugins
Page 8: Plugging into plugins

Plugins are Frameworks

Not Blueprints

Page 9: Plugging into plugins
Page 10: Plugging into plugins
Page 11: Plugging into plugins

It’s not about core plugins, it’s about plugin developers

making better plugins.

Page 12: Plugging into plugins

Make your plugins extensible and be nice to

other developers

Page 13: Plugging into plugins

Use the WordPress Core API.

Page 14: Plugging into plugins

WordPress Core APIs

● Database API● HTTP API● Shortcode API● Transients API● Shortcode API

And many more....

Page 15: Plugging into plugins

Create your own actions and filters.

Page 16: Plugging into plugins

do_actionif ( $valid_request ) {

if ( $status == 'approve' ) {// dev can remove or add todo_action( 'new_user_approve_approve_user' );

} else if ( $status == 'deny' ) {do_action( 'new_user_approve_deny_user' );

}}

Page 17: Plugging into plugins

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 );

Page 18: Plugging into plugins

Allow theme developers to override plugin templates.

Page 19: Plugging into plugins

// 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;}

Page 20: Plugging into plugins

Create template functions.

Page 21: Plugging into plugins

/** * 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());}

Page 22: Plugging into plugins

Create utility methods.

Page 23: Plugging into plugins

/** * 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 ) {

....}

Page 24: Plugging into plugins

Decisions not options.Actions and filters are even better.

Page 25: Plugging into plugins

/** 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 = '';

Page 26: Plugging into plugins

Anything else?

Page 27: Plugging into plugins

Child Plugins

Plugin Mashups

Page 28: Plugging into plugins

CautionYou'll have to keep you plugin up to date

Page 29: Plugging into plugins

The wordpress.org repository does not support plugin dependencies

What if a child plugin is installed, should the parent plugin be installed as well?

Disadvantages

Page 30: Plugging into plugins

● Update your plugins

● Send an update to plugin authors

● Fork it

What can I do now?