/i', ltrim( $page_contents ) ); $has_xsl_stylesheet = ( stripos( $page_contents, 'get_var($wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE post_name=%s", $slugs)); $excluded_id .= $get_post_ids . ','; } $excluded_id = rtrim($excluded_id, ','); if ( in_array( get_queried_object_id(), (array) explode( ',', $excluded_id) ) ) { return true; } } // if post ID excluded if ( ! empty( $settings['excluded_post_ids'] ) && function_exists( 'is_singular' ) && is_singular() ) { if ( in_array( get_queried_object_id(), (array) explode( ',', $settings['excluded_post_ids'] ) ) ) { return true; } } // if page path excluded if ( ! empty($settings['excluded_page_paths'] ) ) { $page_path = parse_url( $server_array['REQUEST_URI'], PHP_URL_PATH ); if ( preg_match($settings['excluded_page_paths'], $page_path ) ) { return true; } } $get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); // if query string excluded if ( ! empty( $get ) ) { // set regex matching query strings that should bypass the cache if ( ! empty( $settings['excluded_query_strings'] ) ) { $query_string_regex = $settings['excluded_query_strings']; } else { $query_string_regex = '/^(?!(fbclid|ref|mc_(cid|eid)|utm_(source|medium|campaign|term|content|expid)|gclid|fb_(action_ids|action_types|source)|age-verified|usqp|cn-reloaded|_ga|_ke)).+$/'; } $query_string = parse_url( $server_array['REQUEST_URI'], PHP_URL_QUERY ); if ( preg_match( $query_string_regex, $query_string ) ) { return true; } } $cookie_array = filter_input_array(INPUT_COOKIE, FILTER_SANITIZE_STRING); // if cookie excluded if ( ! empty( $cookie_array ) ) { // set regex matching cookies that should bypass the cache if ( ! empty( $settings['excluded_cookies'] ) ) { $cookies_regex = $settings['excluded_cookies']; } else { $cookies_regex = '/^(wp-postpass|wordpress_logged_in|comment_author)_/'; } // bypass cache if an excluded cookie is found foreach ( $cookie_array as $key => $value) { if ( preg_match( $cookies_regex, $key ) ) { return true; } } } return false; } /** * check if mobile template * * * @return boolean true if mobile template, false otherwise */ private static function is_mobile() { return ( strpos( TEMPLATEPATH, 'wptouch' ) || strpos( TEMPLATEPATH, 'carrington' ) || strpos( TEMPLATEPATH, 'jetpack' ) || strpos( TEMPLATEPATH, 'handheld' ) ); } /** * check if cache should be bypassed * * * @return boolean true if cache should be bypassed, false otherwise * * @hook boolean bypass_cache */ private static function bypass_cache() { $server_array = filter_input_array(INPUT_SERVER, FILTER_SANITIZE_STRING); // bypass cache hook if ( apply_filters( 'bypass_cache', false ) ) { return true; } // check request method if ( ! isset( $server_array['REQUEST_METHOD'] ) || $server_array['REQUEST_METHOD'] !== 'GET' ) { return true; } // check HTTP status code if ( http_response_code() !== 200 ) { return true; } // check WP_CACHE constant if ( defined( 'WP_CACHE' ) && ! WP_CACHE ) { return true; } // check DONOTCACHEPAGE constant if ( defined( 'DONOTCACHEPAGE' ) && DONOTCACHEPAGE ) { return true; } // check conditional tags if ( self::is_wrong_permalink_structure() || self::is_excluded() ) { return true; } // check conditional tags when output buffering has ended if ( class_exists( 'WP' ) ) { if ( is_admin() || is_search() || is_feed() || is_trackback() || is_robots() || is_preview() || post_password_required() || self::is_mobile() ) { return true; } } return false; } /** * deliver cache * */ public static function deliver_cache() { if ( ! self::$started || self::bypass_cache() ) { return; } readfile( Smack_Cache_Disk::get_cache() ); exit; } }