I am developing a theme that has a lot of theme mods, sections, panels. My issue is that the Customizer loads all of them at once and it can take awhile for it to load. Also, I would really like to load only the settings, sections needed for the page I am currently editing.
I've been looking for some filters in the WP_Customize_Manager
but I can't find any that would modify the sections
, panels
, settings
, controls
proprieties or the methods they are used into.
At this point I am getting the page id by adding it to the Customizer url, something like wp-admin/customize.php?url=pageurl&apageid=700
Based on that page id I would like to register the needed sections and settings, and remove the rest.
Just an example, did this with panels, controls, sections too:
function test_reg( $wp_customize ) {
$currentID = isset( $_GET['apageid'] ) ? absint( $_GET['apageid'] ) : '';
// tmpl_ids() returns an ids array of all the pages that use a certain page template
if( in_array( $currentID, tmpl_ids() ) {
$custom_settings = array(
'custom_setting_' . $currentID,
);
foreach( $custom_settings as $val ) {
... register the setting here.
}
foreach( $wp_customize->settings() as $setting ) {
if( ! in_array( $setting->id, $custom_settings ) ) {
$wp_customize->remove_setting( $setting->id );
}
}
}
}
add_action( 'customize_register', 'test_reg', 999 );
This will remove the settings, but it will not work for the previewer customize_preview_settings
, which will output all of them.
Anyway, any idea how to do this properly? Thank you!