Plugging into plugins

Post on 17-May-2015

1.308 views 1 download

Tags:

Transcript of Plugging into plugins

Plugging into PluginsJosh 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_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' );

}}

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

CautionYou'll have to keep you plugin up to date

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

● Update your plugins

● Send an update to plugin authors

● Fork it

What can I do now?