plugin = $Plugin; $this->build_settings(); add_action('admin_init', array($this, 'options_defaults')); add_action('admin_init', array($this, 'register_settings')); add_action('admin_menu', array($this, 'add_options_page')); } /** * Tab menu items */ private function build_settings() { $this->settings = array ( 'redirects' => array ( 'title' => 'Redirect Rules', 'description' => '', 'callback' => 'redirects', 'fields' => array(), ), '404s' => array ( 'title' => '404 Error Log', 'description' => '', 'callback' => '404s', 'fields' => array(), ), 'link-scanner' => array ( 'title' => 'Link Scanner', 'description' => '', 'callback' => 'link_scanner', 'fields' => array(), ), 'import-export' => array ( 'title' => 'Tools & Options', 'description' => '', 'callback' => 'import_export', 'fields' => array(), ), 'support' => array ( 'title' => 'Support', 'description' => '', 'callback' => 'support', 'fields' => array(), ), 'pro' => array ( 'title' => 'PRO', 'description' => '', 'callback' => 'pro', 'class' => 'pro-ad', 'fields' => array(), ), ); } // build_settings /** * * Build the setting slug based on section. * * @param string $section * @return string */ private function setting_slug($section = 'general') { return $this->plugin->config('option_slug') . '_' . $section; } /** * * Registers the settings based on the JSON file we imported. * */ public function register_settings() { foreach ($this->settings as $section => $args) { register_setting( $this->setting_slug($section), $this->setting_slug($section), array($this, 'sanitize_inputs') ); add_settings_section( $this->setting_slug($section), $args['title'], // array( $this, 'section_'.$section.'_callback'), array($this, 'section_callback'), $this->plugin->config('option_slug') . '_' . $section ); foreach ($args['fields'] as $slug => $args) { $args['section'] = $section; add_settings_field( $slug, $args['label'], array($this, 'field_callback'), $this->setting_slug($section), $this->setting_slug($section), $args ); } } } /** * * Sanitize inputs. TODO * * @param $args * @return mixed */ public function sanitize_inputs($args) { return $args; } /** * * If this is the first time we're loading this, we can use the JSON file to populate some defaults. * */ public function options_defaults() { foreach ($this->settings as $section => $args) { $settings = get_option($this->setting_slug($section)); if (empty($settings)) { $settings = array(); foreach ($args['fields'] as $slug => $args) { $settings[$slug] = $args['default']; } add_option($this->setting_slug($section), $settings, '', 'yes'); } } } /** * * Outputs the Sections intro HTML. A callback. * * @param $args * */ function section_callback($args) { if (isset($_GET['tab'])) { $tab = sanitize_text_field($_GET['tab']); } else { $sections = array_keys($this->settings); $tab = $sections[0]; } EPS_Redirects::wp_kses_wf($this->settings[$tab]['description']); } /** * * Output the Field HTML based on the JSON and 'type' of input. * * @param $args * */ function field_callback($args) { $option_slug = $this->setting_slug($args['section']); $setting = get_option($this->setting_slug($args['section'])); printf( "%s", esc_attr($option_slug), esc_attr($args['slug']), (isset($setting[$args['slug']]) ? esc_attr(setting[$args['slug']]) : null), esc_attr($args['description']) ); } /** * * ADD_PLUGIN_PAGE * * This function initialize the plugin settings page. * * @return string * @author WebFactory Ltd * */ public function add_options_page() { if (in_array($this->plugin->config('menu_location'), $this->menu_locations)) { $func = sprintf("add_%s_page", $this->plugin->config('menu_location')); return $func($this->plugin->name, $this->plugin->name, $this->plugin->config('page_permission'), $this->plugin->config('page_slug'), array($this, 'do_admin_page')); } else { // TODO proper errors dude. printf('ERROR: menu location "%s" not valid.', esc_attr($this->config['menu_location'])); } return false; } /** * * DO_ADMIN_PAGE * * This function will create the admin page. * * @author WebFactory Ltd * */ public function do_admin_page() { $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : false; if (!$current_tab) { $sections = $this->settings; $current_tab = key($sections); } ?>

<?php echo esc_attr($this->plugin->name); ?>plugin->name); ?>


get_tab_nav($current_tab); ?> get_tab($current_tab); ?>
pro_dialog()); } /** * * Outputs the tab navigation based on our sections. * * @param string $current */ function get_tab_nav($current = 'general') { echo ''; } /** * * Gets the content for the current tab. * * @param string $tab * */ public function get_tab($tab = 'general') { if ($this->tab_exists($tab)) { if (has_action($tab . '_admin_tab')) { do_action($tab . '_admin_tab', $this->settings[$tab]); } else { ?>
setting_slug($tab)); do_action($this->setting_section_callback($tab, "_before")); do_settings_sections($this->plugin->config('option_slug') . '_' . $tab); do_action($this->setting_section_callback($tab, '_after')); submit_button(); ?>
plugin->config('option_slug') . '_settings_' . $this->settings[$tab]['callback'] . $suffix; } /** * * Checks to see if a tab exists. * * @param $tab * @return bool * @throws Exception * */ public function tab_exists($tab) { if (!array_key_exists($tab, $this->settings)) { throw new Exception('Tab does not exist'); } return true; } function pro_dialog() { $out = ''; $out .= ''; return $out; } } }