-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.admin-setup.php
66 lines (54 loc) · 1.71 KB
/
class.admin-setup.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
<?php
/*
* Registers the Settings page
*
*/
class Smartkeys_Admin {
function __construct() {
// Set up the admin page in menu
add_action( 'admin_menu', array( $this, 'smartkeys_register_admin_page' ), 1 );
// Save changes
add_action( 'admin_init', array( $this, 'smartkeys_save_settings' ) );
}
/*
* Register Settings Page
*/
function smartkeys_register_admin_page() {
$parent_slug = 'options-general.php';
$smartkeys_page_title = 'SmartKeys Settings';
$smartkeys_menu_title = 'SmartKeys';
$smartkeys_capability = 'manage_options';
$smartkeys_menu_slug = 'smartkeys';
$smartkeys_function = array( $this, 'render_smartkeys_main_page' );
add_submenu_page(
$parent_slug,
$smartkeys_page_title,
$smartkeys_menu_title,
$smartkeys_capability,
$smartkeys_menu_slug,
$smartkeys_function
);
add_action( 'admin_enqueue_scripts', array( $this, 'smartkeys_enqueue_assets' ) );
}
// Enqueue Style
function smartkeys_enqueue_assets( $hook ) {
if ( 'settings_page_smartkeys' != $hook )
return;
wp_enqueue_style( 'smartkeys-css' );
}
// Include view file for settings
function render_smartkeys_main_page() {
// include_once 'larry-bird.php';
include_once 'views/admin-settings.php';
}
// Save the settings
function smartkeys_save_settings() {
if ( isset( $_POST['smartkeys_save_nonce'] ) && wp_verify_nonce( $_POST['smartkeys_save_nonce'], 'smartkeys_save' ) ) {
update_option( 'keys_to_save', $_POST['saved_keys'] );
add_action( 'admin_notices', array( $this, 'smartkeys_updated_success_message' ) );
}
}
function smartkeys_updated_success_message() {
echo '<div id="message" class="updated below-h2"><p>Settings Updated!</p></div>';
}
}