| | 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 | |
| 1074 | | $switched_blog = false; |
| 1075 | | |
| 1076 | | if ( is_multisite() ) { |
| 1077 | | $url_parts = wp_parse_args( wp_parse_url( $url ), array( |
| 1078 | | 'host' => '', |
| 1079 | | 'path' => '/', |
| 1080 | | ) ); |
| 1081 | | |
| 1082 | | $qv = array( 'domain' => $url_parts['host'], 'path' => '/' ); |
| 1083 | | |
| 1084 | | // In case of subdirectory configs, set the path. |
| 1085 | | if ( ! is_subdomain_install() ) { |
| 1086 | | $path = explode( '/', ltrim( $url_parts['path'], '/' ) ); |
| 1087 | | $path = reset( $path ); |
| 1088 | | |
| 1089 | | if ( $path ) { |
| 1090 | | $qv['path'] = get_network()->path . $path . '/'; |
| 1091 | | } |
| 1092 | | } |
| 1093 | | |
| 1094 | | $sites = get_sites( $qv ); |
| 1095 | | $site = reset( $sites ); |
| 1096 | | |
| 1097 | | if ( $site && (int) $site->blog_id !== get_current_blog_id() ) { |
| 1098 | | switch_to_blog( $site->blog_id ); |
| 1099 | | $switched_blog = true; |
| 1100 | | } |
| 1101 | | } |
| 1102 | | |
| 1103 | | $post_id = url_to_postid( $url ); |
| 1104 | | |
| 1105 | | /** This filter is documented in wp-includes/class-wp-oembed-controller.php */ |
| 1106 | | $post_id = apply_filters( 'oembed_request_post_id', $post_id, $url ); |
| 1107 | | |
| 1108 | | if ( ! $post_id ) { |
| 1109 | | if ( $switched_blog ) { |
| 1110 | | restore_current_blog(); |
| 1111 | | } |
| | 1139 | $data = get_oembed_response_data_for_url( $url, $args ); |