Deactivate WordPress Plugin if URL is

I have installed SMS Validator so everyone who register to my site must enter there phone number to sign-up

Now I have created a new function (link) to add a different type user role if users sign-up by visit this link:
http://example.com/wp-login.php?action=register&role=vip_member

Read More

I want to turn OFF SMS Validator ONLY for this URL link.

Is it possible to do it somehow?


Success so far using mathielo code:

// Activate SMSGlobal 
function activate_plugin_conditional() {
if ( !is_plugin_active('sms-validator-SMSG/sms-validator.php') ) {
    activate_plugins('sms-validator-SMSG/sms-validator.php');
    }
}

// Deactivate SMSGlobal
function deactivate_plugin_conditional() {
if ( is_plugin_active('sms-validator-SMSG/sms-validator.php') ) {
    deactivate_plugins('sms-validator-SMSG/sms-validator.php');
    }
}

// Now you in fact deactivate the plugin if the current URL matches your desired URL
if(strpos($_SERVER["REQUEST_URI"], '/wp-login.php?action=register&role=vip_member') !== FALSE){
// Calls the disable function at WP's init
    add_action( 'init', 'deactivate_plugin_conditional' );
}

if(strpos($_SERVER["REQUEST_URI"], '/wp-login.php?action=register&role=seller') !== FALSE){
// Calls the enable function at WP's init
    add_action( 'init', 'activate_plugin_conditional' );
}

if(strpos($_SERVER["REQUEST_URI"], '/wp-login.php?action=register&role=provider') !== FALSE){
// Calls the enable function at WP's init
    add_action( 'init', 'activate_plugin_conditional' );
}

So far this code helps me to activate and deactivate this plugin in this 3 selected URLs.
But I want this plugin to be activated if is deactivated in this links: /wp-login.php and /wp-login.php?action=register

But if I set it to activate on URL: /wp-login.php then it will not be deactivated on URL: /wp-login.php?action=register&role=vip_member where I need it to be deactivated.

Related posts

Leave a Reply

1 comment

  1. You could match the current URL using $_SERVER["REQUEST_URI"] and then disable the plugin in functions.php:

    // Just creating the function that will deactivate the plugin
    function deactivate_plugin_conditional() {
        if ( is_plugin_active('plugin-folder/plugin-name.php') ) {
            deactivate_plugins('plugin-folder/plugin-name.php');    
        }
    }
    
    // Now you in fact deactivate the plugin if the current URL matches your desired URL
    if(strpos($_SERVER["REQUEST_URI"], 'my-disable-url') !== FALSE){
        // Calls the disable function at WP's init
        add_action( 'init', 'deactivate_plugin_conditional' );
    }
    

    Note: Be aware that php’s strpos() may return 0 if the needle matches the given string at position zero, so the condiional !== is needed.

    Got my references from here and implemented the URL check. Check out the current value of $_SERVER["REQUEST_URI"] at your desired URL for a perfect match.


    Answering the second part of your question:

    You could improve your code removing the last 2 ifs and complementing the first one with an else, like so:

    // Now you in fact deactivate the plugin if the current URL matches your desired URL
    if(strpos($_SERVER["REQUEST_URI"], '/wp-login.php?action=register&role=vip_member') !== FALSE){
        // Calls the disable function at WP's init
        add_action( 'init', 'deactivate_plugin_conditional' );
    }
    // Otherwise, for any other URLs the plugin is activated if it's currently disabled.
    else{
        add_action( 'init', 'activate_plugin_conditional' );
    }
    

    Now for every URL that is not the one you wish to deactivate the plugin, your code will enable the plugin if it is currently inactive.