Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Improve method for skipping attachments so no error in console appears #325

Merged
merged 1 commit into from
Nov 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions php/class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,23 @@ 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' );
}
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;
}
}

/**
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions tests/php/test-class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down