WordPress.org

Make WordPress Core

Changeset 40098


Ignore:
Timestamp:
02/21/17 07:01:07 (5 months ago)
Author:
dd32
Message:

Customize: Allow custom post types to be used in starter content.

Changes WP_Customize_Nav_Menus::insert_auto_draft_post() so it can be invoked for a post_type that is not registered (yet).

Props westonruter.
Merges [39924] to the 4.7 branch.
See #38615, #38114.
Fixes #39610.

Location:
branches/4.7
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/class-wp-customize-manager.php

    r40095 r40098  
    998998        ); 
    999999 
     1000        /* 
     1001         * Obtain all post types referenced in starter content to use in query. 
     1002         * This is needed because 'any' will not account for post types not yet registered. 
     1003         */ 
     1004        $post_types = array_filter( array_merge( array( 'attachment' ), wp_list_pluck( $posts, 'post_type' ) ) ); 
     1005 
    10001006        // Re-use auto-draft starter content posts referenced in the current customized state. 
    10011007        $existing_starter_content_posts = array(); 
     
    10041010                'post__in' => $starter_content_auto_draft_post_ids, 
    10051011                'post_status' => 'auto-draft', 
    1006                 'post_type' => 'any', 
     1012                'post_type' => $post_types, 
    10071013                'posts_per_page' => -1, 
    10081014            ) ); 
  • branches/4.7/src/wp-includes/class-wp-customize-nav-menus.php

    r40095 r40098  
    787787     */ 
    788788    public function insert_auto_draft_post( $postarr ) { 
    789         if ( ! isset( $postarr['post_type'] ) || ! post_type_exists( $postarr['post_type'] )  ) { 
     789        if ( ! isset( $postarr['post_type'] ) ) { 
    790790            return new WP_Error( 'unknown_post_type', __( 'Unknown post type' ) ); 
    791791        } 
  • branches/4.7/tests/phpunit/tests/customize/manager.php

    r39575 r40098  
    373373                    'post_title' => 'Custom', 
    374374                    'thumbnail' => '{{waffles}}', 
     375                ), 
     376                'unknown_cpt' => array( 
     377                    'post_type' => 'unknown_cpt', 
     378                    'post_title' => 'Unknown CPT', 
    375379                ), 
    376380            ), 
     
    442446 
    443447        $posts_by_name = array(); 
    444         $this->assertCount( 6, $changeset_values['nav_menus_created_posts'] ); 
     448        $this->assertCount( 7, $changeset_values['nav_menus_created_posts'] ); 
    445449        $this->assertContains( $existing_published_home_page_id, $changeset_values['nav_menus_created_posts'], 'Expected reuse of non-auto-draft posts.' ); 
    446450        $this->assertContains( $existing_canola_attachment_id, $changeset_values['nav_menus_created_posts'], 'Expected reuse of non-auto-draft attachment.' ); 
     
    462466            $posts_by_name[ $post_name ] = $post->ID; 
    463467        } 
    464         $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom' ), array_keys( $posts_by_name ) ); 
     468        $this->assertEquals( array( 'waffles', 'canola', 'home', 'about', 'blog', 'custom', 'unknown-cpt' ), array_keys( $posts_by_name ) ); 
    465469        $this->assertEquals( 'Custom', get_post( $posts_by_name['custom'] )->post_title ); 
    466470        $this->assertEquals( 'sample-page-template.php', get_page_template_slug( $posts_by_name['about'] ) ); 
  • branches/4.7/tests/phpunit/tests/customize/nav-menus.php

    r39507 r40098  
    539539        $this->assertEquals( 'unknown_post_type', $r->get_error_code() ); 
    540540 
    541         $r = $menus->insert_auto_draft_post( array( 'post_type' => 'fake' ) ); 
     541        // Non-existent post types allowed as of #39610. 
     542        $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Non-existent', 'post_type' => 'nonexistent' ) ); 
     543        $this->assertInstanceOf( 'WP_Post', $r ); 
     544 
     545        $r = $menus->insert_auto_draft_post( array( 'post_type' => 'post' ) ); 
    542546        $this->assertInstanceOf( 'WP_Error', $r ); 
    543         $this->assertEquals( 'unknown_post_type', $r->get_error_code() ); 
     547        $this->assertEquals( 'empty_title', $r->get_error_code() ); 
    544548 
    545549        $r = $menus->insert_auto_draft_post( array( 'post_status' => 'publish', 'post_title' => 'Bad', 'post_type' => 'post' ) ); 
Note: See TracChangeset for help on using the changeset viewer.