WP_Font_Collection::load_from_url()
Loads the font collection data from a JSON file URL.
Метод класса: WP_Font_Collection{}
Хуков нет.
Возвращает
Массив|WP_Error
. An array containing the font collection data on success, else an instance of WP_Error on failure.
Использование
// private - только в коде основоного (родительского) класса $result = $this->load_from_url( $url );
- $url(строка) (обязательный)
- URL to a JSON file containing the font collection data.
Список изменений
С версии 6.5.0 | Введена. |
Код WP_Font_Collection::load_from_url() WP Font Collection::load from url WP 6.7.1
private function load_from_url( $url ) { // Limit key to 167 characters to avoid failure in the case of a long URL. $transient_key = substr( 'wp_font_collection_url_' . $url, 0, 167 ); $data = get_site_transient( $transient_key ); if ( false === $data ) { $response = wp_safe_remote_get( $url ); if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { return new WP_Error( 'font_collection_request_error', sprintf( // translators: %s: Font collection URL. __( 'Error fetching the font collection data from "%s".' ), $url ) ); } $data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( empty( $data ) ) { return new WP_Error( 'font_collection_decode_error', __( 'Error decoding the font collection data from the HTTP response JSON.' ) ); } // Make sure the data is valid before storing it in a transient. $data = $this->sanitize_and_validate_data( $data, array( 'font_families' ) ); if ( is_wp_error( $data ) ) { return $data; } set_site_transient( $transient_key, $data, DAY_IN_SECONDS ); } return $data; }