-
Notifications
You must be signed in to change notification settings - Fork 63
/
settings.php
105 lines (97 loc) · 3.5 KB
/
settings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
if(!class_exists('WP_Plugin_Template_Settings'))
{
class WP_Plugin_Template_Settings
{
/**
* Construct the plugin object
*/
public function __construct()
{
// register actions
add_action('admin_init', array(&$this, 'admin_init'));
add_action('admin_menu', array(&$this, 'add_menu'));
} // END public function __construct
/**
* hook into WP's admin_init action hook
*/
public function admin_init()
{
// register your plugin's settings
register_setting('wp_plugin_template-group', 'setting_a');
register_setting('wp_plugin_template-group', 'setting_b');
// add your settings section
add_settings_section(
'wp_plugin_template-section',
'WP Plugin Template Settings',
array(&$this, 'settings_section_wp_plugin_template'),
'wp_plugin_template'
);
// add your setting's fields
add_settings_field(
'wp_plugin_template-setting_a',
'Setting A',
array(&$this, 'settings_field_input_text'),
'wp_plugin_template',
'wp_plugin_template-section',
array(
'field' => 'setting_a'
)
);
add_settings_field(
'wp_plugin_template-setting_b',
'Setting B',
array(&$this, 'settings_field_input_text'),
'wp_plugin_template',
'wp_plugin_template-section',
array(
'field' => 'setting_b'
)
);
// Possibly do additional admin_init tasks
} // END public static function activate
public function settings_section_wp_plugin_template()
{
// Think of this as help text for the section.
echo 'These settings do things for the WP Plugin Template.';
}
/**
* This function provides text inputs for settings fields
*/
public function settings_field_input_text($args)
{
// Get the field name from the $args array
$field = $args['field'];
// Get the value of this setting
$value = get_option($field);
// echo a proper input type="text"
echo sprintf('<input type="text" name="%s" id="%s" value="%s" />', $field, $field, $value);
} // END public function settings_field_input_text($args)
/**
* add a menu
*/
public function add_menu()
{
// Add a page to manage this plugin's settings
add_options_page(
'WP Plugin Template Settings',
'WP Plugin Template',
'manage_options',
'wp_plugin_template',
array(&$this, 'plugin_settings_page')
);
} // END public function add_menu()
/**
* Menu Callback
*/
public function plugin_settings_page()
{
if(!current_user_can('manage_options'))
{
wp_die(__('You do not have sufficient permissions to access this page.'));
}
// Render the settings template
include(sprintf("%s/templates/settings.php", dirname(__FILE__)));
} // END public function plugin_settings_page()
} // END class WP_Plugin_Template_Settings
} // END if(!class_exists('WP_Plugin_Template_Settings'))