WordPress.org

Ready to get started?Download WordPress

Forums

[ Feature Request ] (Error-) messages on plugin activation / deactivation (6 posts)

  1. drumatic
    Member
    Posted 3 years ago #

    I guess it would be useful when people can add error messages when a plugin installation failed or to give further instructions to the user.

    I offer to implement this according to wp design standards if i get the opportunity.

    thanks and greets

    drumatic

  2. drumatic
    Member
    Posted 3 years ago #

    i did a little hack to output messages:

    add this to your plugin_activation function:

    add_option( 'myplugin_msg', 'Error: Something went wrong');

    function myplugin_message() {
    	if ( $msg = get_option('myplugin_msg') && $_REQUEST['activate'] == 'true' ) {
    
    		echo '
    		<script type="text/javascript">
    			var el = document.getElementById(\'message\');
    			el.innerHTML = el.innerHTML + \'<p>'. $msg . '</p>\';
    		</script>';		
    
    		delete_option('myplugin_msg');
    	}
    }
    
    add_action( 'wp_print_footer_scripts', 'myplugin_message' );
  3. WordPress already has error messages when you try to activate a plugin that can't be activated. And many plugins already hook into things to tell you why and what to do (WP Super Cache comes to mind).

  4. drumatic
    Member
    Posted 3 years ago #

    yes it get's activated most of the times, even when it can't create a table or something, but i can't tell the user why it happened..

    i will take a look at that plugin thanks.

    but it would be nicer if you could return a WP_Error or string that get's displayed, without nasty hacks..

  5. Mike Toppa
    Member
    Posted 3 years ago #

    This is a late reply, but may be useful for anyone else struggling with this. This is my solution:


    function wpSimpleTestActivate() {
    if (version_compare(get_bloginfo('version'), '3.0', '<')) {
    trigger_error('You must have at least WordPress 3.0 to use SimpleTest for WordPress', E_USER_ERROR);
    }
    }

    Activation runs in a separate process, so triggering a PHP error will not affect anything else. The error message is shown in the activation status message. It's shown as a PHP fatal error, so it's not an elegant solution, but I have not found any other way to return an activation status message.

    Also, I'm not sure what Ipstenu is referring too. I took a quick look at WP Super Cache - it's activation function has absolutely nothing in it.

  6. Newman
    Member
    Posted 3 years ago #

    Due to how WordPress activates plugins, you can effectively control what is put into the message box by first triggering an E_USER_ERROR and then displaying a more friendly error message.

    I have a short post about it here: Custom WordPress Plugin Activation Error Messages

    It allows you to display whatever text you want in the message box without running any javascript or other complex code.

Topic Closed

This topic has been closed to new replies.

About this Topic