[wp-trac] Re: [WordPress Trac] #7671: Plugin fatal error yields irrelevant error message from WordPress

WordPress Trac wp-trac at lists.automattic.com
Wed Sep 3 13:05:54 GMT 2008


#7671: Plugin fatal error yields irrelevant error message from WordPress
-------------------------------+--------------------------------------------
 Reporter:  omry               |        Owner:  anonymous
     Type:  defect             |       Status:  closed   
 Priority:  normal             |    Milestone:           
Component:  General            |      Version:           
 Severity:  normal             |   Resolution:  invalid  
 Keywords:  reporter-feedback  |  
-------------------------------+--------------------------------------------
Changes (by DD32):

  * status:  new => closed
  * version:  2.6 =>
  * resolution:  => invalid
  * milestone:  2.8 =>

Comment:

 Ahhh, Now i understand, Here was me thinking that the error of '123' was
 showing up and not wanted..

 That PHP error was due to trying to activate an allready activated plugin,
 Due to you just using die(), WordPress marked it as activated, however
 never got to redirect the user to say that it had been activated.
 The Workflow is like this:
 {{{
 Set the user to redirect to a failure-to-activate page
 Include the plugin
 <At this point, if theres a fatal error, it'll die and redirect>
 Mark the plugin as activated
 Run the activation hook
 Redirect user to activated-ok page instead of failure page
 }}}

 If you hook in on the activation hook you'll break the workflow and end up
 in odd places.

 Using deactivate_plugins() and wp_die can achieve what you're after, See
 this example plugin:
 {{{
 <?php
 /*
 Plugin Name: Newer WordPress Plugin
 Plugin URI: http://dd32.id.au/wordpress-plugins/?plugin=newer-wordpress-
 test-plugin
 Description: Tests non-activation. Requires WordPress 2.4 or
 later(deactivate_plugins() function call), Requires WordPress 2.8 or later
 to activate
 Author: Dion Hulse
 Version: 1.0
 */

 register_activation_hook(__FILE__, 'nwp_act');

 function nwp_act(){
         global $wp_version;
         if( version_compare( $wp_version, '2.7.9', '>=') )
                 return; //Its WordPress 2.8

         $message = '<h1>Newer WordPress Plugin</h1> <p>This plugin
 requires WordPress 2.8, which you do not have.</p> <p>Click <a
 href="plugins.php">here</a> to go back to plugins list</p>';

         if( function_exists('deactivate_plugins') )
                 deactivate_plugins(__FILE__);
         else
                 $message .= '<p><strong>Please deactivate this plugin
 Immediately</strong></p>'; //We couldnt automatically deactivate without
 messing with array, for Wordpress < 2.4
         wp_die($message);
 }

 ?>
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/7671#comment:3>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list