<!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>[46175] trunk: Improve `do_enclose()` logic on post publish.</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/46175">46175</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/46175","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-09-19 01:48:54 +0000 (Thu, 19 Sep 2019)</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'>Improve `do_enclose()` logic on post publish.
Removing the direct SQL query in `do_all_pings()` improves filterability.
As part of this change, the signature of `do_enclose()` is changed so that
a null `$content` parameter can be passed, with the `$content` then inferred
from the `$post` passed in the second parameter. In addition, the second
parameter was modified so that a post ID or a `WP_Post` object can be
provided. These changes make it possible to trigger enclosure checks with
a post ID alone (as in `do_all_pings()`) and also brings the function
signature in line with `do_trackbacks()` and `pingback()`.
Props dshanske, spacedmonkey, janw.oostendorp, mrmadhat, birgire.
See <a href="https://core.trac.wordpress.org/ticket/36824">#36824</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescommentphp">trunk/src/wp-includes/comment.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestsfunctionsdoEnclosephp">trunk/tests/phpunit/tests/functions/doEnclose.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescommentphp"></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/comment.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/comment.php 2019-09-19 01:25:14 UTC (rev 46174)
+++ trunk/src/wp-includes/comment.php 2019-09-19 01:48:54 UTC (rev 46175)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2639,10 +2639,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> pingback( $ping->post_content, $ping->ID );
</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">- // Do Enclosures
- while ( $enclosure = $wpdb->get_row( "SELECT ID, post_content, meta_id FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1" ) ) {
- delete_metadata_by_mid( 'post', $enclosure->meta_id );
- do_enclose( $enclosure->post_content, $enclosure->ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Do enclosures.
+ $enclosures = get_posts(
+ array(
+ 'post_type' => get_post_types(),
+ 'suppress_filters' => false,
+ 'nopaging' => true,
+ 'meta_key' => '_encloseme',
+ 'fields' => 'ids',
+ )
+ );
+
+ foreach ( $enclosure as $enclosure ) {
+ delete_post_meta( $enclosure, '_encloseme' );
+ do_enclose( null, $enclosure->ID );
</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"> // Do Trackbacks
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></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/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2019-09-19 01:25:14 UTC (rev 46174)
+++ trunk/src/wp-includes/functions.php 2019-09-19 01:48:54 UTC (rev 46175)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -799,27 +799,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * pingbacks and trackbacks.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 1.5.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.3.0 The `$content` parameter was made optional, and the `$post` parameter was
+ * updated to accept a post ID or a WP_Post object.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global wpdb $wpdb WordPress database abstraction object.
</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 $content Post Content.
- * @param int $post_ID Post ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $content Post content. If `null`, the `post_content` field from `$post` is used.
+ * @param int|WP_Post $post Post ID or post object.
+ * @return null|bool Returns false if post is not found.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function do_enclose( $content, $post_ID ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function do_enclose( $content = null, $post ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> //TODO: Tidy this ghetto code up and make the debug code optional
</span><span class="cx" style="display: block; padding: 0 10px"> include_once( ABSPATH . WPINC . '/class-IXR.php' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post = get_post( $post );
+ if ( ! $post ) {
+ return false;
+ }
+
+ if ( null === $content ) {
+ $content = $post->post_content;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_links = array();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $pung = get_enclosed( $post_ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $pung = get_enclosed( $post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post_links_temp = wp_extract_urls( $content );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $pung as $link_test ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! in_array( $link_test, $post_links_temp ) ) { // link no longer in post
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $mids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post_ID, $wpdb->esc_like( $link_test ) . '%' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $mids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $link_test ) . '%' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> foreach ( $mids as $mid ) {
</span><span class="cx" style="display: block; padding: 0 10px"> delete_metadata_by_mid( 'post', $mid );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -851,10 +863,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $post_links An array of enclosure links.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $post_ID Post ID.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_links = apply_filters( 'enclosure_links', $post_links, $post->ID );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( (array) $post_links as $url ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $url != '' && ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post_ID, $wpdb->esc_like( $url ) . '%' ) ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $url != '' && ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE %s", $post->ID, $wpdb->esc_like( $url ) . '%' ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $headers = wp_get_http_headers( $url );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $headers ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -878,7 +890,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"> if ( in_array( substr( $type, 0, strpos( $type, '/' ) ), $allowed_types ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" );
</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"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsfunctionsdoEnclosephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/functions/doEnclose.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/functions/doEnclose.php (rev 0)
+++ trunk/tests/phpunit/tests/functions/doEnclose.php 2019-09-19 01:48:54 UTC (rev 46175)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,305 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Test cases for the `do_enclose()` function.
+ *
+ * @package WordPress\UnitTests
+ *
+ * @since 5.3.0
+ */
+
+/**
+ * Tests_Functions_DoEnclose class.
+ *
+ * @group functions.php
+ * @group post
+ * @covers do_enclose
+ *
+ * @since 5.3.0
+ */
+class Tests_Functions_DoEnclose extends WP_UnitTestCase {
+
+ /**
+ * Setup before each test method.
+ *
+ * @since 5.3.0
+ */
+ public function setUp() {
+ parent::setUp();
+ add_filter( 'pre_http_request', array( $this, 'fake_http_request' ), 10, 3 );
+ }
+
+ /**
+ * Cleanup after each test method.
+ *
+ * @since 5.3.0
+ */
+ public function tearDown() {
+ parent::tearDown();
+ remove_filter( 'pre_http_request', array( $this, 'fake_http_request' ) );
+ }
+
+ /**
+ * Test the function with an explicit content input.
+ *
+ * @since 5.3.0
+ *
+ * @dataProvider data_test_do_enclose
+ */
+ public function test_function_with_explicit_content_input( $content, $expected ) {
+ $post_id = self::factory()->post->create();
+
+ do_enclose( $content, $post_id );
+
+ $actual = $this->get_enclosed_by_post_id( $post_id );
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * Test the function with an implicit content input.
+ *
+ * @since 5.3.0
+ *
+ * @dataProvider data_test_do_enclose
+ */
+ public function test_function_with_implicit_content_input( $content, $expected ) {
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_content' => $content,
+ )
+ );
+
+ do_enclose( null, $post_id );
+
+ $actual = $this->get_enclosed_by_post_id( $post_id );
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * Dataprovider for `test_function_with_explicit_content_input()`
+ * and `test_function_with_implicit_content_input()`.
+ *
+ * @since 5.3.0
+ *
+ * @return array {
+ * @type array {
+ * @type string Post content.
+ * @type string Expected values.
+ * }
+ * }
+ */
+ public function data_test_do_enclose() {
+ return array(
+ 'null' => array(
+ 'content' => null,
+ 'expected' => '',
+ ),
+ 'empty' => array(
+ 'content' => '',
+ 'expected' => '',
+ ),
+ 'single-bare-movie' => array(
+ 'content' => 'movie.mp4',
+ 'expected' => '',
+ ),
+ 'single-bare-audio' => array(
+ 'content' => 'audio.ogg',
+ 'expected' => '',
+ ),
+ 'single-relative-movie' => array(
+ 'content' => '/movie.mp4',
+ 'expected' => "/movie.mp4\n123\nvideo/mp4\n",
+ ),
+ 'single-relative-audio' => array(
+ 'content' => '/audio.ogg',
+ 'expected' => "/audio.ogg\n321\naudio/ogg\n",
+ ),
+ 'single-unknown' => array(
+ 'content' => 'https://example.com/wp-content/uploads/2018/06/file.unknown',
+ 'expected' => '',
+ ),
+ 'single-movie' => array(
+ 'content' => 'https://example.com/wp-content/uploads/2018/06/movie.mp4',
+ 'expected' => "https://example.com/wp-content/uploads/2018/06/movie.mp4\n123\nvideo/mp4\n",
+ ),
+ 'single-audio' => array(
+ 'content' => 'https://example.com/wp-content/uploads/2018/06/audio.ogg',
+ 'expected' => "https://example.com/wp-content/uploads/2018/06/audio.ogg\n321\naudio/ogg\n",
+ ),
+ 'single-movie-query' => array(
+ 'content' => 'https://example.com/wp-content/uploads/2018/06/movie.mp4?test=1',
+ 'expected' => "https://example.com/wp-content/uploads/2018/06/movie.mp4?test=1\n123\nvideo/mp4\n",
+ ),
+ 'multi' => array(
+ 'content' => "https://example.com/wp-content/uploads/2018/06/audio.ogg\n" .
+ 'https://example.com/wp-content/uploads/2018/06/movie.mp4',
+ 'expected' => "https://example.com/wp-content/uploads/2018/06/audio.ogg\n321\naudio/ogg\n" .
+ "https://example.com/wp-content/uploads/2018/06/movie.mp4\n123\nvideo/mp4\n",
+ ),
+ );
+ }
+
+ /**
+ * The function should return false when the post ID input is invalid.
+ *
+ * @since 5.3.0
+ */
+ public function test_function_should_return_false_when_invalid_post_id() {
+ $post_id = null;
+ $result = do_enclose( null, $post_id );
+ $this->assertFalse( $result );
+ }
+
+ /**
+ * The function should delete an enclosed link when it's no longer in the post content.
+ *
+ * @since 5.3.0
+ */
+ public function test_function_should_delete_enclosed_link_when_no_longer_in_post_content() {
+ $data = $this->data_test_do_enclose();
+
+ // Create a post with a single movie link.
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_content' => $data['single-movie']['content'],
+ )
+ );
+
+ do_enclose( null, $post_id );
+
+ $actual = $this->get_enclosed_by_post_id( $post_id );
+ $this->assertSame( $data['single-movie']['expected'], $actual );
+
+ // Replace the movie link with an audio link.
+ wp_update_post(
+ array(
+ 'ID' => $post_id,
+ 'post_content' => $data['single-audio']['content'],
+ )
+ );
+
+ do_enclose( null, $post_id );
+
+ $actual = $this->get_enclosed_by_post_id( $post_id );
+ $this->assertSame( $data['single-audio']['expected'], $actual );
+ }
+
+ /**
+ * The function should support a post object input.
+ *
+ * @since 5.3.0
+ */
+ public function test_function_should_support_post_object_input() {
+ $data = $this->data_test_do_enclose();
+
+ $post_object = self::factory()->post->create_and_get(
+ array(
+ 'post_content' => $data['multi']['content'],
+ )
+ );
+
+ do_enclose( null, $post_object );
+
+ $actual = $this->get_enclosed_by_post_id( $post_object->ID );
+ $this->assertSame( $data['multi']['expected'], $actual );
+ }
+
+ /**
+ * The enclosure links should be filterable with the `enclosure_links` filter.
+ *
+ * @since 5.3.0
+ */
+ public function test_function_enclosure_links_should_be_filterable() {
+ $data = $this->data_test_do_enclose();
+
+ $post_id = self::factory()->post->create(
+ array(
+ 'post_content' => $data['multi']['content'],
+ )
+ );
+
+ add_filter( 'enclosure_links', array( $this, 'filter_enclosure_links' ), 10, 2 );
+ do_enclose( null, $post_id );
+ remove_filter( 'enclosure_links', array( $this, 'filter_enclosure_links' ) );
+
+ $actual = $this->get_enclosed_by_post_id( $post_id );
+ $expected = str_replace( 'example.org', sprintf( 'example-%d.org', $post_id ), $data['multi']['expected'] );
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * A callback to filter the list of enclosure links.
+ *
+ * @since 5.3.0
+ *
+ * @param array $post_links An array of enclosure links.
+ * @param int $post_id Post ID.
+ * @return array $post_links An array of enclosure links.
+ */
+ public function filter_enclosure_links( $enclosure_links, $post_id ) {
+ // Replace the link host to contain the post ID, to test both filter input arguments.
+ foreach ( $enclosure_links as &$link ) {
+ $link = str_replace( 'example.org', sprintf( 'example-%d.org', $post_id ), $link );
+ }
+ return $enclosure_links;
+ }
+
+ /**
+ * Helper function to get all enclosure data for a given post.
+ *
+ * @since 5.3.0
+ *
+ * @param int $post_id Post ID.
+ * @return string All enclosure data for the given post.
+ */
+ protected function get_enclosed_by_post_id( $post_id ) {
+ return join( (array) get_post_meta( $post_id, 'enclosure', false ), '' );
+ }
+
+ /**
+ * Fake the HTTP request response.
+ *
+ * @since 5.3.0
+ *
+ * @param bool $false False.
+ * @param array $arguments Request arguments.
+ * @param string $url Request URL.
+ *
+ * @return array Header.
+ */
+ public function fake_http_request( $false, $arguments, $url ) {
+
+ // Video and audio headers.
+ $fake_headers = array(
+ 'mp4' => array(
+ 'headers' => array(
+ 'content-length' => 123,
+ 'content-type' => 'video/mp4',
+ ),
+ ),
+ 'ogg' => array(
+ 'headers' => array(
+ 'content-length' => 321,
+ 'content-type' => 'audio/ogg',
+ ),
+ ),
+ );
+
+ $path = parse_url( $url, PHP_URL_PATH );
+
+ if ( false !== $path ) {
+ $extension = pathinfo( $path, PATHINFO_EXTENSION );
+ if ( isset( $fake_headers[ $extension ] ) ) {
+ return $fake_headers[ $extension ];
+ }
+ }
+
+ // Fallback header.
+ return array(
+ 'headers' => array(
+ 'content-length' => 0,
+ 'content-type' => '',
+ ),
+ );
+ }
+
+}
</ins></span></pre>
</div>
</div>
</body>
</html>