Make WordPress Core

Ticket #35567: 35567.diff

File 35567.diff, 4.4 KB (added by bradleyt, 9 years ago)
  • src/wp-includes/embed.php

    diff --git src/wp-includes/embed.php src/wp-includes/embed.php
    index cdeaf79..f3916e7 100644
    function wp_oembed_register_route() { 
    343343 * @since 4.4.0
    344344 */
    345345function wp_oembed_add_discovery_links() {
     346        $post      = get_post( $post );
     347        $post_type = get_post_type( $post );
    346348        $output = '';
    347349
    348350        if ( is_singular() ) {
    349                 $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
     351                if(  is_post_type_embeddable($post_type) ) {
     352                        $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n";
    350353
    351                 if ( class_exists( 'SimpleXMLElement' ) ) {
    352                         $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
     354                        if ( class_exists( 'SimpleXMLElement' ) ) {
     355                                $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n";
     356                        }
    353357                }
    354358        }
    355359
    JS; 
    516520 * @return array|false Response data on success, false if post doesn't exist.
    517521 */
    518522function get_oembed_response_data( $post, $width ) {
    519         $post = get_post( $post );
     523        $post      = get_post( $post );
     524        $post_type = get_post_type( $post );
    520525
    521526        if ( ! $post ) {
    522527                return false;
    function get_oembed_response_data( $post, $width ) { 
    526531                return false;
    527532        }
    528533
     534        if( ! is_post_type_embeddable($post_type) ) {
     535                return false;
     536        }
     537
    529538        /**
    530539         * Filter the allowed minimum and maximum widths for the oEmbed response.
    531540         *
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 70a7d73..51a26d2 100644
    function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) 
    962962 *     @type bool|string $has_archive          Whether there should be post type archives, or if a string, the
    963963 *                                             archive slug to use. Will generate the proper rewrite rules if
    964964 *                                             $rewrite is enabled. Default false.
     965 *     @type bool        $is_embeddable        Whether this post type should be embeddable through oembed.
     966 *                                             Default is value of $public.
    965967 *     @type bool|array  $rewrite              {
    966968 *         Triggers the handling of rewrites for this post type. To prevent rewrite, set to false.
    967969 *         Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be
    function register_post_type( $post_type, $args = array() ) { 
    10391041                'register_meta_box_cb' => null,
    10401042                'taxonomies'           => array(),
    10411043                'has_archive'          => false,
     1044                'is_embeddable'        => null,
    10421045                'rewrite'              => true,
    10431046                'query_var'            => true,
    10441047                'can_export'           => true,
    function register_post_type( $post_type, $args = array() ) { 
    11581161                                add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
    11591162                }
    11601163
     1164
    11611165                $permastruct_args = $args->rewrite;
    11621166                $permastruct_args['feed'] = $permastruct_args['feeds'];
    11631167                add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args );
    11641168        }
    11651169
     1170        // If not set, default to the setting for public.
     1171        if ( null === $args->is_embeddable )
     1172                $args->is_embeddable = $args->public;
     1173
    11661174        // Register the post type meta box if a custom callback was specified.
    11671175        if ( $args->register_meta_box_cb )
    11681176                add_action( 'add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1 );
    function is_post_type_viewable( $post_type ) { 
    16871695}
    16881696
    16891697/**
     1698 * Determines whether a post type is considered "embeddable".
     1699 *
     1700 * For all post types the 'is_embeddable' value will be evaluated.
     1701 *
     1702 * @param object $post_type Post type name or object.
     1703 * @return bool Whether the post type should be considered embeddable.
     1704 */
     1705function is_post_type_embeddable( $post_type ) {
     1706        if ( is_scalar( $post_type ) ) {
     1707                $post_type = get_post_type_object( $post_type );
     1708                if ( ! $post_type ) {
     1709                        return false;
     1710                }
     1711        }
     1712
     1713        return $post_type->is_embeddable;
     1714}
     1715
     1716/**
    16901717 * Retrieve list of latest posts or posts matching criteria.
    16911718 *
    16921719 * The defaults are as follows: