Answers for "Plugin Activation Check"

0

Plugin Activation Check

/**
 * Deactivate plugin example class.
 */
class WPDocs_Deactivate_Plugin {
 
    /**
     * Constructor.
     */
    public function __construct() {
        register_activation_hook( __FILE__, array( $this , 'activate' ) );
    }
 
    /**
     * Attempts to activate the plugin if at least PHP 5.4.
     */
    public function activate() {
        // Check PHP Version and deactivate & die if it doesn't meet minimum requirements.
        if ( version_compare( PHP_VERSION, '5.4', '<=' ) ) {
            deactivate_plugins( plugin_basename( __FILE__ ) );
            wp_die( __( 'This plugin requires PHP Version 5.4 or greater.  Sorry about that.', 'textdomain' ) );
        }
         
        // Do activate Stuff now.
    }
}
new WPDocs_Deactivate_Plugin();
Posted by: Guest on January-13-2022

Browse Popular Code Answers by Language