[wp-hackers] Codex on 2.5 plugin/theme migration...

Jacob Santos wordpress at santosj.name
Fri Feb 15 03:01:33 GMT 2008


Ryan Boren wrote:
> On Thu, Feb 14, 2008 at 3:38 PM, Jennifer Hodgdon <yahgrp at poplarware.com> wrote:
>   
>> We might need a Codex article on migrating plugins and themes to 2.5.
>>  The last "migrating" article was for 2.1:
>>    http://codex.wordpress.org/Migrating_Plugins_and_Themes_to_2.1
>>
>>  The only issues I know about right now for 2.5:
>>
>>  - Plugins are activated in a non-global scope, so you may have to add
>>  a couple of 'global' declarations to your plugin to get the activation
>>  to work.
>>     
>
> We can register some common globals within activate_plugin() and in
> includes files where they are used outside of a function such as
> schema.php.
>   

This would only be useful if the plugin author has their code outside of 
a function, which they shouldn't be doing anyway. I know of one plugin 
which makes this mistake, however, most plugin code, should contain its 
own functions and use add_action() and add_filter() functions. In any 
case, after thinking more about what you stated in the ticket and what I 
realized, it wouldn't matter if you place it in activate_plugin(). If it 
was such a hassle, then it would have broken all plugins in existence 
and it hasn't.


function bugtest_test_activate() {
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
}

should be:

function bugtest_test_activate() {
    global $wpdb;
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
}

However, if it existed outside of that function, like this:

require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

function bugtest_test_activate() {
    global $wpdb;
   
}

Then it would be activate_plugin()'s fault. However, since the 
responsibility is on the plugin author and not the core of WordPress, it 
should then be up to the plugin author to first test for whether $wpdb 
is set and if not declare it a global.

if( !isset( $wpdb ) )
    global $wpdb; // Inside function scope.
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

function bugtest_test_activate() {
    global $wpdb;
   
}

This problem should not have been solely isolated on WordPress 2.5, 
since activate_plugins() has existed long before 2.5. Sprinkling 
extraneous global declarations where the variables should already be in 
global scope will confuse the hell out of developers ("Isn't this a 
bug?" No, some plugin author needs it).

This is all in my humble opinion. You learn something new every day it 
seems.


I agree with the rest of Jennifer's points as, there have been many 
times where I need a quick reference guide and the 2.1 information was 
practically worthless when dealing with 2.3 and 2.2 for that matter. 
Widgets as far as I can see are fairly easy to grasp, once you have a 
working example or two. There is also probable that the information 
already exists on the Codex, but isn't referenced anywhere or in a hard 
to find location, as is a lot of great priceless and awesome resources. 
I think it would help if the codex was more organized, but that would 
require an army.

-- 

Jacob Santos

http://www.santosj.name - blog
http://funcdoc.wordpress.com - WordPress Documentation Blog/Guide Licensed under GPLv2

Also known as darkdragon and santosj on WP trac.



More information about the wp-hackers mailing list