Changeset 42343 for trunk/src/wp-includes/class-wp-embed.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-embed.php
r42009 r42343 10 10 public $handlers = array(); 11 11 public $post_ID; 12 public $usecache = true;12 public $usecache = true; 13 13 public $linkifunknown = true; 14 public $last_attr = array();15 public $last_url = '';14 public $last_attr = array(); 15 public $last_url = ''; 16 16 17 17 /** … … 82 82 $post = get_post(); 83 83 84 if ( ! $post || empty( $_GET['message'] ) ) 84 if ( ! $post || empty( $_GET['message'] ) ) { 85 85 return; 86 } 86 87 87 88 ?> … … 107 108 */ 108 109 public function register_handler( $id, $regex, $callback, $priority = 10 ) { 109 $this->handlers[ $priority][$id] = array(110 $this->handlers[ $priority ][ $id ] = array( 110 111 'regex' => $regex, 111 112 'callback' => $callback, … … 157 158 158 159 $rawattr = $attr; 159 $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) );160 $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) ); 160 161 161 162 $this->last_attr = $attr; … … 170 171 foreach ( $handlers as $id => $handler ) { 171 172 if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { 172 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) 173 if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) { 173 174 /** 174 175 * Filters the returned embed handler. … … 183 184 */ 184 185 return apply_filters( 'embed_handler_html', $return, $url, $attr ); 186 } 185 187 } 186 188 } … … 217 219 218 220 if ( $post_ID ) { 219 $cache = get_post_meta( $post_ID, $cachekey, true );221 $cache = get_post_meta( $post_ID, $cachekey, true ); 220 222 $cache_time = get_post_meta( $post_ID, $cachekey_time, true ); 221 223 … … 286 288 287 289 $insert_post_args = array( 288 'post_name' => $key_suffix,290 'post_name' => $key_suffix, 289 291 'post_status' => 'publish', 290 'post_type' => 'oembed_cache',292 'post_type' => 'oembed_cache', 291 293 ); 292 294 293 295 if ( $html ) { 294 296 if ( $cached_post_id ) { 295 wp_update_post( wp_slash( array( 296 'ID' => $cached_post_id, 297 'post_content' => $html, 298 ) ) ); 297 wp_update_post( 298 wp_slash( 299 array( 300 'ID' => $cached_post_id, 301 'post_content' => $html, 302 ) 303 ) 304 ); 299 305 } else { 300 wp_insert_post( wp_slash( array_merge( 301 $insert_post_args, 302 array( 303 'post_content' => $html, 306 wp_insert_post( 307 wp_slash( 308 array_merge( 309 $insert_post_args, 310 array( 311 'post_content' => $html, 312 ) 313 ) 304 314 ) 305 ) ) );315 ); 306 316 } 307 317 } elseif ( ! $cache ) { 308 wp_insert_post( wp_slash( array_merge( 309 $insert_post_args, 310 array( 311 'post_content' => '{{unknown}}', 318 wp_insert_post( 319 wp_slash( 320 array_merge( 321 $insert_post_args, 322 array( 323 'post_content' => '{{unknown}}', 324 ) 325 ) 312 326 ) 313 ) ) );327 ); 314 328 } 315 329 … … 336 350 public function delete_oembed_caches( $post_ID ) { 337 351 $post_metas = get_post_custom_keys( $post_ID ); 338 if ( empty( $post_metas) )352 if ( empty( $post_metas ) ) { 339 353 return; 354 } 340 355 341 356 foreach ( $post_metas as $post_meta_key ) { 342 if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) 357 if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) { 343 358 delete_post_meta( $post_ID, $post_meta_key ); 359 } 344 360 } 345 361 } … … 361 377 * @param array $post_types Array of post types to cache oEmbed results for. Defaults to post types with `show_ui` set to true. 362 378 */ 363 if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ) {379 if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ) { 364 380 return; 365 381 } … … 367 383 // Trigger a caching 368 384 if ( ! empty( $post->post_content ) ) { 369 $this->post_ID = $post->ID;385 $this->post_ID = $post->ID; 370 386 $this->usecache = false; 371 387 … … 407 423 */ 408 424 public function autoembed_callback( $match ) { 409 $oldval = $this->linkifunknown;425 $oldval = $this->linkifunknown; 410 426 $this->linkifunknown = false; 411 $return = $this->shortcode( array(), $match[2] );427 $return = $this->shortcode( array(), $match[2] ); 412 428 $this->linkifunknown = $oldval; 413 429 … … 426 442 } 427 443 428 $output = ( $this->linkifunknown ) ? '<a href="' . esc_url( $url) . '">' . esc_html($url) . '</a>' : $url;444 $output = ( $this->linkifunknown ) ? '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>' : $url; 429 445 430 446 /** … … 455 471 } 456 472 457 $oembed_post_query = new WP_Query( array( 458 'post_type' => 'oembed_cache', 459 'post_status' => 'publish', 460 'name' => $cache_key, 461 'posts_per_page' => 1, 462 'no_found_rows' => true, 463 'cache_results' => true, 464 'update_post_meta_cache' => false, 465 'update_post_term_cache' => false, 466 'lazy_load_term_meta' => false, 467 ) ); 473 $oembed_post_query = new WP_Query( 474 array( 475 'post_type' => 'oembed_cache', 476 'post_status' => 'publish', 477 'name' => $cache_key, 478 'posts_per_page' => 1, 479 'no_found_rows' => true, 480 'cache_results' => true, 481 'update_post_meta_cache' => false, 482 'update_post_term_cache' => false, 483 'lazy_load_term_meta' => false, 484 ) 485 ); 468 486 469 487 if ( ! empty( $oembed_post_query->posts ) ) {
Note: See TracChangeset
for help on using the changeset viewer.