Changeset 44154 for trunk/src/wp-includes/embed.php
- Timestamp:
- 12/14/2018 03:19:48 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/5.0 merged: 43810
- Property svn:mergeinfo changed
-
trunk/src/wp-includes/embed.php
r43571 r44154 62 62 */ 63 63 function wp_embed_defaults( $url = '' ) { 64 if ( ! empty( $GLOBALS['content_width'] ) ) {64 if ( ! empty( $GLOBALS['content_width'] ) ) 65 65 $width = (int) $GLOBALS['content_width']; 66 } 67 68 if ( empty( $width ) ) { 66 67 if ( empty( $width ) ) 69 68 $width = 500; 70 }71 69 72 70 $height = min( ceil( $width * 1.5 ), 1000 ); … … 77 75 * @since 2.9.0 78 76 * 79 * @param int[]$size An array of embed width and height values77 * @param array $size An array of embed width and height values 80 78 * in pixels (in that order). 81 79 * @param string $url The URL that should be embedded. … … 134 132 function wp_oembed_add_provider( $format, $provider, $regex = false ) { 135 133 if ( did_action( 'plugins_loaded' ) ) { 136 $oembed 137 $oembed->providers[ $format] = array( $provider, $regex );134 $oembed = _wp_oembed_get_object(); 135 $oembed->providers[$format] = array( $provider, $regex ); 138 136 } else { 139 137 WP_oEmbed::_add_provider_early( $format, $provider, $regex ); … … 229 227 function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) { 230 228 global $wp_embed; 231 $embed = $wp_embed->autoembed( sprintf( 'https://youtube.com/watch?v=%s', urlencode( $matches[2] ) ) );229 $embed = $wp_embed->autoembed( sprintf( "https://youtube.com/watch?v=%s", urlencode( $matches[2] ) ) ); 232 230 233 231 /** … … 398 396 399 397 if ( '' !== $permalink ) { 400 $url = add_query_arg( 401 array( 402 'url' => urlencode( $permalink ), 403 'format' => ( 'json' !== $format ) ? $format : false, 404 ), 405 $url 406 ); 398 $url = add_query_arg( array( 399 'url' => urlencode( $permalink ), 400 'format' => ( 'json' !== $format ) ? $format : false, 401 ), $url ); 407 402 } 408 403 … … 455 450 * and edit wp-embed.js directly. 456 451 */ 457 $output .= 452 $output .=<<<JS 458 453 include "js/wp-embed.min.js" 459 454 JS; … … 523 518 * } 524 519 */ 525 $min_max_width = apply_filters( 526 'oembed_min_max_width', 527 array( 528 'min' => 200, 529 'max' => 600, 530 ) 531 ); 520 $min_max_width = apply_filters( 'oembed_min_max_width', array( 521 'min' => 200, 522 'max' => 600 523 ) ); 532 524 533 525 $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] ); … … 564 556 } 565 557 558 559 /** 560 * Retrieves the oEmbed response data for a given URL. 561 * 562 * @since 5.0.0 563 * 564 * @param string $url The URL that should be inspected for discovery `<link>` tags. 565 * @param array $args oEmbed remote get arguments. 566 * @return object|false oEmbed response data if the URL does belong to the current site. False otherwise. 567 */ 568 function get_oembed_response_data_for_url( $url, $args ) { 569 $switched_blog = false; 570 571 if ( is_multisite() ) { 572 $url_parts = wp_parse_args( wp_parse_url( $url ), array( 573 'host' => '', 574 'path' => '/', 575 ) ); 576 577 $qv = array( 'domain' => $url_parts['host'], 'path' => '/' ); 578 579 // In case of subdirectory configs, set the path. 580 if ( ! is_subdomain_install() ) { 581 $path = explode( '/', ltrim( $url_parts['path'], '/' ) ); 582 $path = reset( $path ); 583 584 if ( $path ) { 585 $qv['path'] = get_network()->path . $path . '/'; 586 } 587 } 588 589 $sites = get_sites( $qv ); 590 $site = reset( $sites ); 591 592 if ( $site && (int) $site->blog_id !== get_current_blog_id() ) { 593 switch_to_blog( $site->blog_id ); 594 $switched_blog = true; 595 } 596 } 597 598 $post_id = url_to_postid( $url ); 599 600 /** This filter is documented in wp-includes/class-wp-oembed-controller.php */ 601 $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url ); 602 603 if ( ! $post_id ) { 604 if ( $switched_blog ) { 605 restore_current_blog(); 606 } 607 608 return false; 609 } 610 611 $width = isset( $args['width'] ) ? $args['width'] : 0; 612 613 $data = get_oembed_response_data( $post_id, $width ); 614 615 if ( $switched_blog ) { 616 restore_current_blog(); 617 } 618 619 return $data ? (object) $data : false; 620 } 621 622 566 623 /** 567 624 * Filters the oEmbed response data to return an iframe embed code. … … 591 648 if ( wp_attachment_is_image( $post ) ) { 592 649 $thumbnail_id = $post->ID; 593 } else if ( wp_attachment_is( 'video', $post ) ) {650 } else if ( wp_attachment_is( 'video', $post ) ) { 594 651 $thumbnail_id = get_post_thumbnail_id( $post ); 595 652 $data['type'] = 'video'; … … 599 656 if ( $thumbnail_id ) { 600 657 list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) ); 601 $data['thumbnail_url'] 602 $data['thumbnail_width'] 603 $data['thumbnail_height'] 658 $data['thumbnail_url'] = $thumbnail_url; 659 $data['thumbnail_width'] = $thumbnail_width; 660 $data['thumbnail_height'] = $thumbnail_height; 604 661 } 605 662 … … 738 795 $allowed_html = array( 739 796 'a' => array( 740 'href' => true,797 'href' => true, 741 798 ), 742 799 'blockquote' => array(), … … 768 825 769 826 $url = esc_url( "{$results[2]}#?secret=$secret" ); 770 $q 827 $q = $results[1]; 771 828 772 829 $html = str_replace( $results[0], ' src=' . $q . $url . $q . ' data-secret=' . $q . $secret . $q, $html ); … … 775 832 776 833 $allowed_html['blockquote']['data-secret'] = true; 777 $allowed_html['iframe']['data-secret'] 834 $allowed_html['iframe']['data-secret'] = true; 778 835 779 836 $html = wp_kses( $html, $allowed_html ); … … 806 863 } 807 864 808 $link = sprintf( 809 '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>', 865 $link = sprintf( '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>', 810 866 esc_url( get_permalink() ), 811 867 /* translators: %s: Name of current post */ … … 883 939 <style type="text/css"> 884 940 <?php 885 if ( SCRIPT_DEBUG ) {886 readfile( ABSPATH . WPINC . '/css/wp-embed-template.css');887 } else {888 /*889 * If you're looking at a src version of this file, you'll see an "include"890 * statement below. This is used by the `grunt build` process to directly891 * include a minified version of wp-oembed-embed.css, instead of using the892 * readfile() method from above.893 *894 * If you're looking at a build version of this file, you'll see a string of895 * minified CSS. If you need to debug it, please turn on SCRIPT_DEBUG896 * and edit wp-embed-template.css directly.897 */898 ?>899 include "css/wp-embed-template.min.css"900 <?php901 }941 if ( SCRIPT_DEBUG ) { 942 readfile( ABSPATH . WPINC . "/css/wp-embed-template.css" ); 943 } else { 944 /* 945 * If you're looking at a src version of this file, you'll see an "include" 946 * statement below. This is used by the `grunt build` process to directly 947 * include a minified version of wp-oembed-embed.css, instead of using the 948 * readfile() method from above. 949 * 950 * If you're looking at a build version of this file, you'll see a string of 951 * minified CSS. If you need to debug it, please turn on SCRIPT_DEBUG 952 * and edit wp-embed-template.css directly. 953 */ 954 ?> 955 include "css/wp-embed-template.min.css" 956 <?php 957 } 902 958 ?> 903 959 </style> … … 914 970 <script type="text/javascript"> 915 971 <?php 916 if ( SCRIPT_DEBUG ) {917 readfile( ABSPATH . WPINC . '/js/wp-embed-template.js');918 } else {919 /*920 * If you're looking at a src version of this file, you'll see an "include"921 * statement below. This is used by the `grunt build` process to directly922 * include a minified version of wp-embed-template.js, instead of using the923 * readfile() method from above.924 *925 * If you're looking at a build version of this file, you'll see a string of926 * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG927 * and edit wp-embed-template.js directly.928 */929 ?>930 include "js/wp-embed-template.min.js"931 <?php932 }972 if ( SCRIPT_DEBUG ) { 973 readfile( ABSPATH . WPINC . "/js/wp-embed-template.js" ); 974 } else { 975 /* 976 * If you're looking at a src version of this file, you'll see an "include" 977 * statement below. This is used by the `grunt build` process to directly 978 * include a minified version of wp-embed-template.js, instead of using the 979 * readfile() method from above. 980 * 981 * If you're looking at a build version of this file, you'll see a string of 982 * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG 983 * and edit wp-embed-template.js directly. 984 */ 985 ?> 986 include "js/wp-embed-template.min.js" 987 <?php 988 } 933 989 ?> 934 990 </script> … … 1081 1137 */ 1082 1138 function wp_filter_pre_oembed_result( $result, $url, $args ) { 1083 $switched_blog = false; 1084 1085 if ( is_multisite() ) { 1086 $url_parts = wp_parse_args( 1087 wp_parse_url( $url ), 1088 array( 1089 'host' => '', 1090 'path' => '/', 1091 ) 1092 ); 1093 1094 $qv = array( 1095 'domain' => $url_parts['host'], 1096 'path' => '/', 1097 ); 1098 1099 // In case of subdirectory configs, set the path. 1100 if ( ! is_subdomain_install() ) { 1101 $path = explode( '/', ltrim( $url_parts['path'], '/' ) ); 1102 $path = reset( $path ); 1103 1104 if ( $path ) { 1105 $qv['path'] = get_network()->path . $path . '/'; 1106 } 1107 } 1108 1109 $sites = get_sites( $qv ); 1110 $site = reset( $sites ); 1111 1112 if ( $site && (int) $site->blog_id !== get_current_blog_id() ) { 1113 switch_to_blog( $site->blog_id ); 1114 $switched_blog = true; 1115 } 1116 } 1117 1118 $post_id = url_to_postid( $url ); 1119 1120 /** This filter is documented in wp-includes/class-wp-oembed-controller.php */ 1121 $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url ); 1122 1123 if ( ! $post_id ) { 1124 if ( $switched_blog ) { 1125 restore_current_blog(); 1126 } 1127 1128 return $result; 1129 } 1130 1131 $width = isset( $args['width'] ) ? $args['width'] : 0; 1132 1133 $data = get_oembed_response_data( $post_id, $width ); 1134 $data = _wp_oembed_get_object()->data2html( (object) $data, $url ); 1135 1136 if ( $switched_blog ) { 1137 restore_current_blog(); 1138 } 1139 1140 if ( ! $data ) { 1141 return $result; 1142 } 1143 1144 return $data; 1145 } 1139 $data = get_oembed_response_data_for_url( $url, $args ); 1140 1141 if ( $data ) { 1142 return _wp_oembed_get_object()->data2html( $data, $url ); 1143 } 1144 1145 return $result; 1146 }
Note: See TracChangeset
for help on using the changeset viewer.