public function admin_init() { $section = 'default'; add_settings_section($section, __('Hello Kushimoto 設定', 'hello-kushimoto'), array($this, 'section_description'), $this->page_slug); add_settings_field('hello_kushimoto_speaker', __('キャラクター設定', 'hello-kushimoto'), array($this->option_page_view, 'create_select_field'), $this->page_slug, $section, array('name' => 'hello_kushimoto_speaker', 'options' => $this->create_options(), 'current' => $this->option_manager->get_speaker_name())); register_setting($this->option_group, 'hello_kushimoto_speaker'); }
public function test_get_option() { $option_manager = new Hello_Kushimoto_Option_Manager(); $options = $option_manager->get_options(); $this->assertTrue(is_array($options)); $this->assertArrayHasKey('speaker', $options); }
/** * Hello_Kushimoto constructor. */ public function __construct() { load_plugin_textdomain('hello-kushimoto', false, plugin_basename(HELLO_KUSHIMOTO_DIR) . '/languages'); $this->option_manager = new Hello_Kushimoto_Option_Manager(); $this->speaker_seeker = new Hello_Kushimoto_Speaker_Seeker(); new Hello_Kushimoto_Admin_Panel($this->option_manager, $this->speaker_seeker); $speaker_class = $this->option_manager->get_speaker(); if (class_exists($speaker_class, true)) { $speaker = new $speaker_class(); $this->speaker = apply_filters('hello_kushimoto_speaker', $speaker); $this->initialize_modules(); } }
public function test_get_speaker_name() { $option_manager = new Hello_Kushimoto_Option_Manager(); $options = $option_manager->get_speaker_name(); $this->assertTrue(class_exists($options, true)); }
public function options_page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } ?> <div id="hello_kushimoto" class="wrap"> <h2><?php _e('Hello Kushimoto', 'hello-kushimoto'); ?> </h2> <form method="post" action="options.php"> <?php settings_fields('hello_kushimoto_setting'); do_settings_sections('hello_kushimoto_setting'); $options = $this->option_manager->get_options(); $name = $this->option_manager->get_option_name(); ?> <table class="form-table"> <tbody> <tr> <th scope="row"><label for="<?php echo esc_attr($name); ?> "><?php _e('キャラクター設定', 'hello-kushimoto'); ?> </label></th> <td> <select name="<?php echo esc_attr($name); ?> [speaker]" id="<?php echo esc_attr($name); ?> "> <?php $current_speaker = $options['speaker']; $speakers = $this->get_speakers(); foreach ($speakers as $speaker) { $class_name = get_class($speaker); ?> <option value="<?php echo esc_attr($class_name); ?> " <?php selected($current_speaker, $class_name); ?> > <?php echo esc_html($speaker->whoami()); ?> </option> <?php } ?> </select> </td> </tr> </tbody> </table> <?php submit_button(); ?> </form> </div><!-- #hello_kushimoto --> <?php }
/** * * Factory Method for Speaker. * * @return Hello_Kushimoto_Speaker|void */ public function get_current_speaker() { $speaker_class = $this->option_manager->get_speaker_name(); return apply_filters('hello_kushimoto_speaker', $this->create_speaker($speaker_class)); }