• DrLightman

    (@drlightman)


    Basically I want to diplay different ads for mobile/desktop and I want them cached.

    So rather than using a third party library to make the detection (as per Mobile_Detect or wp_is_mobile), I’d rather stick with the very same mobile detection that this wpsc plugin uses, with the .htaccess rules, in order to avoid possible miscachings.

    Is there any wpsc function I can use to do this test? Anything like this would be perfect:

    if( function_exists( 'wpsc_is_mobile' ) ) {
    	if( wpsc_is_mobile( ) ) {
    		// mobile
    	} else {
    		// desktop
    	}
    }

    Thanks.

    https://www.ads-software.com/plugins/wp-super-cache/

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

    (@drlightman)

    Hate to do this, but: bump.

    Thread Starter DrLightman

    (@drlightman)

    I hope Donncha will read this eventually before I dig into the source :v

    Thread Starter DrLightman

    (@drlightman)

    Ok I made a function based on wpsc source code, Donncha can you fast check if it may work? I think it does:

    static function __wpsc_is_mobile( )
    	{
    		global $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
    		$browsers = explode( ',', $wp_cache_mobile_browsers );
    		$user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
    		foreach ($browsers as $browser) {
    			if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) {
    				return true;
    			}
    		}
    		if (isset($_SERVER['HTTP_X_WAP_PROFILE']) )
    			return true;
    		if (isset($_SERVER['HTTP_PROFILE']) )
    			return true;
    
    		if ( isset( $wp_cache_mobile_prefixes ) ) {
    			$browsers = explode( ',', $wp_cache_mobile_prefixes );
    			foreach ($browsers as $browser_prefix) {
    				if ( substr($user_agent, 0, 4) == $browser_prefix ) {
    					return true;
    				}
    			}
    		}
    		$accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : '';
    		if (strpos($accept, 'wap') !== false) {
    			return true;
    		}
    		if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) {
    			return true;
    		}
    		return false;
    	}

    protip: it doesnt check if the two global wpsc vars are set, im doing it in another function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘function/method for mobile detect consistent with its .htaccess rules’ is closed to new replies.