WP_REST_URL_Details_Controller::get_image()
Parses the Open Graph (OG) Image from the provided HTML.
See: https://ogp.me/.
Метод класса: WP_REST_URL_Details_Controller{}
Хуков нет.
Возвращает
Строку
. The OG image on success. Empty string if not found.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_image( $meta_elements, $url );
- $meta_elements(массив) (обязательный)
A multi-dimensional indexed array on success, else empty array.
-
0(string[])
Meta elements with a content attribute. -
1(string[])
Content attribute's opening quotation mark. - 2(string[])
Content attribute's value for each meta element.
-
- $url(строка) (обязательный)
- The target website URL.
Список изменений
С версии 5.9.0 | Введена. |
Код WP_REST_URL_Details_Controller::get_image() WP REST URL Details Controller::get image WP 6.2.2
private function get_image( $meta_elements, $url ) { $image = $this->get_metadata_from_meta_element( $meta_elements, 'property', '(?:og:image|og:image:url)' ); // Bail out if image not found. if ( '' === $image ) { return ''; } // Attempt to convert relative URLs to absolute. $parsed_url = parse_url( $url ); if ( isset( $parsed_url['scheme'] ) && isset( $parsed_url['host'] ) ) { $root_url = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/'; $image = WP_Http::make_absolute_url( $image, $root_url ); } return $image; }