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 #36824.

git-svn-id: https://develop.svn.wordpress.org/trunk@46175 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2019-09-19 01:48:54 +00:00
parent 20a17438d0
commit 48e280db32
3 changed files with 339 additions and 12 deletions

View File

@@ -2639,10 +2639,20 @@ function do_all_pings() {
pingback( $ping->post_content, $ping->ID );
}
// 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 );
// 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 );
}
// Do Trackbacks