<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52008] trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php: REST API: Improve translations, comments, and readability in URL Details endpoint.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52008">52008</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52008","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>hellofromTonya</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-11-04 12:42:26 +0000 (Thu, 04 Nov 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>REST API: Improve translations, comments, and readability in URL Details endpoint.
Improvements:
* Removes HTML tags from translatable strings. Uses `sprintf` with placeholder and translators comment.
* Spells out "OG" to "Open Graph" to help translators.
* Adds `@since` param to new filters.
* Improves comments for code standards and consistency.
* Improves readability by making multiple args multiline.
* Micro-optimizations to avoid unnecessary variable assignments.
Follow-up to <a href="https://core.trac.wordpress.org/changeset/51973">[51973]</a>.
Props hellofromTonya, sergeybiryukov, swissspidy.
Fixes <a href="https://core.trac.wordpress.org/ticket/54358">#54358</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswpresturldetailscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesrestapiendpointsclasswpresturldetailscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php 2021-11-03 20:00:36 UTC (rev 52007)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php 2021-11-04 12:42:26 UTC (rev 52008)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -69,19 +69,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->add_additional_fields_schema( $this->schema );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $schema = array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->schema = array(
</ins><span class="cx" style="display: block; padding: 0 10px"> '$schema' => 'http://json-schema.org/draft-04/schema#',
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => 'url-details',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'object',
</span><span class="cx" style="display: block; padding: 0 10px"> 'properties' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'title' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'The contents of the <title> element from the URL.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => sprintf(
+ /* translators: %s: HTML title tag. */
+ __( 'The contents of the %s element from the URL.' ),
+ '<title>'
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit', 'embed' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'icon' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'The favicon image link of the <link rel="icon"> element from the URL.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => sprintf(
+ /* translators: %s: HTML link tag. */
+ __( 'The favicon image link of the %s element from the URL.' ),
+ '<link rel="icon">'
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'format' => 'uri',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit', 'embed' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -88,13 +96,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'The content of the <meta name="description"> element from the URL.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => sprintf(
+ /* translators: %s: HTML meta tag. */
+ __( 'The content of the %s element from the URL.' ),
+ '<meta name="description">'
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit', 'embed' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'image' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'description' => __( 'The OG image link of the <meta property="og:image"> or <meta property="og:image:url"> element from the URL.' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'description' => sprintf(
+ /* translators: 1: HTML meta tag, 2: HTML meta tag. */
+ __( 'The Open Graph image link of the %1$s or %2$s element from the URL.' ),
+ '<meta property="og:image">',
+ '<meta property="og:image:url">'
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span><span class="cx" style="display: block; padding: 0 10px"> 'format' => 'uri',
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit', 'embed' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -103,18 +120,16 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->schema = $schema;
-
</del><span class="cx" style="display: block; padding: 0 10px"> return $this->add_additional_fields_schema( $this->schema );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Retrieves the contents of the <title> tag from the HTML response.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Retrieves the contents of the `<title>` tag from the HTML response.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_REST_REQUEST $request Full details about the request.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return WP_REST_Response|WP_Error The parsed details as a response object, or an error.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return WP_REST_Response|WP_Error The parsed details as a response object. WP_Error if there are errors.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function parse_url_details( $request ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $url = untrailingslashit( $request['url'] );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -162,10 +177,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the URL data for the response.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param WP_REST_Response $response The response object.
- * @param string $url The requested URL.
- * @param WP_REST_Request $request Request object.
- * @param array $remote_url_response HTTP response body from the remote URL.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.9.0
+ *
+ * @param WP_REST_Response $response The response object.
+ * @param string $url The requested URL.
+ * @param WP_REST_Request $request Request object.
+ * @param string $remote_url_response HTTP response body from the remote URL.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> return apply_filters( 'rest_prepare_url_details', $response, $url, $request, $remote_url_response );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -175,7 +192,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return WP_Error|bool True if the request has access, or WP_Error object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return WP_Error|bool True if the request has permission, else WP_Error.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function permissions_check() {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( current_user_can( 'edit_posts' ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -200,8 +217,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $url The website url whose HTML we want to access.
- * @return string|WP_Error The HTTP response from the remote URL, or an error.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $url The website URL whose HTML to access.
+ * @return string|WP_Error The HTTP response from the remote URL on success.
+ * WP_Error if no response or no content.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_remote_url( $url ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -226,8 +244,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Can be used to adjust response size limit and other WP_Http::request args.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $args Arguments used for the HTTP request
- * @param string $url The attempted URL.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.9.0
+ *
+ * @param array $args Arguments used for the HTTP request.
+ * @param string $url The attempted URL.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $args = apply_filters( 'rest_url_details_http_request_args', $args, $url );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -235,13 +255,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( WP_Http::OK !== wp_remote_retrieve_response_code( $response ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Not saving the error response to cache since the error might be temporary.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return new WP_Error( 'no_response', __( 'URL not found. Response returned a non-200 status code for this URL.' ), array( 'status' => WP_Http::NOT_FOUND ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return new WP_Error(
+ 'no_response',
+ __( 'URL not found. Response returned a non-200 status code for this URL.' ),
+ array( 'status' => WP_Http::NOT_FOUND )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $remote_body = wp_remote_retrieve_body( $response );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $remote_body ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- return new WP_Error( 'no_content', __( 'Unable to retrieve body from response at this URL.' ), array( 'status' => WP_Http::NOT_FOUND ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return new WP_Error(
+ 'no_content',
+ __( 'Unable to retrieve body from response at this URL.' ),
+ array( 'status' => WP_Http::NOT_FOUND )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $remote_body;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -253,18 +281,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $html The HTML from the remote website at URL.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string The title tag contents on success, or an empty string.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The title tag contents on success. Empty string if not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_title( $html ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $pattern = '#<title[^>]*>(.*?)<\s*/\s*title>#is';
</span><span class="cx" style="display: block; padding: 0 10px"> preg_match( $pattern, $html, $match_title );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $title = ! empty( $match_title[1] ) && is_string( $match_title[1] ) ? trim( $match_title[1] ) : '';
-
- if ( empty( $title ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $match_title[1] ) || ! is_string( $match_title[1] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $title = trim( $match_title[1] );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> return $this->prepare_metadata_for_output( $title );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -275,24 +303,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $html The HTML from the remote website at URL.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $url The target website URL.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string The icon URI on success, or an empty string.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The icon URI on success. Empty string if not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_icon( $html, $url ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Grab the icon's link element.
</span><span class="cx" style="display: block; padding: 0 10px"> $pattern = '#<link\s[^>]*rel=(?:[\"\']??)\s*(?:icon|shortcut icon|icon shortcut)\s*(?:[\"\']??)[^>]*\/?>#isU';
</span><span class="cx" style="display: block; padding: 0 10px"> preg_match( $pattern, $html, $element );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $element = ! empty( $element[0] ) && is_string( $element[0] ) ? trim( $element[0] ) : '';
- if ( empty( $element ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $element[0] ) || ! is_string( $element[0] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $element = trim( $element[0] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Get the icon's href value.
</span><span class="cx" style="display: block; padding: 0 10px"> $pattern = '#href=([\"\']??)([^\" >]*?)\\1[^>]*#isU';
</span><span class="cx" style="display: block; padding: 0 10px"> preg_match( $pattern, $element, $icon );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $icon = ! empty( $icon[2] ) && is_string( $icon[2] ) ? trim( $icon[2] ) : '';
- if ( empty( $icon ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $icon[2] ) || ! is_string( $icon[2] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $icon = trim( $icon[2] );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // If the icon is a data URL, return it.
</span><span class="cx" style="display: block; padding: 0 10px"> $parsed_icon = parse_url( $icon );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -319,13 +347,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $meta_elements {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * A multi-dimensional indexed array on success, or empty array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A multi-dimensional indexed array on success, else empty array.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 0 Meta elements with a content attribute.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 1 Content attribute's opening quotation mark.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 2 Content attribute's value for each meta element.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string The meta description contents on success, or an empty string.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The meta description contents on success. Empty string if not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_description( $meta_elements ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Bail out if there are no meta elements.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -333,7 +361,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $description = $this->get_metadata_from_meta_element( $meta_elements, 'name', '(?:description|og:description)' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $description = $this->get_metadata_from_meta_element(
+ $meta_elements,
+ 'name',
+ '(?:description|og:description)'
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Bail out if description not found.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' === $description ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -344,7 +376,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Parses the Open Graph Image from the provided HTML.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Parses the Open Graph (OG) Image from the provided HTML.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * See: https://ogp.me/.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -351,7 +383,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $meta_elements {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * A multi-dimensional indexed array on success, or empty array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A multi-dimensional indexed array on success, else empty array.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 0 Meta elements with a content attribute.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 1 Content attribute's opening quotation mark.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -358,10 +390,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 2 Content attribute's value for each meta element.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $url The target website URL.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string The OG image on success, or empty string.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The OG image on success. Empty string if not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_image( $meta_elements, $url ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $image = $this->get_metadata_from_meta_element( $meta_elements, 'property', '(?:og:image|og:image:url)' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $image = $this->get_metadata_from_meta_element(
+ $meta_elements,
+ 'property',
+ '(?:og:image|og:image:url)'
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Bail out if image not found.
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' === $image ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -425,7 +461,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $key The cache key under which to store the value.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $data The data to be stored at the given cache key.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return bool True when transient set. False if fails.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return bool True when transient set. False if not set.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function set_cache( $key, $data = '' ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $ttl = HOUR_IN_SECONDS;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -436,7 +472,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Can be used to adjust the time until expiration in seconds for the cache
</span><span class="cx" style="display: block; padding: 0 10px"> * of the data retrieved for the given URL.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $ttl the time until cache expiration in seconds.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.9.0
+ *
+ * @param int $ttl The time until cache expiration in seconds.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $cache_expiration = apply_filters( 'rest_url_details_cache_expiration', $ttl );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -449,7 +487,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $html The string of HTML to parse.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string The `<head>..</head>` section on success, or original HTML.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The `<head>..</head>` section on success. Given `$html` if not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_document_head( $html ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $head_html = $html;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -487,7 +525,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $html The string of HTML to be parsed.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * A multi-dimensional indexed array on success, or empty array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A multi-dimensional indexed array on success, else empty array.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 0 Meta elements with a content attribute.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 1 Content attribute's opening quotation mark.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -567,15 +605,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 5.9.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $meta_elements {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * A multi-dimensional indexed array on success, or empty array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A multi-dimensional indexed array on success, else empty array.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 0 Meta elements with a content attribute.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 1 Content attribute's opening quotation mark.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string[] 2 Content attribute's value for each meta element.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $attr Attribute that identifies the element with the target metadata.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $attr Attribute that identifies the element with the target metadata.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param string $attr_value The attribute's value that identifies the element with the target metadata.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string The metadata on success, or an empty string.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string The metadata on success. Empty string if not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private function get_metadata_from_meta_element( $meta_elements, $attr, $attr_value ) {
</span><span class="cx" style="display: block; padding: 0 10px"> // Bail out if there are no meta elements.
</span></span></pre>
</div>
</div>
</body>
</html>