W3 Total Cache 0.9.5 で「WordPress プラグイン同士でライブラリがコンフリクトしています」と出る場合の対処方法

  • 投稿 : 2016-09-28
  • 更新 : 2016-10-02
追記:2016/10/02
W3 Total Cache — WordPress Plugins

問題を解決した「バージョン0.9.5.1」が提供されてるのでそちらを使えばOKだと思う。
私の環境では、0.9.5.1で問題ない感じ・・。

W3 Total Cacheって昔から仕様通り?ちゃんと動いてない感はあるかなぁとは思う。

以下、0.9.5.1が出る以前の内容


Fatal error: require(): Failed opening required '/home/example/example.com/public_html/mobile.example.com/wp-content/plugins/w3-total-cache/lib/Google/Service/Analytics.php' (include_path='.:/opt/php-7.0.7/data/pear') in /home/example/example.com/public_html/blog.example.com/wp-content/plugins/w3-total-cache/w3-total-cache-api.php on line 143

Topic: Conflict with Google Analytics Dashboard for WP (GADWP) « WordPress.org Forums

私の環境では、Google Analytics Dashboard for WPとコンフリクトしてました。
0.9.5からいろいろライブラリを読むようになったので、他のプラグインとそういうことになるケースが多いようで、検索するといっぱいヒットします。

w3-total-cache/libあたりをみれば読み込んでいるライブラリがわかるかと思います。

暫定の対策方法

function w3tc_class_autoload( $class ) {
	$base = null;

	// some php pass classes with slash
	if ( substr( $class, 0, 1 ) == "\\" )
		$class = substr( $class, 1 );

	if ( substr( $class, 0, 5 ) == 'HTTP_' || substr( $class, 0, 7 ) == 'Minify_' ) {
		$base = W3TC_LIB_DIR . DIRECTORY_SEPARATOR . 'Minify' . DIRECTORY_SEPARATOR;
	} elseif ( substr( $class, 0, 8 ) == 'Minify0_' ) {
		$base = W3TC_LIB_DIR . DIRECTORY_SEPARATOR . 'Minify' . DIRECTORY_SEPARATOR;
		$class = substr( $class, 8 );
	} elseif ( substr( $class, 0, 7 ) == 'Google_' &&
		( !defined( 'W3TC_GOOGLE_LIBRARY' ) || W3TC_GOOGLE_LIBRARY ) ) {
		// Google library
		$classPath = explode( '_', $class );
		if ( count( $classPath ) > 3 ) {
			// Maximum class file path depth in this project is 3.
			$classPath = array_slice( $classPath, 0, 3 );
		}

		$filePath = W3TC_LIB_DIR . DIRECTORY_SEPARATOR .
			implode( '/', $classPath ) . '.php';
		if ( is_readable( $filePath ) ) {
                    require $filePath;
                }
		return;
	}

	if ( !is_null( $base ) ) {
		$file = $base . strtr( $class, "\\_",
			DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR ) . '.php';
		if ( is_readable( $file ) ) {
			require_once $file;
                }
	} else if ( substr( $class, 0, 5 ) == 'W3TC\\' ) {
			$filename = W3TC_DIR . DIRECTORY_SEPARATOR . substr( $class, 5 ) . '.php';

                        if ( is_readable( $filename ) ) {
                            require $filename;
                        }
                        else {
                            if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
                                    debug_print_backtrace();
                            }
			}
			
                        return;
		}
}

w3-total-cache-api.phpファイルのw3tc_class_autoload関数を上記に置き換えると回避できます。
オリジナルと比較すればわかりますが、is_readableを用いて回避してるようです。

Topic: Fix for “Fatal error: require():” « WordPress.org Forums

w3tc_class_autoload関数は上記のものをそのまま使いました。

スポンサーリンク