diff --git a/projects/plugins/super-cache/.phan/baseline.php b/projects/plugins/super-cache/.phan/baseline.php index bc33b588e8e44..6a814a0fb43f6 100644 --- a/projects/plugins/super-cache/.phan/baseline.php +++ b/projects/plugins/super-cache/.phan/baseline.php @@ -46,7 +46,6 @@ // PhanTypeMismatchReturn : 2 occurrences // PhanCommentParamWithoutRealParam : 1 occurrence // PhanPluginDuplicateIfCondition : 1 occurrence - // PhanRedefineFunctionInternal : 1 occurrence // PhanRedundantConditionInLoop : 1 occurrence // PhanTypeArraySuspicious : 1 occurrence // PhanTypeConversionFromArray : 1 occurrence @@ -80,7 +79,7 @@ 'tests/e2e/tools/mu-test-helpers.php' => ['PhanTypeMismatchArgument'], 'wp-cache-base.php' => ['PhanTypeMismatchArgumentNullableInternal'], 'wp-cache-phase1.php' => ['PhanRedundantConditionInGlobalScope', 'PhanTypeNonVarPassByRef'], - 'wp-cache-phase2.php' => ['PhanImpossibleCondition', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateIfCondition', 'PhanPluginRedundantAssignment', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanPossiblyUndeclaredVariable', 'PhanRedefineFunctionInternal', 'PhanRedundantCondition', 'PhanSuspiciousValueComparison', 'PhanTypeArraySuspicious', 'PhanTypeArraySuspiciousNull', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentInternalProbablyReal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredConstant', 'PhanUndeclaredVariableDim'], + 'wp-cache-phase2.php' => ['PhanImpossibleCondition', 'PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateIfCondition', 'PhanPluginRedundantAssignment', 'PhanPluginSimplifyExpressionBool', 'PhanPluginUnreachableCode', 'PhanPossiblyUndeclaredVariable', 'PhanRedundantCondition', 'PhanSuspiciousValueComparison', 'PhanTypeArraySuspicious', 'PhanTypeArraySuspiciousNull', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentInternalProbablyReal', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeNonVarPassByRef', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredConstant', 'PhanUndeclaredVariableDim'], 'wp-cache.php' => ['PhanImpossibleCondition', 'PhanPluginDuplicateAdjacentStatement', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPluginNeverReturnFunction', 'PhanPluginSimplifyExpressionBool', 'PhanPossiblyUndeclaredVariable', 'PhanRedundantCondition', 'PhanRedundantConditionInLoop', 'PhanSuspiciousValueComparison', 'PhanTypeArraySuspiciousNullable', 'PhanTypeInvalidDimOffset', 'PhanTypeInvalidLeftOperandOfBitwiseOp', 'PhanTypeInvalidLeftOperandOfNumericOp', 'PhanTypeInvalidRightOperandOfAdd', 'PhanTypeInvalidRightOperandOfBitwiseOp', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentInternalProbablyReal', 'PhanTypeMismatchArgumentInternalReal', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeNonVarPassByRef', 'PhanTypePossiblyInvalidDimOffset', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredConstant', 'PhanUndeclaredFunction', 'PhanUndeclaredVariable', 'PhanUndeclaredVariableDim'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. diff --git a/projects/plugins/super-cache/changelog/update-super-cache-get-apache-headers b/projects/plugins/super-cache/changelog/update-super-cache-get-apache-headers new file mode 100644 index 0000000000000..d43c4d6b80f59 --- /dev/null +++ b/projects/plugins/super-cache/changelog/update-super-cache-get-apache-headers @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Super Cache: Fixed the apache_request_headers fallback so it works when that command is disabled diff --git a/projects/plugins/super-cache/wp-cache-phase2.php b/projects/plugins/super-cache/wp-cache-phase2.php index 44287b4635f1e..adddbe6c0a96e 100644 --- a/projects/plugins/super-cache/wp-cache-phase2.php +++ b/projects/plugins/super-cache/wp-cache-phase2.php @@ -310,7 +310,7 @@ function wp_cache_serve_cache_file() { // don't try to match modified dates if using dynamic code. if ( $wp_cache_mfunc_enabled == 0 && $wp_supercache_304 ) { wp_cache_debug( 'wp_cache_serve_cache_file: checking age of cached vs served files.' ); - $headers = apache_request_headers(); + $headers = wpsc_apache_request_headers(); $remote_mod_time = isset( $headers['If-Modified-Since'] ) ? $headers['If-Modified-Since'] : null; if ( $remote_mod_time === null && isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) { @@ -1751,7 +1751,7 @@ function wp_cache_user_agent_is_rejected() { return false; } - $headers = apache_request_headers(); + $headers = wpsc_apache_request_headers(); if ( empty( $headers['User-Agent'] ) ) { return false; } @@ -3582,23 +3582,25 @@ function wpsc_is_get_query() { return $is_get_query; } -if ( ! function_exists( 'apache_request_headers' ) ) { - /** - * A fallback for get request headers. - * Based on comments from http://php.net/manual/en/function.apache-request-headers.php - * - * @return array List of request headers - */ - function apache_request_headers() { - $headers = array(); +/** + * A fallback for get request headers. + * Based on comments from http://php.net/manual/en/function.apache-request-headers.php + * + * @return array List of request headers + */ +function wpsc_apache_request_headers() { + if ( ! function_exists( 'apache_request_headers' ) || ! is_callable( 'apache_request_headers' ) ) { + $headers = array(); foreach ( array_keys( $_SERVER ) as $skey ) { if ( str_starts_with( $skey, 'HTTP_' ) ) { $header = implode( '-', array_map( 'ucfirst', array_slice( explode( '_', strtolower( $skey ) ), 1 ) ) ); $headers[ $header ] = $_SERVER[ $skey ]; } } - - return $headers; + } else { + $headers = apache_request_headers(); } + + return $headers; } diff --git a/projects/plugins/super-cache/wp-cache.php b/projects/plugins/super-cache/wp-cache.php index 97347ef8bd543..5aa1c630b8af9 100644 --- a/projects/plugins/super-cache/wp-cache.php +++ b/projects/plugins/super-cache/wp-cache.php @@ -1676,8 +1676,6 @@ function wp_cache_sanitize_value($text, & $array) { function wp_cache_update_rejected_ua() { global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce; - if ( !function_exists( 'apache_request_headers' ) ) return; - if ( isset( $_POST[ 'wp_rejected_user_agent' ] ) && $valid_nonce ) { $_POST[ 'wp_rejected_user_agent' ] = str_replace( ' ', '___', $_POST[ 'wp_rejected_user_agent' ] ); $text = str_replace( '___', ' ', wp_cache_sanitize_value( $_POST[ 'wp_rejected_user_agent' ], $cache_rejected_user_agent ) ); @@ -1692,10 +1690,6 @@ function wp_cache_update_rejected_ua() { function wpsc_edit_rejected_ua() { global $cache_rejected_user_agent; - if ( ! function_exists( 'apache_request_headers' ) ) { - return; - } - $admin_url = admin_url( 'options-general.php?page=wpsupercache' ); wp_cache_update_rejected_ua(); wpsc_render_partial(