[wp-hackers] error message on plugin activation, how to ?

DD32 wordpress at dd32.id.au
Sun Dec 14 23:05:05 GMT 2008


Here's a test plugin which achieves that. The error message is shown in the
"Fatal error" scrape area:

<?php
/*
Plugin Name: Newer WordPress Plugin
Plugin URI:
http://dd32.id.au/wordpress-plugins/?plugin=newer-wordpress-test-plugin
Description: Tests non-activation.
Author: Dion Hulse
Version: 1.0

Requires WordPress 2.4 or later(deactivate_plugins() function call),
Requires WordPress 2.9 or later to activate

*/

register_activation_hook(__FILE__, 'nwp_act');

function nwp_act(){
    global $wp_version;
    if( version_compare( $wp_version, '2.8.9', '>=') )
        return; //Its WordPress 2.9+

    $message = '<p>This plugin requires WordPress 2.9, which you do not
have.</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.5
    die($message);
}

?>

2008/12/15 andré renaut <andre.renaut at gmail.com>

> >
> > Hi,
> >
> > When activating a plugin, how can i display an error message if some
> system
> > requirements are not ok.
> >
> > thanks
> >
> > add_action('activate_' . 'myplugin.php',    'install');
> >
> > function install() {
> >    if (system_requirements()) do_install();
> >    else                                                      // ==>
> > 'system requirements ko'
> > }
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list