/** * LiveTube: Allow FB crawler to receive cached HTML for selected static paths * Place in /wp-content/mu-plugins/allow-fb-cache.php */ if ( defined( 'WPINC' ) ) { // Run only on site with blog ID 1 (livetube.tv) if ( function_exists( 'get_current_blog_id' ) && (int) get_current_blog_id() !== 1 ) { return; } add_filter( 'rocket_cache_reject_ua', 'lt_allow_facebook_for_static_paths' ); function lt_allow_facebook_for_static_paths( $ua ) { $allowed_paths = array( '/', '/about', '/about/app', '/about/contact-us', '/legal/privacy', '/legal/tos', '/cookie-policy-eu', '/help', '/media', '/de', '/es', '/ja', '/ko', '/ru', '/uk', '/zh-hans', '/zh-hant' ); $req = isset( $_SERVER['REQUEST_URI'] ) ? strtolower( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; foreach ( $allowed_paths as $p ) { if ( strpos( $req, strtolower( $p ) ) !== false ) { // remove Facebook tokens from reject list $tokens = array( 'facebookexternalhit', 'facebot', 'facebookcatalog' ); foreach ( $tokens as $t ) { $key = array_search( $t, $ua, true ); if ( $key !== false ) { unset( $ua[ $key ] ); } } $ua = array_values( $ua ); break; } } return $ua; } }