WP_REST_URL_Details_Controller
- Since
- 5.9.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php:18
Controller which provides REST endpoint for retrieving information from a remote site's HTML response.
Compatibility
- WordPress
- since 5.9.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 3
Every hook that fires from inside WP_REST_URL_Details_Controller, in the order it appears in the class, grouped by the method that fires it.
WP_REST_URL_Details_Controller::parse_url_details()
- apply_filters( rest_prepare_url_details )filter line 187
Methods · 17
- __construct()Constructs the controller.
- register_routes()Registers the necessary REST API routes.
- get_item_schema()Retrieves the item's schema, conforming to JSON Schema.
- parse_url_details()Retrieves the contents of the title tag from the HTML response.
- permissions_check()Checks whether a given request has permission to read remote URLs.
- get_remote_url()Retrieves the document title from a remote URL.
- get_title()Parses the title tag contents from the provided HTML.
- get_icon()Parses the site icon from the provided HTML.
- get_description()Parses the meta description from the provided HTML.
- get_image()Parses the Open Graph (OG) Image from the provided HTML.
- prepare_metadata_for_output()Prepares the metadata by: - stripping all HTML tags and tag entities.
- build_cache_key_for_url()Utility function to build cache key for a given URL.
- get_cache()Utility function to retrieve a value from the cache at a given key.
- set_cache()Utility function to cache a given data set at a given cache key.
- get_document_head()Retrieves the head element section.
- get_meta_with_content_elements()Gets all the meta tag elements that have a 'content' attribute.
- get_metadata_from_meta_element()Gets the metadata from a target meta element.
Source code
class WP_REST_URL_Details_Controller extends WP_REST_Controller { /** * Constructs the controller. * * @since 5.9.0 */ public function __construct() { $this->namespace = 'wp-block-editor/v1'; $this->rest_base = 'url-details'; } /** * Registers the necessary REST API routes. * * @since 5.9.0 */ public function register_routes() { register_rest_route( $this->namespace, '/' . $this->rest_base, array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'parse_url_details' ), 'args' => array( 'url' => array( 'required' => true, 'description' => __( 'The URL to process.' ), 'validate_callback' => 'wp_http_validate_url', 'sanitize_callback' => 'sanitize_url', 'type' => 'string', 'format' => 'uri', ), ), 'permission_callback' => array( $this, 'permissions_check' ), 'schema' => array( $this, 'get_public_item_schema' ), ), ) ); } /** * Retrieves the item's schema, conforming to JSON Schema. * * @since 5.9.0 * * @return array Item schema data. */ public function get_item_schema() { if ( $this->schema ) { return $this->add_additional_fields_schema( $this->schema ); } $this->schema = array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'url-details', 'type' => 'object', 'properties' => array( 'title' => array( 'description' => sprintf( /* translators: %s: HTML title tag. */ __( 'The contents of the %s element from the URL.' ), '<title>' ), 'type' => 'string', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ), 'icon' => array( 'description' => sprintf( /* translators: %s: HTML link tag. */ __( 'The favicon image link of the %s element from the URL.' ), '<link rel="icon">' ), 'type' => 'string', 'format' => 'uri', 'context' => array( 'view', 'edit', 'embed' ), 'readonly' => true, ),Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.