diff --git a/src/Kunoichi/ThemeCustomizer/CustomizerSetting.php b/src/Kunoichi/ThemeCustomizer/CustomizerSetting.php index f4e672b..d29ff4a 100644 --- a/src/Kunoichi/ThemeCustomizer/CustomizerSetting.php +++ b/src/Kunoichi/ThemeCustomizer/CustomizerSetting.php @@ -11,6 +11,8 @@ abstract class CustomizerSetting extends Singleton { use Utilities; + protected $panel_id = ''; + protected $section_id = ''; /** @@ -44,9 +46,17 @@ protected function after_init() { * @param \WP_Customize_Manager $wp_customizer */ public function customize_register( $wp_customizer ) { + // Register panel. + $panel_setting = $this->panel_settings(); + if ( $panel_setting ) { + $wp_customizer->add_panel( $this->panel_id, $panel_setting ); + } // Register setting if required. $section_setting = $this->section_setting(); if ( $section_setting ) { + if ( $this->panel_id ) { + $section_setting[ 'panel' ] = $this->panel_id; + } $wp_customizer->add_section( $this->get_section(), $section_setting ); } // Register all fields. @@ -76,6 +86,16 @@ protected function register_field( &$wp_customizer, $id, $args ) { $wp_customizer->add_control( new $control_class( $wp_customizer, $id, $args ) ); } + /** + * If proper array returned, register panel. + * + * @see \WP_Customize_Manager::add_panel + * @return array + */ + protected function panel_settings() { + return []; + } + /** * If array returned, register section. * diff --git a/tests/src/Kunoichi/ThemeCustomizerTest/NestedCustomizer.php b/tests/src/Kunoichi/ThemeCustomizerTest/NestedCustomizer.php new file mode 100644 index 0000000..91172d1 --- /dev/null +++ b/tests/src/Kunoichi/ThemeCustomizerTest/NestedCustomizer.php @@ -0,0 +1,40 @@ + 'Nested Section', + ]; + } + + protected function panel_settings() { + return [ + 'title' => 'Nested Panel', + 'description' => 'This panel is added by Kunoichi Theme Customizer.', + 'priority' => 200, + ]; + } + + protected function get_fields() { + return [ + 'nested_section_1' => [ + 'label' => 'Nested Field 1', + ], + 'nested_section_2' => [ + 'label' => 'Nested Field 2', + ], + ]; + } + + +} diff --git a/tests/src/Kunoichi/ThemeCustomizerTest/SimpleCustomizer.php b/tests/src/Kunoichi/ThemeCustomizerTest/SimpleCustomizer.php index 5809bb0..b78d554 100644 --- a/tests/src/Kunoichi/ThemeCustomizerTest/SimpleCustomizer.php +++ b/tests/src/Kunoichi/ThemeCustomizerTest/SimpleCustomizer.php @@ -12,7 +12,7 @@ */ class SimpleCustomizer extends CustomizerSetting { - protected $section_id = 'site-setting'; + protected $section_id = 'title_tagline'; /** @@ -21,8 +21,8 @@ class SimpleCustomizer extends CustomizerSetting { protected function get_fields() { return [ 'site_setting_title' => [ - 'label' => __( 'Title' ), - 'description' => '', + 'label' => 'Added Title', + 'description' => 'This section is added by Kunoichi Theme Customizer.', ], ]; } diff --git a/tests/test-utility.php b/tests/test-utility.php index 360d67d..a3ad1bb 100644 --- a/tests/test-utility.php +++ b/tests/test-utility.php @@ -21,5 +21,4 @@ public function test_translation() { switch_to_locale( 'ja' ); $this->assertEquals( 'メタ情報とSEO', __( 'Meta and SEO', 'theme-customizer' ) ); } - } diff --git a/theme-customizer.php b/theme-customizer.php index 5ca9e7b..c081544 100644 --- a/theme-customizer.php +++ b/theme-customizer.php @@ -16,14 +16,16 @@ if ( ! defined( 'ABSPATH' ) ) { die( 'Invalid request.' ); } - require __DIR__ . '/vendor/autoload.php'; \Kunoichi\ThemeCustomizer::load_locale( get_locale() ); -$auto_loaded = [ 'Patterns' ]; -foreach ( $auto_loaded as $dir ) { - $path = __DIR__ . '/src/Kunoichi/ThemeCustomizer/' . $dir; +$auto_loaded = [ + [ __DIR__ . '/src', 'Kunoichi/ThemeCustomizer/Patterns' ], + [ __DIR__ . '/tests/src/', 'Kunoichi/ThemeCustomizerTest' ], +]; +foreach ( $auto_loaded as list( $base, $dir ) ) { + $path = $base . '/' . $dir; if ( ! is_dir( $path ) ) { continue; } @@ -32,7 +34,7 @@ continue; } list( $file, $class_name ) = $match; - $class_name = "Kunoichi\\ThemeCustomizer\\{$dir}\\{$class_name}"; + $class_name = str_replace( '/', "\\", $dir ) . "\\" . $class_name; if ( ! class_exists( $class_name ) ) { continue; }