-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.php
154 lines (117 loc) · 4.03 KB
/
admin.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/*
* WP Feature Box
* Admin settings
*/
if(!class_exists('WP_Feature_Box_Admin')) {
class WP_Feature_Box_Admin extends WP_Feature_Box {
var $settings_id = 'wfb_settings';
var $settings_group = 'wfb_settings_group';
var $settings_page = 'wfb-settings';
function __construct() {
add_action('admin_menu', array($this, 'add_plugin_page'));
add_action('admin_init', array($this, 'page_init'));
add_filter('wp_feature_box_options', array($this, 'filter_options'));
}
function add_plugin_page() {
add_submenu_page('edit.php?post_type=' . $this->post_type, __('Settings', 'wp-feature-box'), __('Settings', 'wp-feature-box'), 'manage_options', $this->settings_page, array($this, 'create_admin_page'));
}
function create_admin_page() {
$this->store_data();
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e('Feature box settings', 'wp-feature-box'); ?></h2>
<form method="post">
<?php
// This prints out all hidden setting fields
settings_fields($this->settings_group);
do_settings_sections($this->settings_page);
submit_button();
?>
</form>
<form method="post">
<input type="hidden" name="wfb_settings_reset" value="1" />
<?php submit_button(__('Restore default settings', 'wp-feature-box'), 'secondary'); ?>
</form>
</div>
<?php
}
function page_init() {
/*
* Embed
*/
add_settings_section(
'wfb_embed',
__('Embed options', 'wp-feature-box'),
array($this, 'embed_info'),
$this->settings_page
);
add_settings_field(
'allow_embed',
__('Allow embed', 'wp-feature-box'),
array($this, 'embed_allow_input'),
$this->settings_page,
'wfb_embed'
);
add_settings_field(
'default_embed_text',
__('Default footer text (embed credits)', 'wp-feature-box'),
array($this, 'embed_default_text_input'),
$this->settings_page,
'wfb_embed'
);
add_settings_field(
'default_embed_link',
__('Default footer text link', 'wp-feature-box'),
array($this, 'embed_default_link_input'),
$this->settings_page,
'wfb_embed'
);
}
function store_data($input = false) {
if(isset($_REQUEST['wfb_settings_reset'])) {
delete_option($this->settings_id);
return;
}
$input = $input ? $input : $_POST[$this->settings_id];
if(isset($input)) {
if(get_option($this->settings_id) === false)
add_option($this->settings_id, $input);
else
update_option($this->settings_id, $input);
}
}
function filter_options($settings) {
$options = get_option($this->settings_id);
if($options)
$settings = array_merge($settings, $options);
return $settings;
}
function embed_info() {
echo '<p>' . __('Set your embed options:', 'wp-feature-box') , '</p>';
}
function embed_allow_input() {
$options = $this->get_options();
?>
<input type="radio" id="wfb_allow_embed_yes" name="<?php echo $this->settings_id; ?>[allow_embed]" value="1" <?php if($options['allow_embed']) echo 'checked'; ?> /> <label for="wfb_allow_embed_yes"><?php _e('Yes', 'wp-feature-box'); ?></label>
<input type="radio" id="wfb_allow_embed_no" name="<?php echo $this->settings_id; ?>[allow_embed]" value="0" <?php if(!$options['allow_embed']) echo 'checked'; ?> /> <label for="wfb_allow_embed_no"><?php _e('No', 'wp-feature-box'); ?></label>
<?php
}
function embed_default_text_input() {
$options = $this->get_options();
?>
<input type="text" id="wfb_default_embed_text" size="80" name="<?php echo $this->settings_id; ?>[default_embed_text]" value="<?php echo $options['default_embed_text']; ?>" />
<?php
}
function embed_default_link_input() {
$options = $this->get_options();
?>
<input type="text" id="wfb_default_embed_link" size="80" name="<?php echo $this->settings_id; ?>[default_embed_link]" value="<?php echo $options['default_embed_link']; ?>" />
<?php
}
}
}
if(class_exists('WP_Feature_Box_Admin')) {
$wp_feature_box_admin = new WP_Feature_Box_Admin();
}