[wp-hackers] Improving Plugin (and Theme) metadata

DD32 wordpress at dd32.id.au
Fri Jan 25 09:58:33 GMT 2008


On Fri, 25 Jan 2008 19:52:39 +1100, Peter Westwood <peter.westwood at ftwr.co.uk> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Some design improvements below after sleeping on the idea.
>
> Peter Westwood wrote:
> | Some goals for the implementation:
> |
> | 1. Provide the ability for plugin/theme meta data to be translated.
> | 2. Seperate the meta-data from the rest of the plugin/theme.
> | 3. Combine the parsing code used for plugins and themes.
> | 4. Allow for extensible metadata.
> |
> | Requirements:
> |
> | 1. Use gettext so as to integrate with the rest of a plugins translation.
> | 2. Protect against malformed plugins breaking the admin with PHP errors.
> |
> | Possible Solution:
> |
> | 1. Plugins have to be stored within a folder under PLUGINDIR.
> | 2. All plugins have a metadata.php file.
> | 3. metadata.php file is included by the admin plugin page (not in global
> | scope to keep it clean) as a way of discovering the available plugins.
> |
>
> Rather than a metadata.php file we move back to single file plugins.
>
> When we are discovering plugins we define('WP_PLUGIN_DISCOVER',true);
> the simple plugin file my_plugin.php which is in the root PLUGINDIR becomes:
>
> <?php
>
> load_plugin_textdomain();
>
> register_plugin( __FILE__,
> ~                 __('Description'),
> ~                 __('Plugin Name'),
> ~                'http://example.com',
> ~                'Joe Bloggs',
> ~                 'http://joe.bloggs.name'),);
>
> if ( !(defined('WP_PLUGIN_DISCOVER') )
> {
> 	//All plugin code goes here including includes.
> }
>
> //The End
> ?>
>
> You can still use a folder and a metadata.php if you want.


One thing i dont like about all these suggestions is having an extra file to rely on that will be automatically loaded..

I like this solution though, Kind of, However it could work rather ok.

Rather than defining a value, any good plugin shouldnt do any install actions on anything other than the activation hook, So what i'm thinking is maybe there needs to be a discovery mode, where no init/activation/etc hooks are run, only discovery hooks/actions are run.

So instead:
* Plugins page is loaded, Notices that there are plugins which it has not seen before
  * Redirects to a discovery page instead(Note: This is NOT done inline with the usual admin interface for a reason -- We dont want a failed plugin, or a plugin silently modifying the admin page while its loaded) 
  * Redirection is placed for redirecting back to plugins page afterwards(incase plugin fails to load, or does something stupid and unexpected)
  * Discovery page includes the plugin file
  * Discovery page does NOT run admin_init/init/activate hooks, nothing that a plugin should attach itself to currently
  * Discovery page runs a hook "discovery_<plugin_file>"
  * Plugin hooks onto discovery:

<?php
/*
* Meta: Data Still here as normal as a back-fall
*
*/

add_action('init','example_init');
function example_init(){
//modify wordpress behaviour
}

if( function_exists('register_plugin_discovery') ){
   register_plugin_discovery(__FILE__,'example_discovery');
   //Or For those people who do not want to wrap it in a function exists call and retain backwards compatibility:
   // add_action('discovery_' . __FILE__, 'example_discovery');
   function example_discovery(){
	load_plugin_textdomain();
	register_plugin( __FILE__,
		__('Description'),
		__('Plugin Name'),
		'http://example.com',
		'Joe Bloggs',
		'http://joe.bloggs.name');
	//Other things which could be used for feature creep in peoples minds, but shouldnt be implemented
	register_plugin_requirement('PHP','5');
	register_plugin_coniguration_page('options','example plugin');
	
}}

?>
  * Repeat for any more plugins that were also found, assuming no errors have occured yet..
  * Discovery complete, Information needed saved, Hopefully no changes were made to WP. 
  * Redirection takes place back to plugins page (maybe ?discovery=success atthis point to show it went right through)
 * Plugins page is loaded again, Any translated stuff is shown.

Is there any stats on the current spread of English vs. Localised versions of wordpress out there?
How about the number of plugins which currently have translations available?



I apologise to those people who i've just repeated.


More information about the wp-hackers mailing list