• Resolved webstan

    (@webstan)


    Hello,

    I am busy trying to learn more about making plugins. I want to make my plugin unable to activate if the version number of wordpress is lower then the one i give. I used the following code:

    register_activation_hook( __FILE__, 'st_testplugin_install' );
    
    function st_testplugin_install() {
    	if ( version_compare( get_bloginfo( 'version' ), '4.1', '<' ) ) {
    		deactivate_plugins( plugin_basename( __FILE__ ) );
    	}
    }

    After using this code my plugin is still able to activate. It seems like it doesn’t run the deactivate_plugins somehow. My wordpress version is 4.0 so lower then the 4.1 i gave in the version_compare function. I was wondering if someone could help me with this and can tell me what I am doing wrong.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter webstan

    (@webstan)

    Im a beginner on plugins anyone have idea to fix this problem?

    Moderator bcworkz

    (@bcworkz)

    The reason deactivate_plugins() does not work is when the activation hook fires, your plugin is not yet truly activated, so there is nothing to deactivate.

    To prevent activation in your activation hook callback, it merely needs to die() or wp_die() with an appropriate message to update WP to the current version.

    Thread Starter webstan

    (@webstan)

    Alright I understand why this doesn’t work then. Thank you for your answer.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘deactivate_plugins after version check not working’ is closed to new replies.