diff --git a/php/class-wp-customize-posts.php b/php/class-wp-customize-posts.php index 4645b74..090aec5 100644 --- a/php/class-wp-customize-posts.php +++ b/php/class-wp-customize-posts.php @@ -201,16 +201,13 @@ public function get_post_types() { $post_types[ $post_type_object->name ] = $post_type_object; } - // Skip media as special case. - unset( $post_types['attachment'] ); - return $post_types; } /** - * Set missing post type descriptions for built-in post types. + * Set missing post type descriptions for built-in post types and explicitly disallow attachments in customizer UI. */ - public function set_builtin_post_type_descriptions() { + public function configure_builtin_post_types() { global $wp_post_types; if ( post_type_exists( 'post' ) && empty( $wp_post_types['post']->description ) ) { $wp_post_types['post']->description = __( 'Posts are entries listed in reverse chronological order, usually on the site homepage or on a dedicated posts page. Posts can be organized by tags or categories.', 'customize-posts' ); @@ -218,6 +215,9 @@ public function set_builtin_post_type_descriptions() { if ( post_type_exists( 'page' ) && empty( $wp_post_types['page']->description ) ) { $wp_post_types['page']->description = __( 'Pages are ordered and organized hierarchically instead of being listed by date. The organization of pages generally corresponds to the primary nav menu.', 'customize-posts' ); } + if ( post_type_exists( 'attachment' ) && ! isset( $wp_post_types['attachment']->show_in_customizer ) ) { + $wp_post_types['attachment']->show_in_customizer = false; + } } /** @@ -431,7 +431,7 @@ public function register_constructs() { $panel_priority = 900; // Before widgets. // Note that this does not include nav_menu_item. - $this->set_builtin_post_type_descriptions(); + $this->configure_builtin_post_types(); foreach ( $this->get_post_types() as $post_type_object ) { if ( empty( $post_type_object->show_in_customizer ) ) { continue; diff --git a/tests/php/test-class-wp-customize-posts.php b/tests/php/test-class-wp-customize-posts.php index 6e3844f..6efbc5e 100644 --- a/tests/php/test-class-wp-customize-posts.php +++ b/tests/php/test-class-wp-customize-posts.php @@ -169,21 +169,28 @@ public function test_get_post_types() { /** * Test post type descriptions for built-in post types gets set. * - * @see WP_Customize_Posts::set_builtin_post_type_descriptions() + * @see WP_Customize_Posts::configure_builtin_post_types() */ - public function test_set_builtin_post_type_descriptions() { + public function test_configure_builtin_post_types() { global $wp_post_types; $wp_post_types['post']->description = ''; $wp_post_types['page']->description = ''; + unset( $wp_post_types['attachment']->show_in_customizer ); $this->assertEmpty( $wp_post_types['post']->description ); $this->assertEmpty( $wp_post_types['page']->description ); + $this->assertObjectNotHasAttribute( 'show_in_customizer', $wp_post_types['attachment'] ); - $this->posts->set_builtin_post_type_descriptions(); + $this->posts->configure_builtin_post_types(); $this->assertNotEmpty( $wp_post_types['post']->description ); $this->assertNotEmpty( $wp_post_types['page']->description ); + $this->assertFalse( $wp_post_types['attachment']->show_in_customizer ); + + $wp_post_types['attachment']->show_in_customizer = true; + $this->posts->configure_builtin_post_types(); + $this->assertTrue( $wp_post_types['attachment']->show_in_customizer ); } /**