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

Commit db7adaf

Browse files
committed
Export all registered post types to client, but only register panels if show_in_customizer
1 parent 6fdb4ee commit db7adaf

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

js/customize-posts.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
}
9494
return;
9595
}
96+
if ( ! component.data.postTypes[ postType ].show_in_customizer ) {
97+
return;
98+
}
9699
postId = parseInt( idParts[2], 10 );
97100
if ( ! postId ) {
98101
if ( 'undefined' !== typeof console && console.error ) {

php/class-wp-customize-posts.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,16 @@ public function get_post_types() {
8787
$post_types = array();
8888
$post_type_objects = get_post_types( array(), 'objects' );
8989
foreach ( $post_type_objects as $post_type_object ) {
90-
$is_included = $post_type_object->show_ui;
91-
if ( isset( $post_type_object->show_in_customizer ) ) {
92-
$is_included = $post_type_object->show_in_customizer;
90+
$post_type_object = clone $post_type_object;
91+
if ( ! isset( $post_type_object->show_in_customizer ) ) {
92+
$post_type_object->show_in_customizer = $post_type_object->show_ui;
9393
}
94+
$post_type_object->supports = get_all_post_type_supports( $post_type_object->name );
9495

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

99-
// Remove unnecessary properties.
100-
unset( $post_type_object->register_meta_box_cb );
101-
102-
$post_types[ $post_type_object->name ] = $post_type_object;
103-
}
99+
$post_types[ $post_type_object->name ] = $post_type_object;
104100
}
105101

106102
// Skip media as special case.
@@ -228,6 +224,10 @@ public function register_constructs() {
228224
// Note that this does not include nav_menu_item.
229225
$this->set_builtin_post_type_descriptions();
230226
foreach ( $this->get_post_types() as $post_type_object ) {
227+
if ( empty( $post_type_object->show_in_customizer ) ) {
228+
continue;
229+
}
230+
231231
$panel_id = sprintf( 'posts[%s]', $post_type_object->name );
232232

233233
// @todo Should this panel be filterable so that other post types can customize which subclass is used?
@@ -439,6 +439,7 @@ public function enqueue_scripts() {
439439
'menu_icon',
440440
'description',
441441
'hierarchical',
442+
'show_in_customizer',
442443
) );
443444
}
444445

tests/php/test-class-wp-customize-posts.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ public function test_register_constructs() {
234234
$this->do_customize_boot_actions();
235235
foreach ( $posts->get_post_types() as $post_type_object ) {
236236
$panel_id = sprintf( 'posts[%s]', $post_type_object->name );
237-
$this->assertInstanceOf( 'WP_Customize_Posts_Panel', $posts->manager->get_panel( $panel_id ) );
237+
if ( empty( $post_type_object->show_in_customizer ) ) {
238+
$this->assertNull( $posts->manager->get_panel( $panel_id ) );
239+
} else {
240+
$this->assertInstanceOf( 'WP_Customize_Posts_Panel', $posts->manager->get_panel( $panel_id ) );
241+
}
238242
}
239243
}
240244

0 commit comments

Comments
 (0)