[AUTOMATIQUE] Cet article a plus de 5 ans.
Il se peut donc que les informations qu'il fournit ne soient plus totalement exactes.

Recently I had to deal with the W3 Total Cache option to make some conditional tests in the admin, but I discovered that there is no option saved in the database.

Actually, plugin’s options are stored in a PHP file in your wp-content directory. Don’t ask me why, I don’t have the answer…

After having crawled the plugin functions, I have finally find a way to retrieve these options with this simple snippet.

	$W3tcOptions = false;
	if ( defined( 'W3TC_LIB_W3_DIR' ) ) {
		$config = W3_ConfigWriter::get_config_filename();
		if ( file_exists( $config ) ) { 
			$W3tcOptions = include( $config );
	return $W3tcOptions;

The fonction will return an array of the plugin options or false if there is no option.

This snippet use the native plugin’s functions, so it is Multisite compatible, as the plugin.

Hope this helps!


Post written byBrice CAPOBIANCO

WordPress addict and self-taught. I love to learn and to create, then to share…
Founder of bweb.
Share this post

Your email address will not be published. Required fields are marked *

Show 1 comment

1 comment