false, 'reason' => 'method' ); } if ( ! empty( $args['is_admin'] ) ) { return array( 'allowed' => false, 'reason' => 'admin' ); } if ( ! empty( $args['is_feed'] ) ) { return array( 'allowed' => false, 'reason' => 'feed' ); } if ( ! empty( $args['is_preview'] ) ) { return array( 'allowed' => false, 'reason' => 'preview' ); } if ( ! empty( $args['donotcachepage'] ) ) { return array( 'allowed' => false, 'reason' => 'donotcachepage' ); } if ( ! empty( $args['doing_ajax'] ) ) { return array( 'allowed' => false, 'reason' => 'ajax' ); } if ( ! empty( $args['rest_request'] ) ) { return array( 'allowed' => false, 'reason' => 'rest' ); } if ( ! empty( $args['has_post_password'] ) ) { return array( 'allowed' => false, 'reason' => 'password' ); } if ( ! empty( $args['is_multisite_signup'] ) ) { return array( 'allowed' => false, 'reason' => 'signup' ); } $uri = isset( $args['uri'] ) ? (string) $args['uri'] : ''; if ( self::uri_is_sensitive( $uri ) ) { return array( 'allowed' => false, 'reason' => 'uri' ); } $cookies = isset( $args['cookies'] ) && is_array( $args['cookies'] ) ? $args['cookies'] : array(); if ( self::cookies_are_always_sensitive( $cookies ) ) { return array( 'allowed' => false, 'reason' => 'cart_cookie' ); } // Fail closed: the Free cache key is shared across users. Until Pro // supplies an audited per-user storage/serving boundary, never cache // authenticated requests, even if an old premium setting remains saved. if ( ! empty( $args['is_logged_in'] ) ) { return array( 'allowed' => false, 'reason' => 'logged_in' ); } if ( self::cookies_are_sensitive( $cookies ) ) { return array( 'allowed' => false, 'reason' => 'cookie' ); } return array( 'allowed' => true, 'reason' => 'ok' ); } public static function request_is_cacheable( array $args ) { $d = self::request_cache_decision( $args ); return ! empty( $d['allowed'] ); } /** * Device segment for cache keys: "mobile" or "desktop". * * @param array $settings Plugin settings. * @param bool $is_mobile Whether the request is mobile. * @return string */ public static function device_segment( array $settings, $is_mobile ) { if ( ! empty( $settings['cache_mobile'] ) && $is_mobile ) { return 'mobile'; } return 'desktop'; } }