[wp-trac] [WordPress Trac] #13581: Plugin Initialization fails in PHP 4 (WP 3.0-Beta 2) - initializes fine under PHP 5 or PHP 4 (WP 2.9.2)

WordPress Trac wp-trac at lists.automattic.com
Fri May 28 03:29:53 UTC 2010


#13581: Plugin Initialization fails in PHP 4 (WP 3.0-Beta 2) - initializes fine
under PHP 5  or PHP 4 (WP 2.9.2)
--------------------------+-------------------------------------------------
 Reporter:  bennebw       |       Owner:  westi            
     Type:  defect (bug)  |      Status:  new              
 Priority:  normal        |   Milestone:  3.0              
Component:  Plugins       |     Version:  3.0              
 Severity:  normal        |    Keywords:  reporter-feedback
--------------------------+-------------------------------------------------

Comment(by bennebw):

 Replying to [comment:4 ryan]:
 > Plugins can't assume they are running from global scope. That plugin
 needs to declare $wpdb as global.
 Just for kicks, I tried to Install '''NextGen Gallery''' under PHP 4, WP
 3.0 Beta-2.  '''Same problem'''.  I'll be honest, that makes me feel a wee
 bit better that it's not limited to my plugin, because I spent several
 hours trying to debug it last night, but couldn't figure it out without
 know what might have changed in WP 3 that might be causing the issue.

 $wpdb is declared global on line 22.  As I mentioned, it loads fine in PHP
 5 under WP 3.0, but PHP 4 is having real problems.

 Here's the code that gets processed in PhotoSmash up to the point the
 $wpdb is declared global:

 Starting in the main plugin file, the add_action to trigger the
 initialization class:


 //Call the INIT function whenever the Plugin is activated
 add_action('activate_photosmash-galleries/bwb-photosmash.php',
 array(&$bwbPS, 'init'));


 // Now the function that gets run in the $bwbPS object to load the
 Initialization class:

 //Called when plugin is activated
         function init(){

                 require_once(WP_PLUGIN_DIR . "/photosmash-galleries/admin
 /bwbps-init.php");
                 $bwbpsinit = new BWBPS_Init();
         }

 // Now the start of the Initialization Class:

 //Code for initializing BWB-PhotoSmash plugin when it is activated in
 Wordpress Plugins admin page
 class BWBPS_Init{

         var $adminOptionsName = "BWBPhotosmashAdminOptions";

         //Constructor
         function BWBPS_Init(){
                 //Create the PhotoSmash Tables if not exists

                 $psOptions = get_option($this->adminOptionsName);

                 $label = $psOptions['tag_label'] ?
 esc_attr($psOptions['tag_label']) : "Photo tags";
                  $slug = $psOptions['tag_slug'] ? $psOptions['tag_slug'] :
 "photo-tag";

                  register_taxonomy( 'photosmash', 'post', array(
 'hierarchical' => false, 'label' => __($label, 'series'), 'query_var' =>
 'bwbps_wp_tag', 'rewrite' => array( 'slug' => $slug ) ) );

                         global $wp_rewrite;
                         $wp_rewrite->flush_rules();

                         global $wpdb;

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

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13581#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list