-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathclass.bcn_network_admin.php
218 lines (214 loc) · 7.3 KB
/
class.bcn_network_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
<?php
/*
Copyright 2015-2025 John Havlik (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once(dirname(__FILE__) . '/includes/block_direct_access.php');
//Include admin base class
if(!class_exists('bcn_admin'))
{
require_once(dirname(__FILE__) . '/class.bcn_admin.php');
}
use mtekk\adminKit\{adminKit, form, message, setting};
/**
* The administrative interface class
*
*/
class bcn_network_admin extends bcn_admin
{
const version = '7.4.1';
protected $full_name = 'Breadcrumb NavXT Network Settings';
protected $access_level = 'manage_network_options';
/**
* Administrative interface class default constructor
* @param bcn_breadcrumb_trail $breadcrumb_trail a breadcrumb trail object
* @param string $basename The basename of the plugin
*/
function __construct(array &$opts, $basename, array &$settings)
{
//We're going to make sure we load the parent's constructor
parent::__construct($opts, $basename, $settings);
//Change to the proper name
$this->full_name = __('Breadcrumb NavXT Network Settings', 'breadcrumb-navxt');
//Remove the hook added by the parent as we don't want this classes settings page everywhere
remove_action('admin_menu', array($this, 'add_page'));
//Replace with the network_admin hook
add_action('network_admin_menu', array($this, 'add_page'));
}
function is_network_admin()
{
return true;
}
/**
* admin initialization callback function
*
* is bound to wordpress action 'admin_init' on instantiation
*
* @since 3.2.0
* @return void
*/
function init()
{
//We're going to make sure we run the parent's version of this function as well
parent::init();
}
function wp_loaded()
{
parent::wp_loaded();
}
/**
* Return the URL of the settings page for the plugin
*/
function admin_url()
{
return admin_url('network/settings.php?page=' . $this->identifier);
}
/**
* Adds the adminpage the menu and the nice little settings link
*/
function add_page()
{
//Add the submenu page to "settings" menu
$hookname = add_submenu_page('settings.php', $this->full_name, $this->short_name, $this->access_level, $this->identifier, array($this, 'admin_page'));
// check capability of user to manage options (access control)
if(current_user_can($this->access_level))
{
//Register admin_head-$hookname callback
add_action('admin_head-' . $hookname, array($this, 'admin_head'));
//Register admin_print_styles-$hookname callback
add_action('admin_print_styles-' . $hookname, array($this, 'admin_styles'));
//Register admin_print_scripts-$hookname callback
add_action('admin_print_scripts-' . $hookname, array($this, 'admin_scripts'));
//Register Help Output
add_action('load-' . $hookname, array($this, 'help'));
}
}
/**
* help action hook function
*
* @return string
*
*/
function help()
{
$screen = get_current_screen();
//Exit early if the add_help_tab function doesn't exist
if(!method_exists($screen, 'add_help_tab'))
{
return;
}
//Add contextual help on current screen
if($screen->id == 'settings_page_' . $this->identifier . '-network')
{
$this->help_contents($screen);
}
}
/**
* Have to hook into get_option and replace with network wide alternate
*
* @param string $option The name of the option to retrieve
* @return mixed The value of the option
*/
function get_option($option)
{
return get_site_option($option);
}
/**
* Have to hook into update_option and replace with network wide alternate
*
* @param string $option The name of the option to update
* @param mixed $newvalue The new value to set the option to
*
*/
function update_option($option, $newvalue, $autoload = null)
{
return update_site_option($option, $newvalue);
}
/**
* Have to hook into add_option and replace with network wide alternate
*
* @param string $option The name of the option to update
* @param mixed $value The new value to set the option to
* @param null $deprecated Deprecated parameter
* @param string $autoload Whether or not to autoload the option, it's a string because WP is special
*
*/
function add_option($option, $value = '', $deprecated = '', $autoload = 'yes')
{
return add_site_option($option, $value);
}
/**
* Have to hook into delete_option and replace with network wide alternate
*
* @param string $option The name of the option to delete
*/
function delete_option($option)
{
return delete_site_option($option);
}
/**
* A message function that checks for the BCN_SETTINGS_* define statement
*/
function multisite_settings_warn()
{
if(is_multisite())
{
if(defined('BCN_SETTINGS_USE_LOCAL') && BCN_SETTINGS_USE_LOCAL)
{
$this->messages[] = new message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride');
}
else if(defined('BCN_SETTINGS_USE_NETWORK') && BCN_SETTINGS_USE_NETWORK)
{
}
else if(defined('BCN_SETTINGS_FAVOR_LOCAL') && BCN_SETTINGS_FAVOR_LOCAL)
{
$this->messages[] = new message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isitemayoveride');
}
else if(defined('BCN_SETTINGS_FAVOR_NETWORK') && BCN_SETTINGS_FAVOR_NETWORK)
{
$this->messages[] = new message(esc_html__('Warning: Individual site settings may override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nsmayoveride');
}
//Fall through if no settings mode was set
else
{
$this->messages[] = new message(esc_html__('Warning: No BCN_SETTINGS_* define statement found, defaulting to BCN_SETTINGS_USE_LOCAL.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_nosetting');
$this->messages[] = new message(esc_html__('Warning: Individual site settings will override any settings set in this page.', 'breadcrumb-navxt'), 'warning', true, $this->unique_prefix . '_msg_ns_isiteoveride');
}
}
}
/**
* A message function that checks for deprecated settings that are set and warns the user
*/
function deprecated_settings_warn()
{
parent::deprecated_settings_warn();
}
/**
* Function checks the current site to see if the blog options should be disabled
*
* @return boool Whether or not the blog options should be disabled
*/
function maybe_disable_blog_options()
{
return false;
}
/**
* Function checks the current site to see if the mainsite options should be disabled
*
* @return bool Whether or not the mainsite options should be disabled
*/
function maybe_disable_mainsite_options()
{
return false;
}
}