|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* FooGallery Admin Menu class |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
if ( ! class_exists( 'FooGallery_Admin_Menu' ) ) { |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class FooGallery_Admin_Menu { |
|
11
|
|
|
|
|
12
|
|
|
function __construct() { |
|
13
|
|
|
add_action( 'admin_menu', array( $this, 'register_menu_items' ) ); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @todo add context to the translations |
|
18
|
|
|
*/ |
|
19
|
|
|
function register_menu_items() { |
|
20
|
|
|
//we rely on the register_post_type call to add our main menu items |
|
21
|
|
|
$parent_slug = foogallery_admin_menu_parent_slug(); |
|
22
|
|
|
|
|
23
|
|
|
//allow extensions to add their own menu items beforehand |
|
24
|
|
|
do_action( 'foogallery_admin_menu_before' ); |
|
25
|
|
|
|
|
26
|
|
|
$menu_labels = apply_filters( 'foogallery_admin_menu_labels', |
|
27
|
|
|
array( |
|
28
|
|
|
array( |
|
29
|
|
|
'page_title' => sprintf( __( '%s Settings', 'foogallery' ), foogallery_plugin_name() ), |
|
30
|
|
|
'menu_title' => __( 'Settings', 'foogallery' ), |
|
31
|
|
|
), |
|
32
|
|
|
array( |
|
33
|
|
|
'page_title' => sprintf( __( '%s Extensions', 'foogallery' ), foogallery_plugin_name() ), |
|
34
|
|
|
'menu_title' => __( 'Extensions', 'foogallery' ), |
|
35
|
|
|
), |
|
36
|
|
|
array( |
|
37
|
|
|
'page_title' => sprintf( __( '%s Help', 'foogallery' ), foogallery_plugin_name() ), |
|
38
|
|
|
'menu_title' => __( 'Help', 'foogallery' ), |
|
39
|
|
|
), |
|
40
|
|
|
array( |
|
41
|
|
|
'page_title' => sprintf( __( '%s System Information', 'foogallery' ), foogallery_plugin_name() ), |
|
42
|
|
|
'menu_title' => __( 'System Info', 'foogallery' ), |
|
43
|
|
|
), |
|
44
|
|
|
) |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$capability = apply_filters( 'foogallery_admin_menu_capability', 'manage_options' ); |
|
48
|
|
|
|
|
49
|
|
|
add_submenu_page( $parent_slug, $menu_labels[0]['page_title'], $menu_labels[0]['menu_title'], $capability, 'foogallery-settings', array( $this, 'foogallery_settings' ) ); |
|
50
|
|
|
add_submenu_page( $parent_slug, $menu_labels[1]['page_title'], $menu_labels[1]['menu_title'], $capability, 'foogallery-extensions', array( $this, 'foogallery_extensions' ) ); |
|
51
|
|
|
add_submenu_page( $parent_slug, $menu_labels[2]['page_title'], $menu_labels[2]['menu_title'], $capability, 'foogallery-help', array( $this, 'foogallery_help' ) ); |
|
52
|
|
|
|
|
53
|
|
|
if ( current_user_can( 'activate_plugins' ) ) { |
|
54
|
|
|
add_submenu_page( $parent_slug, $menu_labels[3]['page_title'], $menu_labels[3]['menu_title'], $capability, 'foogallery-systeminfo', array( $this, 'foogallery_systeminfo' ) ); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
//allow extensions to add their own menu items afterwards |
|
58
|
|
|
do_action( 'foogallery_admin_menu_after' ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
function foogallery_settings() { |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
$admin_errors = get_transient( 'settings_errors' ); |
|
64
|
|
|
$show_reset_message = false; |
|
65
|
|
|
|
|
66
|
|
|
if ( is_array( $admin_errors ) ) { |
|
67
|
|
|
//try to find a reset 'error' |
|
68
|
|
|
foreach ( $admin_errors as $error ) { |
|
69
|
|
|
if ( 'reset' === $error['setting'] ) { |
|
70
|
|
|
$show_reset_message = true; |
|
71
|
|
|
break; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ( $show_reset_message ) { |
|
77
|
|
|
do_action( 'foogallery_settings_reset' ); |
|
78
|
|
|
?> |
|
79
|
|
|
<div id="message" class="updated"> |
|
80
|
|
|
<p><strong><?php printf( __( '%s settings reset to defaults.', 'foogallery' ), foogallery_plugin_name() ); ?></strong></p> |
|
81
|
|
|
</div> |
|
82
|
|
|
<?php } else if ( isset($_GET['settings-updated']) ) { |
|
83
|
|
|
do_action( 'foogallery_settings_updated' ); |
|
84
|
|
|
?> |
|
85
|
|
|
<div id="message" class="updated"> |
|
86
|
|
|
<p><strong><?php printf( __( '%s settings updated.', 'foogallery' ), foogallery_plugin_name() ); ?></strong></p> |
|
87
|
|
|
</div> |
|
88
|
|
|
<?php } |
|
89
|
|
|
|
|
90
|
|
|
$instance = FooGallery_Plugin::get_instance(); |
|
91
|
|
|
$instance->admin_settings_render_page(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
function foogallery_extensions() { |
|
95
|
|
|
require_once FOOGALLERY_PATH . 'includes/admin/view-extensions.php'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
function foogallery_help() { |
|
99
|
|
|
require_once FOOGALLERY_PATH . 'includes/admin/view-help.php'; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function foogallery_systeminfo() { |
|
103
|
|
|
require_once FOOGALLERY_PATH . 'includes/admin/view-system-info.php'; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.