Automattic / media-explorer

With Media Explorer, you can now search for tweets and videos on Twitter and YouTube directly from the Add Media screen in WordPress.
126 stars 31 forks source link

Add actions/filters for third party devs #28

Closed paulgibbs closed 11 years ago

paulgibbs commented 11 years ago

There are 0 actions and only a few filters for third party devs to use to extend the plugin. We should audit the code and add actions and filters where appropriate.

An example of where this will help is https://github.com/Automattic/media-explorer/blob/master/extended-media-manager.php#L29 -- per the documentation on http://vip.wordpress.com/documentation/extending-media-explorer/, we say:

Create a folder under the services/ directory

Obviously this can't be done on WordPress.com and most sites, and at the very least it adds a manual step to the installation of all plugins that extend the media manager.

Suggest something like this:

function pg_init() {
    foreach ( glob( dirname( __FILE__ ) . '/services/*/service.php' ) as $service )
        include $service;

    do_action( 'pg_init' );
}
add_action( 'init', 'pg_init' );

// Then in my add-on plugin or theme, I can do this:
function pg_plugin_media_explorer_addon() {
    require 'my_addon.php'; // all the media-explorer extension will be in this file
}
add_action( 'pg_init', 'pg_plugin_media_explorer_addon' );
johnbillion commented 11 years ago

How does this look? https://github.com/Automattic/media-explorer/commit/5c23906ae96d87acb559472cb640d002698fbf5e (hooks branch)

We're now firing a emm_init action on the plugins_loaded hook (actually, emm_loaded might be a better name here) and then only loading the services (via the existing emm_services filter) on the init hook.

simonwheatley commented 11 years ago

Can we filter the tabs and labels, add an action in the load method to enqueue/sequence JavaScript and CSS, etc? Somehow fire these hooks from the base class and suffix the class name ala the admin load actions. I'm thinking of people wanting to alter services, rather than add their own. In a motorway carpark, so guessing these possibility without decent code access. :)

paulgibbs commented 11 years ago

@johnbillion - looks like that's on the right track.

@simonwheatley - yes we should action/filterify all the things.

pepegar commented 11 years ago

I've created an action for enqueuing scripts in ca27f8a402d2dda89ff61dfed86554ef54d13c0c and filters for labels and tabs in 98556049f306fa552ca06e9d39882a3c47ee3f6d on hooks branch.