diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/class-wp-embed.php --- a/wp/wp-includes/class-wp-embed.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/class-wp-embed.php Mon Oct 14 18:28:13 2019 +0200 @@ -9,10 +9,10 @@ class WP_Embed { public $handlers = array(); public $post_ID; - public $usecache = true; + public $usecache = true; public $linkifunknown = true; - public $last_attr = array(); - public $last_url = ''; + public $last_attr = array(); + public $last_url = ''; /** * When a URL cannot be embedded, return false instead of returning a link @@ -81,16 +81,17 @@ public function maybe_run_ajax_cache() { $post = get_post(); - if ( ! $post || empty( $_GET['message'] ) ) + if ( ! $post || empty( $_GET['message'] ) ) { return; + } -?> + ?> -handlers[$priority][$id] = array( + $this->handlers[ $priority ][ $id ] = array( 'regex' => $regex, 'callback' => $callback, ); @@ -156,7 +157,7 @@ } $rawattr = $attr; - $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) ); + $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) ); $this->last_attr = $attr; @@ -169,7 +170,7 @@ foreach ( $this->handlers as $priority => $handlers ) { foreach ( $handlers as $id => $handler ) { if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { - if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) + if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) { /** * Filters the returned embed handler. * @@ -182,6 +183,7 @@ * @param array $attr An array of shortcode attributes. */ return apply_filters( 'embed_handler_html', $return, $url, $attr ); + } } } } @@ -216,7 +218,7 @@ $cached_post_id = $this->find_oembed_post_id( $key_suffix ); if ( $post_ID ) { - $cache = get_post_meta( $post_ID, $cachekey, true ); + $cache = get_post_meta( $post_ID, $cachekey, true ); $cache_time = get_post_meta( $post_ID, $cachekey_time, true ); if ( ! $cache_time ) { @@ -285,32 +287,44 @@ } $insert_post_args = array( - 'post_name' => $key_suffix, + 'post_name' => $key_suffix, 'post_status' => 'publish', - 'post_type' => 'oembed_cache', + 'post_type' => 'oembed_cache', ); if ( $html ) { if ( $cached_post_id ) { - wp_update_post( wp_slash( array( - 'ID' => $cached_post_id, - 'post_content' => $html, - ) ) ); + wp_update_post( + wp_slash( + array( + 'ID' => $cached_post_id, + 'post_content' => $html, + ) + ) + ); } else { - wp_insert_post( wp_slash( array_merge( - $insert_post_args, - array( - 'post_content' => $html, + wp_insert_post( + wp_slash( + array_merge( + $insert_post_args, + array( + 'post_content' => $html, + ) + ) ) - ) ) ); + ); } } elseif ( ! $cache ) { - wp_insert_post( wp_slash( array_merge( - $insert_post_args, - array( - 'post_content' => '{{unknown}}', + wp_insert_post( + wp_slash( + array_merge( + $insert_post_args, + array( + 'post_content' => '{{unknown}}', + ) + ) ) - ) ) ); + ); } if ( $has_kses ) { @@ -335,12 +349,14 @@ */ public function delete_oembed_caches( $post_ID ) { $post_metas = get_post_custom_keys( $post_ID ); - if ( empty($post_metas) ) + if ( empty( $post_metas ) ) { return; + } foreach ( $post_metas as $post_meta_key ) { - if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) + if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) { delete_post_meta( $post_ID, $post_meta_key ); + } } } @@ -358,15 +374,15 @@ * * @since 2.9.0 * - * @param array $post_types Array of post types to cache oEmbed results for. Defaults to post types with `show_ui` set to true. + * @param string[] $post_types Array of post type names to cache oEmbed results for. Defaults to post types with `show_ui` set to true. */ - if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ){ + if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ) { return; } // Trigger a caching if ( ! empty( $post->post_content ) ) { - $this->post_ID = $post->ID; + $this->post_ID = $post->ID; $this->usecache = false; $content = $this->run_shortcode( $post->post_content ); @@ -406,9 +422,9 @@ * @return string The embed HTML on success, otherwise the original URL. */ public function autoembed_callback( $match ) { - $oldval = $this->linkifunknown; + $oldval = $this->linkifunknown; $this->linkifunknown = false; - $return = $this->shortcode( array(), $match[2] ); + $return = $this->shortcode( array(), $match[2] ); $this->linkifunknown = $oldval; return $match[1] . $return . $match[3]; @@ -425,7 +441,7 @@ return false; } - $output = ( $this->linkifunknown ) ? '' . esc_html($url) . '' : $url; + $output = ( $this->linkifunknown ) ? '' . esc_html( $url ) . '' : $url; /** * Filters the returned, maybe-linked embed URL. @@ -454,17 +470,19 @@ return $oembed_post_id; } - $oembed_post_query = new WP_Query( array( - 'post_type' => 'oembed_cache', - 'post_status' => 'publish', - 'name' => $cache_key, - 'posts_per_page' => 1, - 'no_found_rows' => true, - 'cache_results' => true, - 'update_post_meta_cache' => false, - 'update_post_term_cache' => false, - 'lazy_load_term_meta' => false, - ) ); + $oembed_post_query = new WP_Query( + array( + 'post_type' => 'oembed_cache', + 'post_status' => 'publish', + 'name' => $cache_key, + 'posts_per_page' => 1, + 'no_found_rows' => true, + 'cache_results' => true, + 'update_post_meta_cache' => false, + 'update_post_term_cache' => false, + 'lazy_load_term_meta' => false, + ) + ); if ( ! empty( $oembed_post_query->posts ) ) { // Note: 'fields'=>'ids' is not being used in order to cache the post object as it will be needed.