Simplicityは基本的に、ページキャッシュプラグインの使用は推奨していません。
ただ、急激なトラフィック増加などにより、どうしてもページキャッシュプラグインを使わなければいけない時があるかもしれません。
そのときのために、以前寝ログの方でW3 Total Cacheを使用する以下の方法を紹介しました。
この記事内で、完全にモバイル表示にも対応させるには、以下のコードを貼り付けるよう書いていました。
if (function_exists('w3_instance')) { function is_mobile() { $w3_mobile = w3_instance('W3_Mobile'); $group = $w3_mobile->get_group(); return "high" === $group || "low" === $group; } }
ただ、上記のコードは、W3 Total Cache v0.9.5からの仕様変更により、W3_Mobileが使用できなくなってしまったため、以下のようなエラーが出るようになってしまいました。
#0 w3tc_class_autoload(W3TC\) #1 spl_autoload_call(W3TC\) called at [WORDPRESS_PATH/wp-content/plugins/w3-total-cache/Dispatcher.php:16] #2 W3TC/Dispatcher::component() called at [WORDPRESS_PATHs/wp-content/plugins/w3-total-cache/inc/define.php:27] #3 w3_instance(W3_Mobile) called at [WORDPRESS_PATH/wp-content/themes/simplicity2-child/functions.php:14] #4 is_mobile() called at [WORDPRESS_PATH/wp-content/themes/simplicity2/lib/image.php:119] #5 include(WORDPRESS_PATH/wp-content/themes/simplicity2/lib/image.php) called at [WORDPRESS_PATH/wp-content/themes/simplicity2/functions.php:17] #6 include(WORDPRESS_PATH/wp-content/themes/simplicity2/functions.php) called at [WORDPRESS_PATH/wp-settings.php:387] #7 require_once(WORDPRESS_PATH/wp-settings.php) called at [WORDPRESS_PATH/wp-config.php:93] #8 require_once(WORDPRESS_PATH/wp-config.php) called at [WORDPRESS_PATH/wp-load.php:39] #9 require_once(WORDPRESS_PATH/wp-load.php) called at [WORDPRESS_PATH/wp-blog-header.php:13] #10 require(WORDPRESS_PATH/wp-blog-header.php) called at [WORDPRESS_PATH/index.php:17] Warning: require(WORDPRESS_PATH/wp-content/plugins/w3-total-cache/.php): failed to open stream: No such file or directory in WORDPRESS_PATH/wp-content/plugins/w3-total-cache/w3-total-cache-api.php on line 161 Fatal error: require(): Failed opening required 'WORDPRESS_PATH/wp-content/plugins/w3-total-cache/.php' (include_path='.;PHP_PATH/php/PEAR') in WORDPRESS_PATH/wp-content/plugins/w3-total-cache/w3-total-cache-api.php on line 161
ですので、以前のコードを利用している場合は、アップデート前に削除するか、以下の新しいコードに変更してください。
if (function_exists('w3_instance')) { function is_mobile() { $cache = w3_instance('W3_PgCache'); $group = $cache->_mobile->get_group(); return "high" === $group || "low" === $group; } }
上記のコードは、v0.9.6以降版です。
参考 【Simplicity2】W3 Total CacheのPage Cacheを正しく使う
ただ、新しいコードに変更したとしても、今後W3 Total Cacheのアップデートにより、またエラーが出る可能性がないとは言えません。
上記コードを使用することにより、何かしらの不利益を被ったとしても、保証はできませんのでご了承ください。あくまで、コードのカスタマイズは自己責任でお願いします。
もし、今後W3 Total Cacheのアップデートによりエラーが出て、管理画面に入れなくなったときのために、プラグインの削除方法も以下に掲載しておきます。