equal
deleted
inserted
replaced
329 |
329 |
330 /** |
330 /** |
331 * Adds oEmbed discovery links in the head element of the website. |
331 * Adds oEmbed discovery links in the head element of the website. |
332 * |
332 * |
333 * @since 4.4.0 |
333 * @since 4.4.0 |
|
334 * @since 6.8.0 Output was adjusted to only embed if the post supports it. |
334 */ |
335 */ |
335 function wp_oembed_add_discovery_links() { |
336 function wp_oembed_add_discovery_links() { |
336 $output = ''; |
337 $output = ''; |
337 |
338 |
338 if ( is_singular() ) { |
339 if ( is_singular() && is_post_embeddable() ) { |
339 $output .= '<link rel="alternate" title="' . _x( 'oEmbed (JSON)', 'oEmbed resource link name' ) . '" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; |
340 $output .= '<link rel="alternate" title="' . _x( 'oEmbed (JSON)', 'oEmbed resource link name' ) . '" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; |
340 |
341 |
341 if ( class_exists( 'SimpleXMLElement' ) ) { |
342 if ( class_exists( 'SimpleXMLElement' ) ) { |
342 $output .= '<link rel="alternate" title="' . _x( 'oEmbed (XML)', 'oEmbed resource link name' ) . '" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n"; |
343 $output .= '<link rel="alternate" title="' . _x( 'oEmbed (XML)', 'oEmbed resource link name' ) . '" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n"; |
343 } |
344 } |
536 |
537 |
537 /** |
538 /** |
538 * Retrieves the oEmbed response data for a given post. |
539 * Retrieves the oEmbed response data for a given post. |
539 * |
540 * |
540 * @since 4.4.0 |
541 * @since 4.4.0 |
|
542 * @since 6.8.0 Output was adjusted to only embed if the post type supports it. |
541 * |
543 * |
542 * @param WP_Post|int $post Post ID or post object. |
544 * @param WP_Post|int $post Post ID or post object. |
543 * @param int $width The requested width. |
545 * @param int $width The requested width. |
544 * @return array|false Response data on success, false if post doesn't exist |
546 * @return array|false Response data on success, false if post doesn't exist, |
545 * or is not publicly viewable. |
547 * is not publicly viewable or post type is not embeddable. |
546 */ |
548 */ |
547 function get_oembed_response_data( $post, $width ) { |
549 function get_oembed_response_data( $post, $width ) { |
548 $post = get_post( $post ); |
550 $post = get_post( $post ); |
549 $width = absint( $width ); |
551 $width = absint( $width ); |
550 |
552 |
551 if ( ! $post ) { |
553 if ( ! $post ) { |
552 return false; |
554 return false; |
553 } |
555 } |
554 |
556 |
555 if ( ! is_post_publicly_viewable( $post ) ) { |
557 if ( ! is_post_publicly_viewable( $post ) ) { |
|
558 return false; |
|
559 } |
|
560 |
|
561 if ( ! is_post_embeddable( $post ) ) { |
556 return false; |
562 return false; |
557 } |
563 } |
558 |
564 |
559 /** |
565 /** |
560 * Filters the allowed minimum and maximum widths for the oEmbed response. |
566 * Filters the allowed minimum and maximum widths for the oEmbed response. |
719 $data['type'] = 'video'; |
725 $data['type'] = 'video'; |
720 } |
726 } |
721 } |
727 } |
722 |
728 |
723 if ( $thumbnail_id ) { |
729 if ( $thumbnail_id ) { |
724 list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) ); |
730 list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 0 ) ); |
725 $data['thumbnail_url'] = $thumbnail_url; |
731 $data['thumbnail_url'] = $thumbnail_url; |
726 $data['thumbnail_width'] = $thumbnail_width; |
732 $data['thumbnail_width'] = $thumbnail_width; |
727 $data['thumbnail_height'] = $thumbnail_height; |
733 $data['thumbnail_height'] = $thumbnail_height; |
728 } |
734 } |
729 |
735 |