-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclass-database-admin-admin.php
253 lines (194 loc) · 5.57 KB
/
class-database-admin-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
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
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://bowo.io
* @since 1.0.0
*
* @package Database_Admin
* @subpackage Database_Admin/admin
*/
/**
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package Database_Admin
* @subpackage Database_Admin/admin
* @author Bowo <[email protected]>
*/
class Database_Admin_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Database_Admin_Loader as all of the hooks are defined
* in that particular class.
*
* The Database_Admin_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/database-admin-admin.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Database_Admin_Loader as all of the hooks are defined
* in that particular class.
*
* The Database_Admin_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/database-admin-admin.js', array( 'jquery' ), $this->version, false );
}
/**
* Output Adminer iframe
*
* @since 1.0.0
*/
public function da_adminer() {
ob_start();
echo '<iframe id="da-iframe" src="/dbadmnr"></iframe>';
return ob_get_clean();
}
/**
* Conditionally include adminer.php script
*
* @since 1.0.0
*/
public function da_maybe_include_adminer() {
$request_uri = esc_url_raw( $_SERVER['REQUEST_URI'] );
if ( strpos( $request_uri, 'dbadmnr' ) !== false ) {
if ( current_user_can( 'manage_options' ) ) {
include plugin_dir_path( dirname( __FILE__ ) ) . 'admin/lib/adminer.php';
exit;
} else {
exit;
}
}
}
/**
* Add main admin page
*
* @since 1.0.0
*/
public function da_main_page() {
if ( class_exists( 'CSF' ) ) {
// Set a unique slug-like ID
$prefix = 'database-admin';
CSF::createOptions ( $prefix, array(
'menu_title' => 'Database Admin',
'menu_slug' => 'database-admin',
'menu_type' => 'submenu',
'menu_parent' => 'tools.php',
'menu_position' => 1,
'framework_title' => 'Database Admin <small>by <a href="https://bowo.io" target="_blank">bowo.io</a></small>',
'framework_class' => 'da',
'show_bar_menu' => false,
'show_search' => false,
'show_reset_all' => false,
'show_reset_section' => false,
'show_form_warning' => false,
'sticky_header' => true,
'save_defaults' => true,
'show_footer' => false,
'footer_credit' => '<a href="https://wordpress.org/plugins/database-admin/" target="_blank">Database Admin</a> (<a href="https://github.com/qriouslad/database-admin" target="_blank">github</a>) is built with the <a href="https://github.com/devinvinson/WordPress-Plugin-Boilerplate/" target="_blank">WordPress Plugin Boilerplate</a>, <a href="https://wppb.me" target="_blank">wppb.me</a>, <a href="https://github.com/Codestar/codestar-framework" target="_blank">CodeStar</a> and <a href="https://www.adminer.org/" target="_blank">Adminer</a>.',
) );
CSF::createSection( $prefix, array(
'title' => 'Adminer',
'fields' => array(
array(
'type' => 'content',
'title' => '',
'class' => 'da-body',
'content' => $this->da_adminer(),
),
),
) );
}
}
/**
* Register a submenu directly with WP core function
*
* @since 1.0.0
*/
public function da_register_submenu() {
add_submenu_page(
'tools.php',
'Database Admin',
'Database Admin',
'manage_options',
'database-admin',
'da_register_submenu_callback'
);
}
/**
* Skeleton callback function for submenu registration
*
* @since 1.0.0
*/
public function da_register_submenu_callback() {
echo 'Nothing to show here...';
}
/**
* Add "Access Now" plugin action link
*
* @since 1.0.0
*/
public function da_plugin_action_links( $links ) {
$action_link = '<a href="tools.php?page=' . $this->plugin_name . '">Access Now</a>';
array_unshift( $links, $action_link );
return $links;
}
/**
* Remove CodeStar framework welcome / ads page
*
* @since 1.0.0
*/
public function da_remove_codestar_submenu() {
remove_submenu_page( 'tools.php', 'csf-welcome' );
}
}