1 <?php
2
3 4 5 6 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 23
24 public function __construct() {
25 $this->init();
26 }
27
28 29 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 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 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 54
55 public function settings_page_start() {
56 echo '<form action="options.php" method="post">';
57 }
58
59 60 61
62 public function Settings_page_end() {
63 echo '<hr/>';
64 submit_button();
65 echo '</form>';
66 }
67
68 69 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 82
83 public function register_page_settings() {
84
85 register_setting('pluginPage', 'sample_settings');
86
87 add_settings_section(
88 'sample_pluginPage_section', __('Your section description', 'sample'), 'sample_settings_section_callback', 'pluginPage'
89 );
90
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