-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtootpress_developer.php
266 lines (207 loc) · 5.69 KB
/
tootpress_developer.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
/**
* Developer Tools
*
* @package TootPress
* @since 0.1
*/
// Security: Stops code execution if WordPress is not loaded
if (!defined('ABSPATH')) { exit; }
/**
* Adds Page to Tool Menu.
*
* @since 0.1
*/
function tootpress_tools_dev_menu() {
add_management_page(
'Toots Developer',
'Toots Developer',
'manage_options',
'tootpress-tools-dev-menu',
'tootpress_tools_dev_controller'
);
}
// Display developer tools only, if option is set
$tootpress_developer=get_option('tootpress_developer');
if ($tootpress_developer == 1)
{
add_action('admin_menu', 'tootpress_tools_dev_menu');
}
/**
* Controls the output of the tool page.
*
* @since 0.1
*/
function tootpress_tools_dev_controller() {
echo '<div class="wrap">';
// Apps
$tootpress_scripting=false;
$tootpress_clearing=false;
/*
Which App to load?
*/
// Scripting
if(isset($_GET['scripting'])) {
if($_GET['scripting']=='true')
{
$tootpress_scripting=true;
}
}
// Clearing
if(isset($_GET['clearing'])) {
if($_GET['clearing']=='true')
{
$tootpress_clearing=true;
}
}
// App Loader
if ($tootpress_scripting) {
tootpress_script_load();
}
elseif ($tootpress_clearing) {
tootpress_clearing_load();
} else {
// Display Apps, if no App selected
tootpress_tools_developer();
}
echo '</div>';
}
/**
* Displays the developer tools
*
* @since 0.1
*/
function tootpress_tools_developer() {
echo '
<!-- headline -->
<h1 class="tootpress_tools_headline">Toots Developer</h1>
<p class="tootpress_tools_description">Helper Tools</p>
<table class="form-table">
<!-- Run the script -->
<tr valign="top">
<th scope="row">
<label for="cron">Run Script</label>
</th>
<td>
<a class="button" href="'.admin_url(). 'tools.php?page=tootpress-tools-dev-menu&scripting=true">Yes!</a>
</td>
</tr>
<!-- Clear Data -->
<tr valign="top">
<th scope="row">
<label for="cron">Start afresh</label>
</th>
<td>
<a class="button" href="'.admin_url(). 'tools.php?page=tootpress-tools-dev-menu&clearing=true">Do!</a>
</td>
</tr>
</table>';
}
/**
* Executes the script tool
*
* @since 0.1
*/
function tootpress_script_load() {
echo '<h1 class="tootpress_tools_headline">TootPress › Scripting</h1>';
echo '<p class="tootpress_tools_description">Output<br/> </p>';
tootpress_scripting();
tootpress_tools_dev_close();
}
/**
* Executes the data clearing
*
* @since 0.1
*/
function tootpress_clearing_load() {
tootpress_clear_data();
echo '<h1 class="tootpress_tools_headline">TootPress › Start afresh</h1>';
echo '<p class="tootpress_tools_description">Following data were reset.</p>';
echo '<p>';
echo '* Toots<br/>';
echo '* Media<br/>';
echo '* Option Latest Toot<br/>';
echo '* Option Oldest Toot<br/>';
echo '* Option Last Insert<br/>';
echo '* Option Timeline Complete<br/>';
echo '* Option Cron NewToots Status<br/>';
echo '* Option Cron AllToots Status<br/>';
echo '</p>';
tootpress_tools_dev_close();
}
/**
* Outputs the bottom of the tool page
*
* @since 0.1
*/
function tootpress_tools_dev_close() {
echo '<p> <br/><a class="button" href="'.esc_url(admin_url()).'tools.php?page=tootpress-tools-dev-menu">Back to TootPress Tools</a></p>';
}
/**
* Adds Developer Options Page to Options Menu.
*
* @since 0.1
*/
function tootpress_options_dev_menu() {
add_options_page('TootPress Developer', 'TootPress Developer', 'manage_options', 'tootpress-options-dev', "tootpress_options_dev_content");
}
// Display developer option only, if option is set
$tootpress_developer=get_option('tootpress_developer');
if ($tootpress_developer == 1)
{
add_action( 'admin_menu', 'tootpress_options_dev_menu');
}
/**
* Defines the TootPress Developer Options Page
*
* @since 0.1
*/
function tootpress_options_dev_content() {
// Header
echo '
<div class="wrap">
<h1>Options › TootPress Developer</h1>
<p class="tootpress_settings_dev">Internal Process Options<br/> </p>
<form method="post" action="options.php">';
// Options
do_settings_sections( 'tootpress-options-dev' );
settings_fields( 'tootpress_options_dev' );
submit_button();
echo '</form></div><div class="clear"></div>';
}
/**
* Displays the Input Fields for Developers.
*
* @since 0.1
*/
function tootpress_options_dev_display_latest_toot()
{
echo '<input class="regular-text" type="text" name="tootpress_latest_toot" id="tootpress_latest_toot" value="' . esc_attr(get_option('tootpress_latest_toot')) .'"/>';
}
function tootpress_options_dev_display_oldest_toot()
{
echo '<input class="regular-text" type="text" name="tootpress_oldest_toot" id="tootpress_oldest_toot" value="'. esc_attr(get_option('tootpress_oldest_toot')) .'"/>';
}
/**
* Displays the Developer Chapter Description.
*
* @since 0.1
*/
function tootpress_options_dev_display_description()
{ echo '<p>Database Values</p>'; }
/**
* Defines the Developer Option Chapters including input fields
*
* @since 0.1
*/
function tootpress_options_dev_display()
{
add_settings_section("tootpress_settings_dev_section", "Read / Manipulate", "tootpress_options_dev_display_description", "tootpress-options-dev");
add_settings_field("tootpress_latest_toot", "Latest Toot", "tootpress_options_dev_display_latest_toot", "tootpress-options-dev", "tootpress_settings_dev_section");
add_settings_field("tootpress_oldest_toot", "Oldest Toot", "tootpress_options_dev_display_oldest_toot", "tootpress-options-dev", "tootpress_settings_dev_section");
register_setting("tootpress_options_dev", "tootpress_latest_toot");
register_setting("tootpress_options_dev", "tootpress_oldest_toot");
}
// Actions
add_action("admin_init", "tootpress_options_dev_display");
?>