ller->get_items, * but global styles does not require as many parameters. * * @since 6.3.0 * * @param WP_REST_Request $request The request instance. * @return WP_REST_Response|WP_Error */ public function get_items( $request ) { $parent = $this->get_parent( $request['parent'] ); if ( is_wp_error( $parent ) ) { return $parent; } $global_styles_config = $this->get_decoded_global_styles_json( $parent->post_content ); if ( is_wp_error( $global_styles_config ) ) { return $global_styles_config; } $is_head_request = $request->is_method( 'HEAD' ); if ( wp_revisions_enabled( $parent ) ) { $registered = $this->get_collection_params(); $query_args = array( 'post_parent' => $parent->ID, 'post_type' => 'revision', 'post_status' => 'inherit', 'posts_per_page' => -1, 'orderby' => 'date ID', 'order' => 'DESC', ); $parameter_mappings = array( 'offset' => 'offset', 'page' => 'paged', 'per_page' => 'posts_per_page', ); foreach ( $parameter_mappings as $api_param => $wp_param ) { if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { $query_args[ $wp_param ] = $request[ $api_param ]; } } if ( $is_head_request ) { // Force the 'fields' argument. For HEAD requests, only post IDs are required to calculate pagination. $query_args['fields'] = 'ids'; // Disable priming post meta for HEAD requests to improve performance. $query_args['update_post_term_cache'] = false; $query_args['update_post_meta_cache'] = false; } $revisions_query = new WP_Query(); $revisions = $revisions_query->query( $query_args ); $offset = isset( $query_args['offset'] ) ? (int) $query_args['offset'] : 0; $page = isset( $query_args['paged'] ) ? (int) $query_args['paged'] : 0; $total_revisions = $revisions_query->found_posts; if ( $total_revisions < 1 ) { // Out-of-bounds, run the query without pagination/offset to get the total count. unset( $query_args['paged'], $query_args['offset'] ); $count_query = new WP_Query(); $query_args['fields'] = 'ids'; $query_args['posts_per_page'] = 1; $query_args['update_post_meta_cache'] = false; $query_args['update_post_term_cache'] = false; $count_query->query( $query_args ); $total_revisions = $count_query->found_posts; } if ( $revisions_query->query_vars['posts_per_page'] > 0 ) { $max_pages = (int) ceil( $total_revisions / (int) $revisions_query->query_vars['posts_per_page'] ); } else { $max_pages = $total_revisions > 0 ? 1 : 0; } if ( $total_revisions > 0 ) { if ( $offset >= $total_revisions ) { return new WP_Error( 'rest_revision_invalid_offset_number', __( 'The offset number requested is larger than or equal to the number of available revisions.' ), array( 'status' => 400 ) ); } elseif ( ! $offset && $page > $max_pages ) { return new WP_Error( 'rest_revision_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) ); } } } else { $revisions = array(); $total_revisions = 0; $max_pages = 0; $page = (int) $request['page']; } if ( ! $is_head_request ) { $response = array(); foreach ( $revisions as $revision ) { $data = $this->prepare_item_for_response( $revision, $request ); $response[] = $this->prepare_response_for_collection( $data ); } $response = rest_ensure_response( $response ); } else { $response = new WP_REST_Response( array() ); } $response->header( 'X-WP-Total', (int) $total_revisions ); $response->header( 'X-WP-TotalPages', (int) $max_pages ); $request_params = $request->get_query_params(); $base_path = rest_url( sprintf( '%s/%s/%d/%s', $this->namespace, $this->parent_base, $request['parent'], $this->rest_base ) ); $base = add_query_arg( urlencode_deep( $request_params ), $base_path ); if ( $page > 1 ) { $prev_page = $page - 1; if ( $prev_page > $max_pages ) { $prev_page = $max_pages; } $prev_link = add_query_arg( 'page', $prev_page, $base ); $response->link_header( 'prev', $prev_link ); } if ( $max_pages > $page ) { $next_page = $page + 1; $next_link = add_query_arg( 'page', $next_page, $base ); $response->link_header( 'next', $next_link ); } return $response; } /** * Prepares the revision for the REST response. * * @since 6.3.0 * @since 6.6.0 Added resolved URI links to the response. * * @param WP_Post $post Post revision object. * @param WP_REST_Request $request Request object. * @return WP_REST_Response|WP_Error Response object. */ public function prepare_item_for_response( $post, $request ) { // Don't prepare the response body for HEAD requests. if ( $request->is_method( 'HEAD' ) ) { return new WP_REST_Response( array() ); } $parent = $this->get_parent( $request['parent'] ); $global_styles_config = $this->get_decoded_global_styles_json( $post->post_content ); if ( is_wp_error( $global_styles_config ) ) { return $global_styles_config; } $fields = $this->get_fields_for_response( $request ); $data = array(); $theme_json = null; if ( ! empty( $global_styles_config['styles'] ) || ! empty( $global_styles_config['settings'] ) ) { $theme_json = new WP_Theme_JSON( $global_styles_config, 'custom' ); $global_styles_config = $theme_json->get_raw_data(); if ( rest_is_field_included( 'settings', $fields ) ) { $data['settings'] = ! empty( $global_styles_config['settings'] ) ? $global_styles_config['settings'] : new stdClass(); } if ( rest_is_field_included( 'styles', $fields ) ) { $data['styles'] = ! empty( $global_styles_config['styles'] ) ? $global_styles_config['styles'] : new stdClass(); } } if ( rest_is_field_included( 'author', $fields ) ) { $data['author'] = (int) $post->post_author; } if ( rest_is_field_included( 'date', $fields ) ) { $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date ); } if ( rest_is_field_included( 'date_gmt', $fields ) ) { $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt ); } if ( rest_is_field_included( 'id', $fields ) ) { $data['id'] = (int) $post->ID; } if ( rest_is_field_included( 'modified', $fields ) ) { $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified ); } if ( rest_is_field_included( 'modified_gmt', $fields ) ) { $data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt ); } if ( rest_is_field_included( 'parent', $fields ) ) { $data['parent'] = (int) $parent->ID; } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); $resolved_theme_uris = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme_json ); if ( ! empty( $resolved_theme_uris ) ) { $response->add_links( array( 'https://api.w.org/theme-file' => $resolved_theme_uris, ) ); } return $response; } /** * Retrieves the revision's schema, conforming to JSON Schema. * * @since 6.3.0 * @since 6.6.0 Merged parent and parent controller schema data. * * @return array Item schema data. */ public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $schema = parent::get_item_schema(); $parent_schema = $this->parent_controller->get_item_schema(); $schema['properties'] = array_merge( $schema['properties'], $parent_schema['properties'] ); unset( $schema['properties']['guid'], $schema['properties']['slug'], $schema['properties']['meta'], $schema['properties']['content'], $schema['properties']['title'] ); $this->schema = $schema; return $this->add_additional_fields_schema( $this->schema ); } /** * Retrieves the query params for collections. * Removes params that are not supported by global styles revisions. * * @since 6.6.0 * * @return array Collection parameters. */ public function get_collection_params() { $query_params = parent::get_collection_params(); unset( $query_params['exclude'], $query_params['include'], $query_params['search'], $query_params['order'], $query_params['orderby'] ); return $query_params; } } e() { $api_key = $this->get_api_key(); if ( is_wp_error( $api_key ) ) { return $api_key; } $response = $this->request_api( [ 'a' => 'clear_cache', 'k' => $api_key['k'], 's' => $api_key['s'], ] ); if ( is_wp_error( $response ) ) { return $response; } Logger::info( 'Sucuri firewall cache cleared.', [ 'sucuri firewall cache', ] ); return true; } /** * Get the API key. * * @since 3.2 * * @return array|WP_Error An array with the keys 'k' and 's', required by the API. A WP_Error object if no key or invalid key. */ private function get_api_key() { $api_key = trim( $this->options->get( 'sucury_waf_api_key', '' ) ); if ( ! $api_key ) { Logger::error( 'API key was not found.', [ 'sucuri firewall cache', ] ); return new WP_Error( 'no_sucuri_api_key', __( 'Sucuri firewall API key was not found.', 'rocket' ) ); } $matches = self::is_api_key_valid( $api_key ); if ( ! $matches ) { Logger::error( 'API key is invalid.', [ 'sucuri firewall cache', ] ); return new WP_Error( 'invalid_sucuri_api_key', __( 'Sucuri firewall API key is invalid.', 'rocket' ) ); } return [ 'k' => $matches['k'], 's' => $matches['s'], ]; } /** * Request against the API. * * @since 3.2 * * @param array $params Parameters to send. * * @return array|WP_Error The response data on success. A WP_Error object on failure. */ private function request_api( $params = [] ) { $params['time'] = time(); $params = $this->build_query( $params ); $url = sprintf( static::API_URL, $params ); /** * Filters the arguments for the Sucuri API request * * @since 3.3.4 * * @param array $args Arguments for the request. */ $args = apply_filters( 'rocket_sucuri_api_request_args', [ 'timeout' => 5, 'redirection' => 5, 'httpversion' => '1.1', 'blocking' => true, // This filter is documented in wp-includes/class-wp-http-streams.php. 'sslverify' => apply_filters( 'https_ssl_verify', true ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ] ); $response = wp_remote_get( $url, $args ); if ( is_wp_error( $response ) ) { Logger::error( 'Error when contacting the API.', [ 'sucuri firewall cache', 'url' => $url, 'response' => $response->get_error_message(), ] ); // translators: %s is an error message. return new WP_Error( 'wp_error_sucuri_api', sprintf( __( 'Error when contacting Sucuri firewall API. Error message was: %s', 'rocket' ), $response->get_error_message() ) ); } $contents = wp_remote_retrieve_body( $response ); if ( empty( $contents ) ) { Logger::error( 'Could not get a response from the API.', [ 'sucuri firewall cache', 'url' => $url, 'response' => $response, ] ); return new WP_Error( 'sucuri_api_no_response', __( 'Could not get a response from the Sucuri firewall API.', 'rocket' ) ); } $data = json_decode( $contents, true ); if ( ! $data || ! is_array( $data ) ) { Logger::error( 'Invalid response from the API.', [ 'sucuri firewall cache', 'url' => $url, 'response_body' => $contents, ] ); return new WP_Error( 'sucuri_api_invalid_response', __( 'Got an invalid response from the Sucuri firewall API.', 'rocket' ) ); } if ( empty( $data['status'] ) ) { Logger::error( 'The action failed.', [ 'sucuri firewall cache', 'url' => $url, 'response_data' => $data, ] ); if ( empty( $data['messages'] ) || ! is_array( $data['messages'] ) ) { return new WP_Error( 'sucuri_api_error_status', __( 'The Sucuri firewall API returned an unknown error.', 'rocket' ) ); } // translators: %s is an error message. $message = _n( 'The Sucuri firewall API returned the following error: %s', 'The Sucuri firewall API returned the following errors: %s', count( $data['messages'] ), 'rocket' ); $message = sprintf( $message, '
' . implode( '
', $data['messages'] ) ); return new WP_Error( 'sucuri_api_error_status', $message ); } return $data; } /** * Add the helper message on the CDN settings. * * @param string[] $addons Name from the addon that requires the helper message. * @return string[] */ public function add_cdn_helper_message( array $addons ): array { if ( ! $this->options->get( 'sucury_waf_cache_sync', false ) ) { return $addons; } $addons[] = 'Sucuri'; return $addons; } /** * An i18n-friendly alternative to the built-in PHP method `http_build_query()`. * * @param array|object $params An array or object containing properties. * * @return string An URL-encoded string. */ private function build_query( $params ): string { if ( ! $params ) { return ''; } $params = (array) $params; foreach ( $params as $param => $value ) { $params[ $param ] = $param . '=' . rawurlencode( (string) $value ); } return implode( '&', $params ); } }
Fatal error: Uncaught TypeError: WP_Rocket\Event_Management\Event_Manager::add_subscriber(): Argument #1 ($subscriber) must be of type WP_Rocket\Event_Management\Subscriber_Interface, string given, called in /htdocs/le-blog.fr/wp-content/plugins/wp-rocket/inc/Plugin.php on line 168 and defined in /htdocs/le-blog.fr/wp-content/plugins/wp-rocket/inc/classes/event-management/class-event-manager.php:33 Stack trace: #0 /htdocs/le-blog.fr/wp-content/plugins/wp-rocket/inc/Plugin.php(168): WP_Rocket\Event_Management\Event_Manager->add_subscriber('WP_Rocket\\Addon...') #1 /htdocs/le-blog.fr/wp-content/plugins/wp-rocket/inc/main.php(47): WP_Rocket\Plugin->load() #2 /htdocs/le-blog.fr/wp-includes/class-wp-hook.php(341): rocket_init('') #3 /htdocs/le-blog.fr/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters(NULL, Array) #4 /htdocs/le-blog.fr/wp-includes/plugin.php(522): WP_Hook->do_action(Array) #5 /htdocs/le-blog.fr/wp-settings.php(593): do_action('plugins_loaded') #6 /htdocs/le-blog.fr/wp-config.php(102): require_once('/htdocs/le-blog...') #7 /htdocs/le-blog.fr/wp-load.php(50): require_once('/htdocs/le-blog...') #8 /htdocs/le-blog.fr/wp-blog-header.php(13): require_once('/htdocs/le-blog...') #9 /htdocs/le-blog.fr/index.php(17): require('/htdocs/le-blog...') #10 {main} thrown in /htdocs/le-blog.fr/wp-content/plugins/wp-rocket/inc/classes/event-management/class-event-manager.php on line 33