Exemplo n.º 1
0
 /**
  * Init hooks
  */
 static function init()
 {
     self::$options = ['tab_one' => ['page_title' => __('The plugin name', PN_PLUGIN_DIR), 'page_description' => __('Manage post types and taxonomies.', PN_PLUGIN_DIR), 'fields' => ['field_name' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'text', 'option_name' => 'field_name', 'default' => false, 'options' => []], 'field_name_2' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'textarea', 'option_name' => 'field_name_2', 'default' => false, 'options' => []], 'field_name_3' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'checkbox', 'option_name' => 'field_name_3', 'default' => false, 'options' => []], 'field_name_4' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'select', 'option_name' => 'field_name_4', 'default' => false, 'options' => ['foo', 'bar']]]], 'tab_two' => ['page_title' => __('The plugin name', PN_PLUGIN_DIR), 'page_description' => __('Manage post types and taxonomies.', PN_PLUGIN_DIR), 'fields' => ['field_name' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'text', 'option_name' => 'field_name', 'default' => false, 'options' => []], 'field_name_2' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'textarea', 'option_name' => 'field_name_2', 'default' => false, 'options' => []], 'field_name_3' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'checkbox', 'option_name' => 'field_name_3', 'default' => false, 'options' => []], 'field_name_4' => ['label' => __('Label nice name', PN_PLUGIN_DIR), 'field_type' => 'select', 'option_name' => 'field_name_4', 'default' => false, 'options' => ['foo', 'bar']]]]];
     // Loads plugin text domain and scripts
     add_action('after_setup_theme', [__CLASS__, 'pn_theme_setup']);
     add_action('admin_enqueue_scripts', [__CLASS__, 'pn_scripts']);
     // Custom action hooks
     // Ajax action hooks
 }
Exemplo n.º 2
0
 /**
  * Initiate options from options array
  */
 public function pn_settings_init()
 {
     $this->options = Pn::getOptions();
     /**
      * TODO set default values
      * $options = get_option('pn_settings');
      * */
     foreach ($this->options as $step => $props) {
         register_setting('pn_option_page_' . $step, 'pn_settings');
         add_settings_section(strtolower(str_replace(' ', '_', $props['page_title'])), $props['page_description'], $this->pn_settings_section_callback(), 'pn_option_page_' . $step);
         /**
          * Use options array to build PN options
          */
         foreach ($props['fields'] as $key => $value) {
             /**
              * TODO set default values
              * if ( !isset( $options[$value['option_name']] ) )
              * add_option( $value['option_name'], $value['default']);
              * */
             add_settings_field($key, $value['label'], array(&$this, 'pn_' . $value['field_type'] . '_field_render'), 'pn_option_page_' . $step, strtolower(str_replace(' ', '_', $props['page_title'])), array('option_name' => $value['option_name'], 'options' => $value['options']));
         }
     }
 }