Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a mobile version I'm building outside of Wordpress in a subfolder on the same server as my Wordpress install. I'm including the wp-load.php file to pull content from the WordPress database.

If I turn this plugin on (http://wordpress.org/plugins/php-mobile-redirect/), it goes into an endless loop.

I realize now by doing this I'm also calling all active plugins. Or at least I think I'm calling the redirect script which is causing the endless loop.

If I go to the normal site, http://s168249.gridserver.com/ on a mobile phone or by spoofing the browser, endless loop.

If I go to the mobile site, http://s168249.gridserver.com/mobile/index.php, on a phone, endless loop.

If I turn off the redirect, I can go to the mobile site without a hitch.

CURRENTLY ALL REDIRECTION IS OFF

So I assume that the include of the mobile redirect script us wp_load.php in the mobile index.php file is what's causing the issue.

Is there a way to exclude just this plugin?

http://wordpress.org/extend/plugins/php-mobile-redirect/

share|improve this question
    
How can you "exclude" the plugin and still have it work? Try to clarify this question please. –  s_ha_dum Jul 29 '13 at 15:08
    
That plugin appears to depend on cookies Is it possible that that is part of the issue? –  s_ha_dum Jul 29 '13 at 15:13
    
I'm trying to exclude it from the mobile version of the site, not the full site. –  Dave Rottino Jul 29 '13 at 19:00
add comment

2 Answers

up vote 1 down vote accepted

Disable the plugin at all and in your function.php add

add_action('init', 'my_mobile_redirect');

function get_first_url_subdir() {
  return str_replace( str_replace( array('http://', 'https://'), '', get_site_url() ), '', $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
} 

function redirect_mobile_with_cookie() {
  $cookiename = 'redirect_mobile_is_a_mobile_device';
  if ( isset($_COOKIE[$cookiename]) && ($_COOKIE[$cookiename] == 'yes') && strpos(get_first_url_subdir(), '/mobile') !== 0)
    return true;
  return false;
} 

function my_mobile_redirect(){
  if ( redirect_mobile_with_cookie() ) {
     wp_redirect( get_site_url() . '/mobile/');
     exit();
  } elseif  ( strpos(get_first_url_subdir(), '/mobile') !== 0 && wp_is_mobile() ) {
    $cookiename = 'redirect_mobile_is_a_mobile_device';
    setcookie($cookiename, 'yes');
    wp_redirect( get_site_url() . '/mobile/');
    exit();
  }
}

Previous functions works with Wordpress wp_is_mobile function that do not differentiate between tablets and phones.

If you need to differentiate between tablets and phones you can use the script Mobile Detect. Download it, put in a folder. For semplicity here I assume Mobile_Detect.php resides in theme root.

The following function works in combination with the three above.

function my_adv_mobile_redirect() {
   if ( redirect_mobile_with_cookie() ) {
     wp_redirect( get_site_url() . '/mobile/');
     exit();
  } else {
    @include_once( trailingslashit(TEMPLATEPATH) . 'Mobile_Detect.php' );
    if ( ! class_exists('Mobile_Detect') ) return my_mobile_redirect();
    $detect = new Mobile_Detect;
    // redirects only phones
    if  (strpos(get_first_url_subdir(), '/mobile') !== 0 && ($detect->isMobile() && ! $detect->isTablet())) {
      $cookiename = 'redirect_mobile_is_a_mobile_device';
      setcookie($cookiename, 'yes');
      wp_redirect( get_site_url() . '/mobile/');
      exit();
    }
  }
}

If you want to use this advanced function just replace the init action in the previous code with: add_action('init', 'my_adv_mobile_redirect')

share|improve this answer
    
This block of code works. I've added an extra else if to bounce you back to regular site if you're trying to access the mobile site. Now I just need to figure out how to exclude all tablet devices and how to make a view full site option with cookies. –  Dave Rottino Jul 29 '13 at 18:58
    
@DaveRottino, see my new code... –  G. M. Jul 29 '13 at 19:32
    
Junk! Now I'm getting the following error: Fatal error: Allowed memory size of 103809024 bytes exhausted (tried to allocate 261900 bytes) in /nfs/c03/h04/mnt/168249/domains/owensgroup.com/html/wp-includes/formatting.php on line 940 I can't get it to go at all now. –  Dave Rottino Aug 13 '13 at 15:13
    
@DaveRottino The error was generated by the get_option call. I've totally removed that function that is not necessary and, by calling db, slows down the redirect. I've tested in a desktop and it works, it should on a mobile device, too. Probably is a good idea change the cookie name in the code and make it more customized for your site. –  G. M. Aug 16 '13 at 22:08
add comment

I haven't tested this but in the index.php for your mobile site can you add

remove_action('init', 'pmr_mobile_redirect');

this in theory will disable the redirect plugin.

share|improve this answer
    
I tried this and no go. It does remove the redirect. I determined it's working with a little execute code detection BUT on mobile, it still causes a infinite loop. –  Dave Rottino Jul 29 '13 at 18:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.