Overview
  • Namespace
  • Class

Namespaces

  • nk2580
    • wordsmith
      • Actions
      • Endpoints
      • Environment
      • Filters
      • Inputs
        • Fields
      • Menus
      • MetaBoxes
      • PostTypes
      • Routes
      • Scripts
      • SettingsPages
      • Taxonomies
        • Hierarchical
        • NonHierarchical
      • UserCapabilities
      • UserRoles
      • Utillities
        • NavWalkers

Classes

  • nk2580\wordsmith\Actions\Action
  • nk2580\wordsmith\Actions\AJAXAction
  • nk2580\wordsmith\Endpoints\Endpoint
  • nk2580\wordsmith\Endpoints\EndpointHandler
  • nk2580\wordsmith\Environment\Instance
  • nk2580\wordsmith\Environment\Plugin
  • nk2580\wordsmith\Environment\Theme
  • nk2580\wordsmith\Filters\Filter
  • nk2580\wordsmith\Inputs\Fields\AddressField
  • nk2580\wordsmith\Inputs\Fields\CheckBoxField
  • nk2580\wordsmith\Inputs\Fields\EmailField
  • nk2580\wordsmith\Inputs\Fields\FileUploadField
  • nk2580\wordsmith\Inputs\Fields\GalleryField
  • nk2580\wordsmith\Inputs\Fields\HiddenField
  • nk2580\wordsmith\Inputs\Fields\ImageUploadField
  • nk2580\wordsmith\Inputs\Fields\PasswordField
  • nk2580\wordsmith\Inputs\Fields\RadioButtonField
  • nk2580\wordsmith\Inputs\Fields\SelectBoxField
  • nk2580\wordsmith\Inputs\Fields\TextAreaField
  • nk2580\wordsmith\Inputs\Fields\TextField
  • nk2580\wordsmith\Inputs\Fields\UrlField
  • nk2580\wordsmith\Inputs\Input
  • nk2580\wordsmith\Inputs\Repeater
  • nk2580\wordsmith\Menus\Menu
  • nk2580\wordsmith\MetaBoxes\MetaBox
  • nk2580\wordsmith\PostTypes\PostType
  • nk2580\wordsmith\Routes\Route
  • nk2580\wordsmith\Routes\RouteFactory
  • nk2580\wordsmith\Routes\RouteGroup
  • nk2580\wordsmith\Scripts\AdminScript
  • nk2580\wordsmith\Scripts\PublicScript
  • nk2580\wordsmith\SettingsPages\SettingsPage
  • nk2580\wordsmith\Taxonomies\Hierarchical\HierarchicalTaxonomy
  • nk2580\wordsmith\Taxonomies\NonHierarchical\NonHierarchicalTaxonomy
  • nk2580\wordsmith\Taxonomies\Taxonomy
  • nk2580\wordsmith\UserCapabilities\UserCapability
  • nk2580\wordsmith\UserRoles\UserRole
  • nk2580\wordsmith\Utillities\Cypher
  • nk2580\wordsmith\Utillities\JsonResponse
  • nk2580\wordsmith\Utillities\NavWalkers\Bootstrap
  • nk2580\wordsmith\Utillities\PDF
 1 <?php
 2 
 3 /*
 4  * WORDSMITH SETTINGS PAGE CLASS
 5  * 
 6  * this class is the base object for a post type to be added into wordpress.
 7  * 
 8  */
 9 
10 namespace nk2580\wordsmith\SettingsPages;
11 
12 class SettingsPage {
13 
14     protected $page_title;
15     protected $menu_title;
16     protected $icon;
17     protected $position;
18     protected $capability;
19     protected $slug;
20 
21     /**
22      * Hook into the appropriate actions when the class is constructed.
23      */
24     public function __construct() {
25         $this->init();
26     }
27 
28     /**
29      * register all required hooks for the settings page class.
30      */
31     public function init() {
32         add_action('admin_menu', array($this, 'init_page'));
33         add_action('admin_init', array($this, 'register_page_settings'));
34     }
35 
36     /**
37      * action to add the page to the admin menu.
38      */
39     public function init_page() {
40         add_menu_page($this->page_title, $this->menu_title, $this->capability, $this->slug, array($this, 'output_page'), $this->icon, $this->position);
41     }
42 
43     /**
44      * output the page content.
45      */
46     public function output_page() {
47         $this->settings_page_start();
48         $this->settings_page_ouptut();
49         $this->Settings_page_end();
50     }
51 
52     /**
53      * extension action for page start HTML output.
54      */
55     public function settings_page_start() {
56         echo '<form action="options.php" method="post">';
57     }
58 
59     /**
60      * extension action for page end HTML output.
61      */
62     public function Settings_page_end() {
63         echo '<hr/>';
64         submit_button();
65         echo '</form>';
66     }
67 
68     /**
69      * override this method to print the output of your settings page.
70      */
71     public function settings_page_ouptut() {
72         $output = '<h2>Example Settings Page</h2>' .
73                 '<p>override this content by implmenting the output_page() method in your custom page class.</p>';
74         echo $output;
75 
76         settings_fields('pluginPage');
77         do_settings_sections('pluginPage');
78     }
79 
80     /**
81      * registers the page settings for the settings page.
82      */
83     public function register_page_settings() {
84         //regsiter the setting to be saved
85         register_setting('pluginPage', 'sample_settings');
86         // add the setting section for the input field
87         add_settings_section(
88             'sample_pluginPage_section', __('Your section description', 'sample'), 'sample_settings_section_callback', 'pluginPage'
89         );
90         // register the fild using the input class
91         $samplefield = new \nk2580\wordsmith\Inputs\Fields\TextField('samplefield', '', false);
92         add_settings_field(
93             'samplefield', $samplefield->getLabel(), $samplefield->printField(), 'pluginPage', 'sample_pluginPage_section'
94         );
95     }
96 
97 }
98 
API documentation generated by ApiGen