ded URLs.
$uris[] = '/(?:.+/)?embed/';
/**
* Filter the rejected uri
*
* @since 2.1
*
* @param array $uris List of rejected uri
*/
$uris = apply_filters( 'rocket_cache_reject_uri', $uris );
$uris = array_filter( $uris );
if ( ! $uris ) {
return '';
}
if ( '' !== $home_root ) {
foreach ( $uris as $i => $uri ) {
if ( preg_match( '/' . $home_root_escaped . '\(?\//', $uri ) ) {
// Remove the home directory from the new URIs.
$uris[ $i ] = substr( $uri, $home_root_len );
}
}
}
$uris = implode( '|', $uris );
if ( '' !== $home_root ) {
// Add the home directory back.
$uris = $home_root . '(' . $uris . ')';
}
return $uris;
}
/**
* Get all cookie names we don't cache.
*
* @since 2.0
*
* @return string A pipe separated list of rejected cookies.
*/
function get_rocket_cache_reject_cookies() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$logged_in_cookie = explode( COOKIEHASH, LOGGED_IN_COOKIE );
$logged_in_cookie = array_map( 'preg_quote', $logged_in_cookie );
$logged_in_cookie = implode( '.+', $logged_in_cookie );
$cookies = get_rocket_option( 'cache_reject_cookies', [] );
$cookies[] = $logged_in_cookie;
$cookies[] = 'wp-postpass_';
$cookies[] = 'wptouch_switch_toggle';
$cookies[] = 'comment_author_';
$cookies[] = 'comment_author_email_';
/**
* Filter the rejected cookies.
*
* @since 2.1
*
* @param array $cookies List of rejected cookies.
*/
$cookies = (array) apply_filters( 'rocket_cache_reject_cookies', $cookies );
$cookies = array_filter( $cookies );
$cookies = array_flip( array_flip( $cookies ) );
return implode( '|', $cookies );
}
/**
* Get list of mandatory cookies to be able to cache pages.
*
* @since 2.7
*
* @return string A pipe separated list of mandatory cookies.
*/
function get_rocket_cache_mandatory_cookies() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$cookies = [];
/**
* Filter list of mandatory cookies.
*
* @since 2.7
*
* @param array $cookies List of mandatory cookies.
*/
$cookies = (array) apply_filters( 'rocket_cache_mandatory_cookies', $cookies );
$cookies = array_filter( $cookies );
$cookies = array_flip( array_flip( $cookies ) );
return implode( '|', $cookies );
}
/**
* Get list of dynamic cookies.
*
* @since 2.7
*
* @return array List of dynamic cookies.
*/
function get_rocket_cache_dynamic_cookies() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$cookies = [];
/**
* Filter list of dynamic cookies.
*
* @since 2.7
*
* @param array $cookies List of dynamic cookies.
*/
$cookies = (array) apply_filters( 'rocket_cache_dynamic_cookies', $cookies );
$cookies = array_filter( $cookies );
$cookies = array_unique( $cookies );
return $cookies;
}
/**
* Get all User-Agent we don't allow to get cache files.
*
* @since 2.3.5
*
* @return string A pipe separated list of rejected User-Agent.
*/
function get_rocket_cache_reject_ua() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$ua = get_rocket_option( 'cache_reject_ua', [] );
$ua[] = 'facebookexternalhit';
$ua[] = 'WhatsApp';
/**
* Filter the rejected User-Agent
*
* @since 2.3.5
*
* @param array $ua List of rejected User-Agent.
*/
$ua = (array) apply_filters( 'rocket_cache_reject_ua', $ua );
$ua = array_filter( $ua );
$ua = array_flip( array_flip( $ua ) );
$ua = implode( '|', $ua );
return str_replace( [ ' ', '\\\\ ' ], '\\ ', $ua );
}
/**
* Get all query strings which can be cached.
*
* @since 2.3
*
* @return array List of query strings which can be cached.
*/
function get_rocket_cache_query_string() { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals
$query_strings = get_rocket_option( 'cache_query_strings', [] );
/**
* Filter query strings which can be cached.
*
* @since 2.3
*
* @param array $query_strings List of query strings which can be cached.
*/
$query_strings = (array) apply_filters( 'rocket_cache_query_strings', $query_strings );
$query_strings = array_filter( $query_strings );
$query_strings = array_flip( array_flip( $query_strings ) );
return $query_strings;
}
/**
* Determine if the key is valid
*
* @since 2.9 use hash_equals() to compare the hash values
* @since 1.0
*
* @return bool true if everything is ok, false otherwise
*/
function rocket_valid_key() {
return true;
delete_transient( 'rocket_check_key_errors' );
}
/**
* Determine if the key is valid.
*
* @since 2.9.7 Remove arguments ($type & $data).
* @since 2.9.7 Stop to auto-check the validation each 1 & 30 days.
* @since 2.2 The function do the live check and update the option.
*
* @return bool|array
*/
function rocket_check_key() {
// Recheck the license.
$return = rocket_valid_key();
if ( $return ) {
rocket_delete_licence_data_file();
return $return;
}
Logger::info( 'LICENSE VALIDATION PROCESS STARTED.', [ 'license validation process' ] );
$response = wp_remote_get(
rocket_get_constant( 'WP_ROCKET_WEB_VALID' ),
[
'timeout' => 30,
]
);
if ( is_wp_error( $response ) ) {
Logger::error(
'License validation failed.',
[
'license validation process',
'request_error' => $response->get_error_messages(),
]
);
set_transient( 'rocket_check_key_errors', $response->get_error_messages() );
return $return;
}
$body = wp_remote_retrieve_body( $response );
$json = json_decode( $body );
if ( null === $json ) {
if ( '' === $body ) {
Logger::error( 'License validation failed. No body available in response.', [ 'license validation process' ] );
// Translators: %1$s = opening em tag, %2$s = closing em tag, %3$s = opening link tag, %4$s closing link tag.
$message = __( 'License validation failed. Our server could not resolve the request from your website.', 'rocket' ) . '
' . sprintf( __( 'Try clicking %1$sValidate License%2$s below. If the error persists, follow %3$sthis guide%4$s.', 'rocket' ), '', '', '', '' );
set_transient( 'rocket_check_key_errors', [ $message ] );
return $return;
}
Logger::error(
'License validation failed.',
[
'license validation process',
'response_body' => $body,
]
);
if ( 'NULLED' === $body ) {
// Translators: %1$s = opening link tag, %2$s = closing link tag.
$message = __( 'License validation failed. You may be using a nulled version of the plugin. Please do the following:', 'rocket' ) . '