mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-07 14:14:36 +00:00
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:
@@ -799,27 +799,39 @@ function wp_extract_urls( $content ) {
|
||||
* pingbacks and trackbacks.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @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.
|
||||
*
|
||||
* @global wpdb $wpdb WordPress database abstraction object.
|
||||
*
|
||||
* @param string $content Post Content.
|
||||
* @param int $post_ID Post ID.
|
||||
* @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.
|
||||
*/
|
||||
function do_enclose( $content, $post_ID ) {
|
||||
function do_enclose( $content = null, $post ) {
|
||||
global $wpdb;
|
||||
|
||||
//TODO: Tidy this ghetto code up and make the debug code optional
|
||||
include_once( ABSPATH . WPINC . '/class-IXR.php' );
|
||||
|
||||
$post = get_post( $post );
|
||||
if ( ! $post ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( null === $content ) {
|
||||
$content = $post->post_content;
|
||||
}
|
||||
|
||||
$post_links = array();
|
||||
|
||||
$pung = get_enclosed( $post_ID );
|
||||
$pung = get_enclosed( $post->ID );
|
||||
|
||||
$post_links_temp = wp_extract_urls( $content );
|
||||
|
||||
foreach ( $pung as $link_test ) {
|
||||
if ( ! in_array( $link_test, $post_links_temp ) ) { // link no longer in post
|
||||
$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 ) . '%' ) );
|
||||
$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 ) . '%' ) );
|
||||
foreach ( $mids as $mid ) {
|
||||
delete_metadata_by_mid( 'post', $mid );
|
||||
}
|
||||
@@ -851,10 +863,10 @@ function do_enclose( $content, $post_ID ) {
|
||||
* @param array $post_links An array of enclosure links.
|
||||
* @param int $post_ID Post ID.
|
||||
*/
|
||||
$post_links = apply_filters( 'enclosure_links', $post_links, $post_ID );
|
||||
$post_links = apply_filters( 'enclosure_links', $post_links, $post->ID );
|
||||
|
||||
foreach ( (array) $post_links as $url ) {
|
||||
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 ) . '%' ) ) ) {
|
||||
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 ) . '%' ) ) ) {
|
||||
|
||||
$headers = wp_get_http_headers( $url );
|
||||
if ( $headers ) {
|
||||
@@ -878,7 +890,7 @@ function do_enclose( $content, $post_ID ) {
|
||||
}
|
||||
|
||||
if ( in_array( substr( $type, 0, strpos( $type, '/' ) ), $allowed_types ) ) {
|
||||
add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
|
||||
add_post_meta( $post->ID, 'enclosure', "$url\n$len\n$mime\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user