mobble icon indicating copy to clipboard operation
mobble copied to clipboard

mobble and wordpress wp rocket cache

Open wpsumo opened this issue 5 years ago • 6 comments

@scottsweb doesn't seem to play nicely anymore with the preloaded cache. It should be working with wp rocket which triggers is_mobile when using mobile and desktop cache separated.

So the element to display on a desktop should show on desktop and mobile on mobile. But it seems to be something that isn't playing nice anymore.

As wp rocket is triggering two different user agents and two different cache files it should be working and display the correct things for wp rockets preloader and store those rules in the cache. Then the PHP conditions won't work as the cache is cache and don't involve PHP. But that's not the issue, the issue is it seems to not play as it should with wp rockets preload of the cache.

Any idea?

wpsumo avatar Mar 24 '20 09:03 wpsumo

Any chance you could look into it and support wp_is_mobile which most probably is the issue as this is what wordpress cache plugin use. https://codex.wordpress.org/Function_Reference/wp_is_mobile

wpsumo avatar Mar 24 '20 10:03 wpsumo

As WP Rocket is a premium plugin I am not sure how much testing I can do. You could use wp_is_mobile directly in your code to see if that works as expected, that might save you requiring this plugin?

Also, this plugin is largely just a wrapper for http://mobiledetect.net/ - it might be worth updating the underlying library as there will be some user agent changes that my plugin doesn't have yet.

scottsweb avatar Mar 24 '20 11:03 scottsweb

@scottsweb Drop me an email tobias . alriksson (@) gmail . com and I send the latest version for you to test. Having issues where the condition sets to not display on mobile. But sometimes it fails and also doesn't display on the desktop.

You could use wp_is_mobile directly in your code to see if that works as expected, that might save you requiring this plugin?

True not that tech-savvy in PHP as a developer. Right now I'm using oxygen builder and registring a condition with mobble.

https://oxygenbuilder.com/documentation/other/conditions/

And code snippet:

if ( function_exists( 'oxygen_vsb_register_condition' ) ) {

	if ( ! class_exists( 'Mobile_Detect' ) ) {
		return;
	}

	oxygen_vsb_register_condition(
		// Condition Name
		'Is Mobile',

		// Values: The array of pre-set values the user can choose from.
		// Set the custom key's value to true to allow users to input custom values.
		array( 
			'options' => array( 'true', 'false' ),
			'custom' => false
		),

		// Operators
		array( '==' ),
		
		// Callback Function: Name of function that will be used to handle the condition
		'wpm_is_mobile_fallback',

		// Condition Category: Default ones are Archive, Author, Other, Post, User
		'Other'
	);

}

/**
 * Callback function to handle the condition.
 * @param  mixed 	$value    	Input value - in this case, true or false selected by the user.
 * @param  string 	$operator 	Comparison operator selected by the user.
 *
 * @return boolean 				true or false.
 */
function wpm_is_mobile_fallback( $value, $operator ) {

	if ( 'true' === $value ) {
		return ( is_mobile() );
	} else {
		return ( is_mobile() ) ? false : true;
	}

}

Also, this plugin is largely just a wrapper for http://mobiledetect.net/ - it might be worth updating the underlying library as there will be some user agent changes that my plugin doesn't have yet.

Any plans updating the underlying library?

wpsumo avatar Mar 24 '20 12:03 wpsumo

Testing this new one does it look alright to you? But still happily make the mobble functional for wp rocket. But might be safer to use wp native mobile as wp rocket use the same hook.

if ( function_exists( 'oxygen_vsb_register_condition' ) ) {

	oxygen_vsb_register_condition(
		// Condition Name
		'Is WP Mobile',

		// Values: The array of pre-set values the user can choose from.
		// Set the custom key's value to true to allow users to input custom values.
		array( 
			'options' => array( 'true', 'false' ),
			'custom' => false
		),

		// Operators
		array( '==' ),
		
		// Callback Function: Name of function that will be used to handle the condition
		'wpm_is_mobile_fallback',

		// Condition Category: Default ones are Archive, Author, Other, Post, User
		'Other'
	);

}

/**
 * Callback function to handle the condition.
 * @param  mixed 	$value    	Input value - in this case, true or false selected by the user.
 * @param  string 	$operator 	Comparison operator selected by the user.
 *
 * @return boolean 				true or false.
 */
function wpm_is_mobile_fallback( $value, $operator ) {

	if ( 'true' === $value ) {
		return ( wp_is_mobile() );
	} else {
		return ( wp_is_mobile() ) ? false : true;
	}

}

wpsumo avatar Mar 24 '20 12:03 wpsumo

No plans to update this plugin. Sites generally require caching these days and this plugin has never played well with various cache scenarios.

I am not familar with Oxygen builder but the logic for wpm_is_mobile_fallback seems off to me. The if and the else both return wp_is_mobile... so I think it would be simpler to just do something like:

function wpm_is_mobile_fallback( $value, $operator ) {
		return ( wp_is_mobile() );
}

I am not sure what this gives you in Oxygen builder... some kind of re-usable piece of logic perhaps? The problem with my approach is that I am ignoring their operator and value which might be important.

scottsweb avatar Mar 24 '20 17:03 scottsweb

No plans to update this plugin. Sites generally require caching these days and this plugin has never played well with various cache scenarios.

True, but maybe the option to change the value with ajax after DOM is done. But PHP works fine for real users. As only require a reload once you mix with dev tools and change device. But a real user visit from desktop and mobile without switching from mobile to desktop view or vise versa. Ajax become a must if using GEO triggers. But thanks anyhow maybe better to just use the native WP function then as it seems to work just fine while I've been testing.

But still, like mobble for is_iphone is_android etc to display certain things but not using at the moment. So your plugin is still used by many users, especially with the builder.

I am not familar with Oxygen builder but the logic for wpm_is_mobile_fallback seems off to me. The if and the else both return wp_is_mobile... so I think it would be simpler to just do something like:

I am not sure what this gives you in Oxygen builder... some kind of re-usable piece of logic perhaps? The problem with my approach is that I am ignoring their operator and value which might be important.

Yeah it's the function that is used. So it's to register into their builder. Otherwise, I would agree with you no need as it would only need to wrap the divs or whatever I want to display or not display in the wp_is_mobile.

Callback Function (string) Name of function that will be used to handle the condition.

It's to register custom conditions into the builders condition feature. https://oxygenbuilder.com/documentation/other/conditions/

wpsumo avatar Mar 26 '20 17:03 wpsumo