First of all I have some points to discuss:
1) Why the plugin uses the Customizer Javascript API over the PHP API for creating sections, panels and controls?
The JS API is not so extensible and very documented as the PHP is. I’m not saying that the JS API is bad, but in most cases, is used only in live preview.
2) Why the plugin can’t have custom hooks? I mean customize_posts hooks. Why not?
For example, if I want to add a custom field in ‘page’ section, I would do something like this:
add_action('customize_posts_add_field', function($section, $wp_customize){
$wp_customize->add_setting( 'header_textcolor' , array(
'default' => '#000000',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize,
'link_color', array(
'label' => __( 'Header Color', 'mytheme' ),
'section' => $section->id,
'settings' => 'your_setting_id',
) ) );
...
});
This is way is so much clearer than the gist you paste here:
https://gist.github.com/westonruter/f8473159e48fbacbef9dcd6498155846