WordPress.org

Ready to get started?Download WordPress

Forums

WP Mobile Detect
[resolved] Function to deactivate plugins on devices (4 posts)

  1. terranova23
    Member
    Posted 1 year ago #

    Hi there!

    Thanks for this great plugin, with any luck this will be JUST what I was looking for!

    I'm trying to write a function to disable a specific plugin on mobile devices, as this plugin creates an iframe that devices are unable to scroll. I've tried fixing the problem via CSS, and now it seems disabling the plugin itself is a much better solution. Here is my code:

    function deactivate_plugin_conditional() {
        if ( wpmd_is_device() ) {
        deactivate_plugins('audiobar/audiobar.php');
        }
    }
    add_action( 'admin_init', 'deactivate_plugin_conditional' );

    I'm no expert in PHP, and this is something I cobbled together from various things I've read, so it may be the code itself that is causing the problem. I've tried placing this in several PHP files (theme functions, wp config, index, etc.) and no luck.

    So my question is - am I using the function from your plugin correctly? Any suggestions on how I might get this to work?

    Thanks so much!
    Rory

    http://wordpress.org/extend/plugins/wp-mobile-detect/

  2. Jesse Friedman
    Member
    Plugin Author

    Posted 1 year ago #

    I'd rather see you perform the functions of that plugin only if they are on the correct device.

    Deactivating a plugin at this point will not solve your problem, nor do I think it is possible.

    Lets say your AudioBar plugin has a function called wp_audiobar() you could do

    if( ! wmpd_is_device() ) {
    wp_audiobar();
    }

  3. upsangel
    Member
    Posted 8 months ago #

    Dear Jesse,
    I am holding the site e.g. http://upsangel.com/router-2/router-ap-1to1-match/ (also it s in Chinese but I hope it doesn't matter)
    and i am having the same problem with terranova23 that i wanna disable LINKWITHIN when that is a mobile (the LINKWINTHIN make the mobile view bad, too wide)
    so I expect to add

    if( ! wmpd_is_device() ) {
    linkwithin/linkwithin.php();
    }

    to where?
    Thanks for your help in advance!

  4. upsangel
    Member
    Posted 8 months ago #

    Seems that it is a PHP function, I tried the below but cannot work it out:

    1. I deactive the linkwithin plugin,

    2. Then I add this to my responsive theme's functions.php:
    function deactivate_plugin_conditional() {
    if( ! wmpd_is_device() ) {
    linkwithin/linkwithin.php();
    }
    }
    add_action( 'admin_init', 'deactivate_plugin_conditional' );

    I have tried "linkwithin/linkwithin.php()" and "linkwithin.php()", both not work for me... seems I missed some steps or some code wrong

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic