This repository has been archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
inc-admin-options-debug.php
171 lines (128 loc) · 4.19 KB
/
inc-admin-options-debug.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Simple FIelds options page for import and export
*/
class simple_fields_options_page_debug {
var
$slug = "debug",
$sf = null;
function __construct() {
add_action("simple_fields_init", array($this, "init"));
}
function init($sf) {
$this->sf = $sf;
// Add tab and output content when on that tab
add_action("simple_fields_after_last_options_nav_tab", array($this, "print_nav_tab"));
add_action("simple_fields_subpage_$this->slug", array($this, "output_page"));
// Save options on admin init
add_action("simple_fields_options_page_save", array($this, "save_debug_options"));
}
/**
* Get name of this options page tab
*
* @return string
*/
function get_name() {
return _e('Debug', 'simple-fields');
}
function output_scripts_and_styles() {
?>
<script>
</script>
<style>
</style>
<?php
}
/**
* Print the tab for this tab
*
* @param string $subpage Name of current tab
*/
function print_nav_tab($subpage) {
?>
<a href="<?php echo add_query_arg(array("sf-options-subpage" => $this->slug), SIMPLE_FIELDS_FILE) ?>" class="nav-tab <?php echo $this->slug === $subpage ? "nav-tab-active" : "" ?>"><?php esc_html( $this->get_name() ) ?></a>
<?php
}
/**
* Save options for debug
*/
function save_debug_options($action) {
if ("edit-options-save" == $action) {
if ( ! wp_verify_nonce( $_POST["_wpnonce"], "save-debug-options" ) ) wp_die( __("Cheatin’ uh?") );
$this->sf->save_options(array(
"debug_type" => (int) $_POST["debug_type"]
));
wp_redirect( add_query_arg( array(
"message" => "debug-options-saved",
"sf-options-subpage" => "debug"
), SIMPLE_FIELDS_FILE ) );
exit;
}
}
/**
* Output contents for this options page
*/
function output_page() {
do_action("simple_fields_options_print_nav_tabs", $this->slug);
?>
<div class="simple-fields-debug">
<h3><?php echo __('Debug', 'simple-fields') ?></h3>
<?php
// Dropdown with debug options
// Debug type. 0 = no debug, 1 = debug for admins only, 2 = debug for all
$options = $this->sf->get_options();
$debug_type = isset($options["debug_type"]) ? (int) $options["debug_type"] : "0";
// capability edit_themes
?>
<form action="<?php echo SIMPLE_FIELDS_FILE ?>&action=edit-options-save&sf-options-subpage=debug" method="post">
<?php
printf('
<p>
<select name=debug_type>
<option value=0 %1$s>%4$s</option>
<option value=1 %2$s>%5$s</option>
<option value=2 %3$s>%6$s</option>
</select>
</p>
',
$debug_type === 0 ? "selected" : "",
$debug_type === 1 ? "selected" : "",
$debug_type === 2 ? "selected" : "",
__("Don't enable debug output", "simple-fields"),
__("Enable debug output for administrators", "simple-fields"),
__("Enable debug output for all users", "simple-fields")
);
?>
<p class=description>
<?php _e("Automatically append information about attached fields on posts (using filter 'the_content').", "simple-fields"); ?>
</p>
<p>
<input class="button" type=submit value="<?php _e("Save changes", "simple-fields") ?>">
</p>
<?php wp_nonce_field( "save-debug-options" ) ?>
</form><!-- // enable debug -->
<ul>
<li><a href='<?php echo SIMPLE_FIELDS_FILE ?>&action=simple-fields-view-debug-info&sf-options-subpage=debug'><?php echo __('View debug information', 'simple-fields') ?></a></li>
</ul>
<?php
// view debug information
$action = isset( $_REQUEST["action"] ) ? $_REQUEST["action"] : "";
if ("simple-fields-view-debug-info" == $action) {
echo "<h3>Post Connectors</h3>\n";
echo "<p>Called with function <code>get_post_connectors()</code>";
sf_d( $this->sf->get_post_connectors() );
echo "<hr>";
echo "<h3>Field Groups</h3>\n";
echo "<p>Called with function <code>get_field_groups()</code>";
sf_d( $this->sf->get_field_groups() );
echo "<hr>";
echo "<h3>simple_fields_post_type_defaults</h3>";
echo '<p>Called with: get_option("simple_fields_post_type_defaults")';
sf_d( $this->sf->get_post_type_defaults() );
}
?>
</div>
<?php
}
}
new simple_fields_options_page_debug();