-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmegafono-wordpress-admin-page.php
51 lines (43 loc) · 1.52 KB
/
megafono-wordpress-admin-page.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
<?php
class MegafonoWordpressAdminPage {
function __construct( ) {
add_menu_page( 'Megafono', 'Megafono', 'manage_options', 'megafono', array( $this, 'render'), 'dashicons-megaphone', 61 );
}
public function render() {
global $wpdb;
$table_name = $wpdb->prefix . 'megafono_settings';
$uid = $wpdb->get_row( "SELECT value FROM $table_name WHERE name='uid' LIMIT 1");
if ( $_SERVER["REQUEST_METHOD"] == "POST" ){
$this->handle_post($uid);
$uid = $wpdb->get_row( "SELECT value FROM $table_name WHERE name='uid' LIMIT 1");
}
$uid_value = $uid ? $uid->value : '';
include_once( 'views/admin.php' );
}
public function handle_post($uid) {
if( check_admin_referer( 'megafono-settings-save', 'megafono-settings' ) && isset($_POST['megafono_uid']) ) {
global $wpdb;
$table_name = $wpdb->prefix . 'megafono_settings';
if ( $uid == null ) {
$wpdb->insert(
$table_name,
array(
'name' => 'uid',
'value' => $_POST['megafono_uid'],
)
);
} else {
$wpdb->update(
$table_name,
array(
'value' => $_POST['megafono_uid'],
),
array(
'name' => 'uid'
)
);
}
}
}
}
?>