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

Commit

Permalink
Merge pull request #130 from xwp/bugfix/no-show-in-customizer
Browse files Browse the repository at this point in the history
Export all registered post types to client, but only register panels if show_in_customizer
  • Loading branch information
valendesigns committed May 4, 2016
2 parents 2abb585 + 2cc3c56 commit 32efa6d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 3 additions & 0 deletions js/customize-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
}
return;
}
if ( ! component.data.postTypes[ postType ].show_in_customizer ) {
return;
}
postId = parseInt( idParts[2], 10 );
if ( ! postId ) {
if ( 'undefined' !== typeof console && console.error ) {
Expand Down
23 changes: 12 additions & 11 deletions php/class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,16 @@ public function get_post_types() {
$post_types = array();
$post_type_objects = get_post_types( array(), 'objects' );
foreach ( $post_type_objects as $post_type_object ) {
$is_included = $post_type_object->show_ui;
if ( isset( $post_type_object->show_in_customizer ) ) {
$is_included = $post_type_object->show_in_customizer;
$post_type_object = clone $post_type_object;
if ( ! isset( $post_type_object->show_in_customizer ) ) {
$post_type_object->show_in_customizer = $post_type_object->show_ui;
}
$post_type_object->supports = get_all_post_type_supports( $post_type_object->name );

if ( $is_included ) {
$post_type_object = clone $post_type_object;
$post_type_object->supports = get_all_post_type_supports( $post_type_object->name );
// Remove unnecessary properties.
unset( $post_type_object->register_meta_box_cb );

// Remove unnecessary properties.
unset( $post_type_object->register_meta_box_cb );

$post_types[ $post_type_object->name ] = $post_type_object;
}
$post_types[ $post_type_object->name ] = $post_type_object;
}

// Skip media as special case.
Expand Down Expand Up @@ -228,6 +224,10 @@ public function register_constructs() {
// Note that this does not include nav_menu_item.
$this->set_builtin_post_type_descriptions();
foreach ( $this->get_post_types() as $post_type_object ) {
if ( empty( $post_type_object->show_in_customizer ) ) {
continue;
}

$panel_id = sprintf( 'posts[%s]', $post_type_object->name );

// @todo Should this panel be filterable so that other post types can customize which subclass is used?
Expand Down Expand Up @@ -439,6 +439,7 @@ public function enqueue_scripts() {
'menu_icon',
'description',
'hierarchical',
'show_in_customizer',
) );
}

Expand Down
6 changes: 5 additions & 1 deletion tests/php/test-class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ public function test_register_constructs() {
$this->do_customize_boot_actions();
foreach ( $posts->get_post_types() as $post_type_object ) {
$panel_id = sprintf( 'posts[%s]', $post_type_object->name );
$this->assertInstanceOf( 'WP_Customize_Posts_Panel', $posts->manager->get_panel( $panel_id ) );
if ( empty( $post_type_object->show_in_customizer ) ) {
$this->assertNull( $posts->manager->get_panel( $panel_id ) );
} else {
$this->assertInstanceOf( 'WP_Customize_Posts_Panel', $posts->manager->get_panel( $panel_id ) );
}
}
}

Expand Down

0 comments on commit 32efa6d

Please sign in to comment.