| 1 |
<?php |
| 2 |
/** |
| 3 |
Plugin Name: User Role by BestWebSoft |
| 4 |
Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/user-role/ |
| 5 |
Description: Powerful user role management plugin for WordPress website. Create, edit, copy, and delete user roles. |
| 6 |
Author: BestWebSoft |
| 7 |
Text Domain: user-role |
| 8 |
Domain Path: /languages |
| 9 |
Version: 1.6.8 |
| 10 |
Author URI: https://bestwebsoft.com/ |
| 11 |
License: GPLv3 or later |
| 12 |
*/ |
| 13 |
|
| 14 |
/* |
| 15 |
© Copyright 2023 BestWebSoft ( https://support.bestwebsoft.com ) |
| 16 |
|
| 17 |
This program is free software; you can redistribute it and/or modify |
| 18 |
it under the terms of the GNU General Public License, version 2, as |
| 19 |
published by the Free Software Foundation. |
| 20 |
|
| 21 |
This program is distributed in the hope that it will be useful, |
| 22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
GNU General Public License for more details. |
| 25 |
|
| 26 |
You should have received a copy of the GNU General Public License |
| 27 |
along with this program; if not, write to the Free Software |
| 28 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 |
*/ |
| 30 |
|
| 31 |
if ( ! function_exists( 'srrl_add_pages' ) ) { |
| 32 |
function srrl_add_pages() { |
| 33 |
global $submenu, $srrl_plugin_info, $wp_version; |
| 34 |
|
| 35 |
$settings = add_menu_page( __( 'Roles', 'user-role' ), 'User Role', 'manage_options', 'user-role.php', 'srrl_main_page', 'none' ); |
| 36 |
add_submenu_page( 'user-role.php', __( 'Roles', 'user-role' ), __( 'Roles', 'user-role' ), 'manage_options', 'user-role.php', 'srrl_main_page' ); |
| 37 |
if ( isset( $_REQUEST['srrl_action'] ) && in_array( $_REQUEST['srrl_action'], array( 'edit', 'update' ) ) ) { |
| 38 |
add_submenu_page( 'user-role.php', __( 'Edit Role', 'user-role' ), __( 'Add New', 'user-role' ), 'manage_options', 'srrl_add_new_roles', 'srrl_add_new_roles' ); |
| 39 |
} else { |
| 40 |
add_submenu_page( 'user-role.php', __( 'Add New', 'user-role' ), __( 'Add New', 'user-role' ), 'manage_options', 'srrl_add_new_roles', 'srrl_add_new_roles' ); |
| 41 |
} |
| 42 |
add_submenu_page( 'user-role.php', __( 'User Role Settings', 'user-role' ), __( 'Settings', 'user-role' ), 'manage_options', 'srrl_settings', 'srrl_settings_page' ); |
| 43 |
add_submenu_page( 'user-role.php', 'BWS Panel', 'BWS Panel', 'manage_options', 'srrl-bws-panel', 'bws_add_menu_render' ); |
| 44 |
|
| 45 |
if ( isset( $submenu['user-role.php'] ) ) { |
| 46 |
$submenu['user-role.php'][] = array( |
| 47 |
'<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'user-role' ) . '</span>', |
| 48 |
'manage_options', |
| 49 |
'https://bestwebsoft.com/products/wordpress/plugins/user-role/?k=0e8fa1e4abf7647412878a5570d4977a&pn=132&v=' . $srrl_plugin_info['Version'] . '&wp_v=' . $wp_version, |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
add_action( 'load-' . $settings, 'srrl_add_tabs' ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
if ( ! function_exists( 'srrl_plugins_loaded' ) ) { |
| 58 |
function srrl_plugins_loaded() { |
| 59 |
load_plugin_textdomain( 'user-role', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/* Plugin init function */ |
| 64 |
if ( ! function_exists( 'srrl_init' ) ) { |
| 65 |
function srrl_init() { |
| 66 |
global $srrl_plugin_info; |
| 67 |
|
| 68 |
require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php'; |
| 69 |
bws_include_init( plugin_basename( __FILE__ ) ); |
| 70 |
|
| 71 |
if ( empty( $srrl_plugin_info ) ) { |
| 72 |
if ( ! function_exists( 'get_plugin_data' ) ) { |
| 73 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 74 |
} |
| 75 |
$srrl_plugin_info = get_plugin_data( dirname( __FILE__ ) . '/user-role.php' ); |
| 76 |
} |
| 77 |
|
| 78 |
/* Function check if plugin is compatible with current WP version */ |
| 79 |
bws_wp_min_version_check( plugin_basename( __FILE__ ), $srrl_plugin_info, '4.5' ); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
/* Plugin admin init function */ |
| 84 |
if ( ! function_exists( 'srrl_admin_init' ) ) { |
| 85 |
function srrl_admin_init() { |
| 86 |
global $bws_plugin_info, $srrl_plugin_info, $pagenow, $srrl_options; |
| 87 |
|
| 88 |
if ( empty( $bws_plugin_info ) ) { |
| 89 |
$bws_plugin_info = array( |
| 90 |
'id' => '132', |
| 91 |
'version' => $srrl_plugin_info['Version'], |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
/* Call register settings function */ |
| 96 |
$plugin_pages = array( |
| 97 |
'user-role.php', |
| 98 |
'srrl_add_new_roles', |
| 99 |
'srrl_settings', |
| 100 |
); |
| 101 |
if ( isset( $_GET['page'] ) && in_array( sanitize_text_field( $_GET['page'] ), $plugin_pages ) ) { |
| 102 |
srrl_register_settings(); |
| 103 |
} |
| 104 |
|
| 105 |
if ( 'plugins.php' === $pagenow ) { |
| 106 |
/* Install the option defaults */ |
| 107 |
if ( function_exists( 'bws_plugin_banner_go_pro' ) ) { |
| 108 |
srrl_register_settings(); |
| 109 |
bws_plugin_banner_go_pro( $srrl_options, $srrl_plugin_info, 'srrl', 'user-role', 'a2f27e2893147873133fe67d81fa274d', '132', 'user-role' ); |
| 110 |
|
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/* Style & js on */ |
| 117 |
if ( ! function_exists( 'srrl_admin_head' ) ) { |
| 118 |
function srrl_admin_head() { |
| 119 |
wp_enqueue_style( 'srrl_icon', plugins_url( 'css/icon.css', __FILE__ ) ); |
| 120 |
|
| 121 |
$plugin_pages = array( |
| 122 |
'user-role.php', |
| 123 |
'srrl_add_new_roles', |
| 124 |
'srrl_settings', |
| 125 |
); |
| 126 |
if ( isset( $_GET['page'] ) && in_array( sanitize_text_field( $_GET['page'] ), $plugin_pages ) ) { |
| 127 |
wp_enqueue_style( 'srrl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) ); |
| 128 |
wp_enqueue_script( 'srrl_script', plugins_url( '/js/script.js', __FILE__ ), array( 'jquery' ) ); |
| 129 |
$srrl_translation_array = array( |
| 130 |
'confirm_recover' => __( 'Are you sure, you want to recover selected role(s)?', 'user-role' ), |
| 131 |
); |
| 132 |
wp_localize_script( 'srrl_script', 'srrl_translation', $srrl_translation_array ); |
| 133 |
|
| 134 |
bws_enqueue_settings_scripts(); |
| 135 |
} |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/*Plugin activate*/ |
| 140 |
if ( ! function_exists( 'srrl_plugin_activate' ) ) { |
| 141 |
function srrl_plugin_activate() { |
| 142 |
if ( is_multisite() ) { |
| 143 |
switch_to_blog( 1 ); |
| 144 |
register_uninstall_hook( __FILE__, 'srrl_delete_options' ); |
| 145 |
restore_current_blog(); |
| 146 |
} else { |
| 147 |
register_uninstall_hook( __FILE__, 'srrl_delete_options' ); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
if ( ! function_exists( 'srrl_get_options_default' ) ) { |
| 153 |
function srrl_get_options_default() { |
| 154 |
global $srrl_plugin_info; |
| 155 |
|
| 156 |
return array( |
| 157 |
'plugin_option_version' => $srrl_plugin_info['Version'], |
| 158 |
'first_install' => strtotime( 'now' ), |
| 159 |
'suggest_feature_banner' => 1, |
| 160 |
); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Create plugin options |
| 166 |
* |
| 167 |
* @return void |
| 168 |
*/ |
| 169 |
if ( ! function_exists( 'srrl_register_settings' ) ) { |
| 170 |
function srrl_register_settings() { |
| 171 |
global $srrl_options, $srrl_plugin_info, $wpdb; |
| 172 |
|
| 173 |
if ( is_multisite() && is_network_admin() ) { |
| 174 |
if ( ! get_site_option( 'srrl_options' ) ) { |
| 175 |
add_site_option( 'srrl_options', srrl_get_options_default() ); |
| 176 |
} |
| 177 |
|
| 178 |
$srrl_options = get_site_option( 'srrl_options' ); |
| 179 |
} else { |
| 180 |
if ( ! get_option( 'srrl_options' ) ) { |
| 181 |
add_option( 'srrl_options', srrl_get_options_default() ); |
| 182 |
} |
| 183 |
|
| 184 |
$srrl_options = get_option( 'srrl_options' ); |
| 185 |
} |
| 186 |
|
| 187 |
if ( ! isset( $srrl_options['plugin_option_version'] ) || $srrl_plugin_info['Version'] !== $srrl_options['plugin_option_version'] ) { |
| 188 |
$srrl_options['plugin_option_version'] = $srrl_plugin_info['Version']; |
| 189 |
$srrl_options['hide_premium_options'] = array(); |
| 190 |
if ( is_multisite() ) { |
| 191 |
$all_blogs = $wpdb->get_col( 'SELECT `blog_id` FROM `' . $wpdb->base_prefix . 'blogs`' ); |
| 192 |
foreach ( $all_blogs as $blog_id ) { |
| 193 |
update_blog_option( $blog_id, 'srrl_options', $srrl_options ); |
| 194 |
} |
| 195 |
update_site_option( 'srrl_options', $srrl_options ); |
| 196 |
switch_to_blog( 1 ); |
| 197 |
register_uninstall_hook( __FILE__, 'srrl_delete_options' ); |
| 198 |
restore_current_blog(); |
| 199 |
} else { |
| 200 |
update_option( 'srrl_options', $srrl_options ); |
| 201 |
register_uninstall_hook( __FILE__, 'srrl_delete_options' ); |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Settings page |
| 209 |
*/ |
| 210 |
if ( ! function_exists( 'srrl_settings_page' ) ) { |
| 211 |
function srrl_settings_page() { |
| 212 |
if ( ! class_exists( 'Bws_Settings_Tabs' ) ) { |
| 213 |
require_once dirname( __FILE__ ) . '/bws_menu/class-bws-settings.php'; |
| 214 |
} |
| 215 |
require_once dirname( __FILE__ ) . '/includes/class-srrl-settings.php'; |
| 216 |
$page = new Srrl_Settings_Tabs( plugin_basename( __FILE__ ) ); |
| 217 |
if ( method_exists( $page, 'add_request_feature' ) ) { |
| 218 |
$page->add_request_feature(); |
| 219 |
} ?> |
| 220 |
<div class="wrap"> |
| 221 |
<h1 class="srrl-title"><?php esc_html_e( 'User Role Settings', 'user-role' ); ?></h1> |
| 222 |
<?php $page->display_content(); ?> |
| 223 |
</div> |
| 224 |
<?php |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Create backup-options |
| 230 |
* when we go to the plugin settings page |
| 231 |
* |
| 232 |
* @return void |
| 233 |
*/ |
| 234 |
if ( ! function_exists( 'srrl_create_backup' ) ) { |
| 235 |
function srrl_create_backup() { |
| 236 |
global $wpdb; |
| 237 |
$restore_option = get_option( 'srrl_backup_option_capabilities' ); |
| 238 |
$flag = false; |
| 239 |
if ( ! $restore_option ) { |
| 240 |
add_option( 'srrl_backup_option_capabilities', get_option( $wpdb->prefix . 'user_roles' ) ); |
| 241 |
} else { |
| 242 |
$roles = get_option( $wpdb->prefix . 'user_roles' ); |
| 243 |
foreach ( $roles as $key => $value ) { |
| 244 |
if ( ! array_key_exists( $key, $restore_option ) ) { |
| 245 |
$restore_option[ $key ] = $value; |
| 246 |
$flag = true; |
| 247 |
} |
| 248 |
} |
| 249 |
if ( $flag ) { |
| 250 |
update_option( 'srrl_backup_option_capabilities', $restore_option ); |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Display plugin roles page |
| 258 |
* |
| 259 |
* @return void |
| 260 |
*/ |
| 261 |
if ( ! function_exists( 'srrl_main_page' ) ) { |
| 262 |
function srrl_main_page() { |
| 263 |
?> |
| 264 |
<div class="wrap"> |
| 265 |
<h1> |
| 266 |
<?php |
| 267 |
esc_html_e( 'Roles', 'user-role' ); |
| 268 |
srrl_pro_block( 'srrl_add_new', 'srrl_add_new', false ); |
| 269 |
?> |
| 270 |
</h1> |
| 271 |
<?php |
| 272 |
require_once dirname( __FILE__ ) . '/includes/class-user-role.php'; |
| 273 |
|
| 274 |
/* create 'restore'-options */ |
| 275 |
srrl_create_backup(); |
| 276 |
|
| 277 |
$roles_list = new Srrl_Roles_List( plugin_basename( __FILE__ ) ); |
| 278 |
$roles_list->display_list(); |
| 279 |
?> |
| 280 |
</div> |
| 281 |
<?php |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Display plugin add new role page |
| 287 |
* |
| 288 |
* @return void |
| 289 |
*/ |
| 290 |
if ( ! function_exists( 'srrl_add_new_roles' ) ) { |
| 291 |
function srrl_add_new_roles() { |
| 292 |
global $title; |
| 293 |
?> |
| 294 |
<div class="wrap"> |
| 295 |
<h1><?php echo esc_html( $title ); ?></h1> |
| 296 |
<?php require_once dirname( __FILE__ ) . '/includes/edit-role-page.php'; ?> |
| 297 |
</div> |
| 298 |
<?php |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
/** |
| 303 |
* Add new or update an existing one role ( from "edit_role"-page ) |
| 304 |
* |
| 305 |
* @param string $name role display name |
| 306 |
* @param string $slug role name |
| 307 |
* @param array $caps allowed capabilities |
| 308 |
* @return array $result result of action |
| 309 |
*/ |
| 310 |
if ( ! function_exists( 'srrl_single_handle_role' ) ) { |
| 311 |
function srrl_single_handle_role( $name, $slug, $caps ) { |
| 312 |
global $wp_roles; |
| 313 |
$result = array( |
| 314 |
'error' => '', |
| 315 |
'message' => '', |
| 316 |
); |
| 317 |
if ( empty( $name ) ) { |
| 318 |
$result['error'][] = __( 'Please enter role name', 'user-role' ); |
| 319 |
} |
| 320 |
if ( empty( $slug ) ) { |
| 321 |
$result['error'][] = __( 'Please enter role slug', 'user-role' ); |
| 322 |
} |
| 323 |
if ( empty( $caps ) || ! is_array( $caps ) ) { |
| 324 |
$result['error'][] = __( 'Please select some capabilities for role', 'user-role' ); |
| 325 |
} |
| 326 |
if ( ! empty( $result['error'] ) ) { |
| 327 |
$result['error'] = implode( '.<br/>', $result['error'] ); |
| 328 |
} else { |
| 329 |
$slug = strtolower( trim( stripslashes( esc_html( $slug ) ) ) ); |
| 330 |
$name = trim( stripslashes( esc_html( $name ) ) ); |
| 331 |
if ( |
| 332 |
! preg_match( '/^[a-zA-Z0-9]+([-_\s]?[a-zA-Z0-9])*$/', $slug ) || /* not only latin, numbers, '-' or '_' */ |
| 333 |
preg_match( '/^([-_\s]*?)$/', $slug ) || /* only '-' or '_' */ |
| 334 |
is_numeric( $slug ) /* only numbers */ |
| 335 |
) { |
| 336 |
$result['error'] = __( 'Wrong slug. See allowed symbols', 'user-role' ); |
| 337 |
} else { |
| 338 |
if ( 0 === srrl_update_role( $slug, $name, $caps ) ) { |
| 339 |
$result['error'] = __( 'Some error occured', 'user-role' ); |
| 340 |
} else { |
| 341 |
$result['message'] = __( 'Role was successfully updated', 'user-role' ); |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
if ( method_exists( $wp_roles, 'for_site' ) ) { |
| 347 |
$wp_roles->for_site(); |
| 348 |
} else { |
| 349 |
$wp_roles->reinit(); |
| 350 |
} |
| 351 |
|
| 352 |
return $result; |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
/** |
| 357 |
* Getting capabilities of the selected role |
| 358 |
* |
| 359 |
* @return array $result result message and capabilities of the selected role |
| 360 |
*/ |
| 361 |
if ( ! function_exists( 'srrl_copy_role' ) ) { |
| 362 |
function srrl_copy_role() { |
| 363 |
$result = array( |
| 364 |
'error' => '', |
| 365 |
'message' => '', |
| 366 |
'caps' => array(), |
| 367 |
); |
| 368 |
if ( isset( $_REQUEST['srrl_select_role'] ) && '-1' !== sanitize_text_field( wp_unslash( $_REQUEST['srrl_select_role'] ) ) ) { |
| 369 |
global $wpdb; |
| 370 |
$prefix = $wpdb->get_blog_prefix(); |
| 371 |
$blog_roles = get_option( "{$prefix}user_roles" ); |
| 372 |
if ( empty( $blog_roles ) ) { |
| 373 |
$result['error'] = __( 'Can not get capabilities of the selected role', 'user-role' ); |
| 374 |
} else { |
| 375 |
if ( array_key_exists( sanitize_text_field( wp_unslash( $_REQUEST['srrl_select_role'] ) ), $blog_roles ) ) { |
| 376 |
$result['caps'] = $blog_roles[ sanitize_text_field( wp_unslash( $_REQUEST['srrl_select_role'] ) ) ]['capabilities']; |
| 377 |
$result['message'] = __( 'Capabilities were successfully loaded', 'user-role' ) . '. <a class="bws_save_anchor" href="#bws-submit-button">' . __( 'Save Changes', 'user-role' ) . '</a>'; |
| 378 |
} else { |
| 379 |
$result['error'] = __( 'Selected role is not exists. Capabilities not loaded', 'user-role' ); |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
return $result; |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
/** |
| 388 |
* Update of the role |
| 389 |
* |
| 390 |
* @return mixed an integer (1 or 0) or WP_Role object |
| 391 |
*/ |
| 392 |
if ( ! function_exists( 'srrl_update_role' ) ) { |
| 393 |
function srrl_update_role( $slug, $name, $caps ) { |
| 394 |
global $wpdb; |
| 395 |
$blog_roles = get_option( "{$wpdb->prefix}user_roles" ); |
| 396 |
if ( 'administrator' === $slug ) { |
| 397 |
$caps['activate_plugins'] = true; |
| 398 |
$caps['create_users'] = true; |
| 399 |
$caps['delete_plugins'] = true; |
| 400 |
$caps['delete_themes'] = true; |
| 401 |
$caps['delete_users'] = true; |
| 402 |
$caps['edit_files'] = true; |
| 403 |
$caps['edit_plugins'] = true; |
| 404 |
$caps['edit_theme_options'] = true; |
| 405 |
$caps['edit_themes'] = true; |
| 406 |
$caps['edit_users'] = true; |
| 407 |
$caps['export'] = true; |
| 408 |
$caps['import'] = true; |
| 409 |
$caps['install_plugins'] = true; |
| 410 |
$caps['install_themes'] = true; |
| 411 |
$caps['list_users'] = true; |
| 412 |
$caps['manage_options'] = true; |
| 413 |
$caps['promote_users'] = true; |
| 414 |
$caps['remove_users'] = true; |
| 415 |
$caps['switch_themes'] = true; |
| 416 |
$caps['update_core'] = true; |
| 417 |
$caps['update_plugins'] = true; |
| 418 |
$caps['update_themes'] = true; |
| 419 |
$caps['edit_dashboard'] = true; |
| 420 |
$caps['add_users'] = true; |
| 421 |
} |
| 422 |
if ( array_key_exists( $slug, $blog_roles ) ) { |
| 423 |
$blog_roles[ $slug ] = array( |
| 424 |
'name' => $name, |
| 425 |
'capabilities' => $caps, |
| 426 |
); |
| 427 |
update_option( "{$wpdb->prefix}user_roles", $blog_roles ); |
| 428 |
return 1; |
| 429 |
} else { |
| 430 |
return 0; |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
/** |
| 436 |
* Recovers or resets of capabilities |
| 437 |
* |
| 438 |
* @param array/string $slug_array roles slugs |
| 439 |
* @return void |
| 440 |
*/ |
| 441 |
if ( ! function_exists( 'srrl_recover_role' ) ) { |
| 442 |
function srrl_recover_role( $slug_array ) { |
| 443 |
global $wpdb; |
| 444 |
$result = array( |
| 445 |
'error' => '', |
| 446 |
'notice' => '', |
| 447 |
'message' => '', |
| 448 |
); |
| 449 |
$action_info = get_option( 'srrl_backup_option_capabilities' ); |
| 450 |
$slugs = array(); |
| 451 |
if ( empty( $action_info ) ) { |
| 452 |
$result['error'] = __( 'Can not recover selected roles', 'user-role' ); |
| 453 |
} else { |
| 454 |
$blog_roles = get_option( "{$wpdb->prefix}user_roles" ); |
| 455 |
foreach ( (array) $slug_array as $slug ) { |
| 456 |
if ( array_key_exists( $slug, $action_info ) ) { |
| 457 |
$blog_roles[ $slug ] = $action_info[ $slug ]; |
| 458 |
} else { |
| 459 |
$slugs[] = $slug; |
| 460 |
} |
| 461 |
} |
| 462 |
if ( empty( $slugs ) ) { |
| 463 |
$result['message'] = __( 'Selected roles were recovered successfully', 'user-role' ); |
| 464 |
} else { |
| 465 |
$result['error'] = __( 'Can not recover next roles', 'user-role' ) . ':<br />' . implode( ',<br/>', $slugs ); |
| 466 |
} |
| 467 |
update_option( "{$wpdb->prefix}user_roles", $blog_roles ); |
| 468 |
} |
| 469 |
return $result; |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
/** |
| 474 |
* Forming html-structure of metabox on Add/ Edit role page |
| 475 |
* |
| 476 |
* @param object $post WP_Post object |
| 477 |
* @param array $metabox parameters, which was passed thru add_meta_box() action |
| 478 |
* @return void |
| 479 |
*/ |
| 480 |
if ( ! function_exists( 'srrl_metabox_content' ) ) { |
| 481 |
function srrl_metabox_content( $post, $metabox ) { |
| 482 |
$slug = isset( $_REQUEST['srrl_slug'] ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['srrl_slug'] ) ) ) : ''; |
| 483 |
$slug = empty( $slug ) && isset( $_REQUEST['srrl_role_slug'] ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['srrl_role_slug'] ) ) ) : $slug; |
| 484 |
$admin_capabilities = |
| 485 |
'administrator' === $slug |
| 486 |
? |
| 487 |
array( |
| 488 |
'activate_plugins', |
| 489 |
'create_users', |
| 490 |
'delete_plugins', |
| 491 |
'delete_themes', |
| 492 |
'delete_users', |
| 493 |
'edit_files', |
| 494 |
'edit_plugins', |
| 495 |
'edit_theme_options', |
| 496 |
'edit_themes', |
| 497 |
'edit_users', |
| 498 |
'export', |
| 499 |
'import', |
| 500 |
'install_plugins', |
| 501 |
'install_themes', |
| 502 |
'list_users', |
| 503 |
'manage_options', |
| 504 |
'promote_users', |
| 505 |
'remove_users', |
| 506 |
'switch_themes', |
| 507 |
'update_core', |
| 508 |
'update_plugins', |
| 509 |
'update_themes', |
| 510 |
'edit_dashboard', |
| 511 |
'add_users', |
| 512 |
) |
| 513 |
: |
| 514 |
array(); |
| 515 |
foreach ( $metabox['args'][0] as $key => $value ) { |
| 516 |
$checked = ( array_key_exists( $value, $metabox['args'][1] ) ) ? ' checked="checked"' : ''; |
| 517 |
$readonly = in_array( $value, $admin_capabilities ) ? ' disabled="disabled"' : ''; |
| 518 |
echo '<label class="srrl_label_cap" for="srrl_' . esc_attr( $value ) . '"><input class="srrl_check_cap ' . esc_attr( $metabox['args'][2] ) . '" type="checkbox" name="srrl_role_caps[]" id="srrl_' . esc_attr( $value ) . '" value="' . esc_attr( $value ) . '"' . esc_html( $checked ) . esc_html( $readonly ) . ' />' . esc_attr( $value ) . '</label>'; |
| 519 |
} |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
/** |
| 524 |
* Display list of Blogs |
| 525 |
* |
| 526 |
* @param object $post WP_Post object |
| 527 |
* @param array $metabox parameters, which was passed thru add_meta_box() action |
| 528 |
* @return void |
| 529 |
*/ |
| 530 |
if ( ! function_exists( 'srrl_list_of_blogs' ) ) { |
| 531 |
function srrl_list_of_blogs( $post, $metabox ) { |
| 532 |
echo esc_attr( $metabox['args'][0] ); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
/* Action_links */ |
| 537 |
if ( ! function_exists( 'srrl_plugin_action_links' ) ) { |
| 538 |
function srrl_plugin_action_links( $links, $file ) { |
| 539 |
static $this_plugin; |
| 540 |
if ( ! $this_plugin ) { |
| 541 |
$this_plugin = plugin_basename( __FILE__ ); |
| 542 |
} |
| 543 |
if ( $file === $this_plugin ) { |
| 544 |
$settings_link = '<a href="admin.php?page=srrl_settings">' . __( 'Settings', 'user-role' ) . '</a>'; |
| 545 |
array_unshift( $links, $settings_link ); |
| 546 |
} |
| 547 |
return $links; |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
if ( ! function_exists( 'srrl_plugin_banner' ) ) { |
| 552 |
function srrl_plugin_banner() { |
| 553 |
global $hook_suffix, $srrl_plugin_info; |
| 554 |
|
| 555 |
if ( 'plugins.php' === $hook_suffix ) { |
| 556 |
bws_plugin_banner_to_settings( $srrl_plugin_info, 'srrl_options', 'user-role', 'admin.php?page=srrl_settings' ); |
| 557 |
} |
| 558 |
|
| 559 |
if ( isset( $_GET['page'] ) && 'user-role.php' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) { |
| 560 |
bws_plugin_suggest_feature_banner( $srrl_plugin_info, 'srrl_options', 'user-role' ); |
| 561 |
} |
| 562 |
} |
| 563 |
} |
| 564 |
|
| 565 |
if ( ! function_exists( 'srrl_register_plugin_links' ) ) { |
| 566 |
function srrl_register_plugin_links( $links, $file ) { |
| 567 |
$base = plugin_basename( __FILE__ ); |
| 568 |
if ( $file === $base ) { |
| 569 |
$links[] = '<a href="admin.php?page=srrl_settings">' . __( 'Settings', 'user-role' ) . '</a>'; |
| 570 |
$links[] = '<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538799" target="_blank">' . __( 'FAQ', 'user-role' ) . '</a>'; |
| 571 |
$links[] = '<a href="https://support.bestwebsoft.com">' . __( 'Support', 'user-role' ) . '</a>'; |
| 572 |
} |
| 573 |
return $links; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
/** |
| 578 |
* Add help tab on settings page |
| 579 |
* |
| 580 |
* @return void |
| 581 |
*/ |
| 582 |
if ( ! function_exists( 'srrl_add_tabs' ) ) { |
| 583 |
function srrl_add_tabs() { |
| 584 |
$args = array( |
| 585 |
'id' => 'srrl', |
| 586 |
'section' => '200538799', |
| 587 |
); |
| 588 |
bws_help_tab( get_current_screen(), $args ); |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
/** |
| 593 |
* Show ads for PRO |
| 594 |
* |
| 595 |
* @return void |
| 596 |
*/ |
| 597 |
if ( ! function_exists( 'srrl_pro_block' ) ) { |
| 598 |
function srrl_pro_block( $func, $class = '', $show_cross = true, $show_link = true ) { |
| 599 |
global $srrl_plugin_info, $wp_version, $srrl_options; |
| 600 |
if ( ! bws_hide_premium_options_check( $srrl_options ) ) { |
| 601 |
?> |
| 602 |
<div class="bws_pro_version_bloc <?php echo esc_attr( $class ); ?>"> |
| 603 |
<div class="bws_pro_version_table_bloc"> |
| 604 |
<?php if ( $show_cross ) { ?> |
| 605 |
<button type="submit" name="bws_hide_premium_options" class="notice-dismiss bws_hide_premium_options" title="<?php esc_html_e( 'Close', 'user-role' ); ?>"></button> |
| 606 |
<?php } ?> |
| 607 |
<div class="bws_table_bg"></div> |
| 608 |
<?php call_user_func( $func ); ?> |
| 609 |
</div> |
| 610 |
<?php if ( $show_link ) { ?> |
| 611 |
<div class="bws_pro_version_tooltip"> |
| 612 |
<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/user-role/?k=0e8fa1e4abf7647412878a5570d4977a&pn=132&v=<?php echo esc_attr( $srrl_plugin_info['Version'] ); ?>&wp_v=<?php echo esc_attr( $wp_version ); ?>" target="_blank" title="User Role Pro Plugin"><?php esc_html_e( 'Upgrade to Pro', 'user-role' ); ?></a> |
| 613 |
<div class="clear"></div> |
| 614 |
</div> |
| 615 |
<?php } ?> |
| 616 |
</div> |
| 617 |
<?php |
| 618 |
} |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
if ( ! function_exists( 'srrl_blog_switcher' ) ) { |
| 623 |
function srrl_blog_switcher() { |
| 624 |
?> |
| 625 |
<div class="srrl_blog_switcher bws_pro_version"> |
| 626 |
<select name="srrl_blog_id" disabled="disabled"> |
| 627 |
<option value="off"><?php echo esc_html( get_bloginfo() ) . ' (' . esc_url( parse_url( get_bloginfo( 'url' ), PHP_URL_HOST ) ) . ')'; ?></option> |
| 628 |
</select> |
| 629 |
<input type="submit" class="button-primary" name="srrl_switch_to_blog" value="<?php esc_html_e( 'Switch to Blog', 'user-role' ); ?>" disabled="disabled" /> |
| 630 |
</div> |
| 631 |
<?php |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
if ( ! function_exists( 'srrl_blog_list' ) ) { |
| 636 |
function srrl_blog_list() { |
| 637 |
?> |
| 638 |
<div class="metabox-holder srrl_metabox"> |
| 639 |
<table class="form-table"><tr><th><?php esc_html_e( 'Allow for blogs', 'user-role' ); ?></th></tr></table> |
| 640 |
<?php do_meta_boxes( 'user-role-blog.php', 'normal', null ); ?> |
| 641 |
</div> |
| 642 |
<?php |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
if ( ! function_exists( 'srrl_menu_list' ) ) { |
| 647 |
function srrl_menu_list() { |
| 648 |
global $menu; |
| 649 |
?> |
| 650 |
<div id="postbox-menu" class="postbox"> |
| 651 |
<h2 class="hndle" style="position: unset;"><span><label class="srrl_group_label"><input class="hide-if-no-js srrl_group_cap" id="srrl_menu_checkbox" type="checkbox" value="srrl_plugins"><?php esc_html_e( 'Access to plugins (menu items)', 'user-role' ); ?></label></span></h2> |
| 652 |
<div class="inside"> |
| 653 |
<?php |
| 654 |
$menu_array = $menu; |
| 655 |
foreach ( $menu_array as $single_menu ) { |
| 656 |
if ( '' === $single_menu[0] ) { |
| 657 |
continue; |
| 658 |
} |
| 659 |
if ( strpos( $single_menu[0], ' <' ) ) { |
| 660 |
$single_menu[0] = substr( $single_menu[0], 0, strpos( $single_menu[0], ' <' ) ); |
| 661 |
} |
| 662 |
?> |
| 663 |
<label class="srrl_label_cap" ><input class="srrl_check_cap srrl_menus" type="checkbox" name="" value="0"><?php echo esc_attr( $single_menu[0] ); ?></label> |
| 664 |
<?php } ?> |
| 665 |
</div> |
| 666 |
</div> |
| 667 |
<?php |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
if ( ! function_exists( 'srrl_select' ) ) { |
| 672 |
function srrl_select() { |
| 673 |
?> |
| 674 |
<div class="bws_pro_version"> |
| 675 |
<select name="srrl_select" disabled="disabled"> |
| 676 |
<option value="-1"><?php esc_html_e( 'Select blog', 'user-role' ); ?> </option> |
| 677 |
</select> |
| 678 |
</div> |
| 679 |
<?php |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
if ( ! function_exists( 'srrl_add_new' ) ) { |
| 684 |
function srrl_add_new() { |
| 685 |
?> |
| 686 |
<div class="bws_pro_version"> |
| 687 |
<button class="button-primary" disabled="disabled"><?php esc_html_e( 'Add New', 'user-role' ); ?></button> |
| 688 |
</div> |
| 689 |
<?php |
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
/* Plugin delete options */ |
| 694 |
if ( ! function_exists( 'srrl_delete_options' ) ) { |
| 695 |
function srrl_delete_options() { |
| 696 |
/* recover all options on every blog to the ones in the backup */ |
| 697 |
global $wpdb; |
| 698 |
|
| 699 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 700 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 701 |
} |
| 702 |
|
| 703 |
$all_plugins = get_plugins(); |
| 704 |
|
| 705 |
if ( ! array_key_exists( 'user-role-pro/user-role-pro.php', $all_plugins ) ) { |
| 706 |
if ( is_multisite() ) { |
| 707 |
$all_blogs = $wpdb->get_col( 'SELECT `blog_id` FROM `' . $wpdb->prefix . 'blogs`' ); |
| 708 |
foreach ( $all_blogs as $blog_id ) { |
| 709 |
$srrl_repair_roles = get_blog_option( $blog_id, 'srrl_backup_option_capabilities' ); |
| 710 |
if ( is_array( $srrl_repair_roles ) && ! empty( $srrl_repair_roles ) ) { |
| 711 |
update_blog_option( $blog_id, $wpdb->get_blog_prefix( $blog_id ) . 'user_roles', $srrl_repair_roles ); |
| 712 |
} |
| 713 |
delete_blog_option( $blog_id, 'srrl_backup_option_capabilities' ); |
| 714 |
delete_blog_option( $blog_id, 'srrl_options' ); |
| 715 |
} |
| 716 |
delete_site_option( 'srrl_options' ); |
| 717 |
} else { |
| 718 |
$srrl_repair_roles = get_option( 'srrl_backup_option_capabilities' ); |
| 719 |
if ( is_array( $srrl_repair_roles ) && ! empty( $srrl_repair_roles ) ) { |
| 720 |
update_option( $wpdb->prefix . 'user_roles', $srrl_repair_roles ); |
| 721 |
} |
| 722 |
delete_option( 'srrl_backup_option_capabilities' ); |
| 723 |
delete_option( 'srrl_options' ); |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
require_once dirname( __FILE__ ) . '/bws_menu/bws_include.php'; |
| 728 |
bws_include_init( plugin_basename( __FILE__ ) ); |
| 729 |
bws_delete_plugin( plugin_basename( __FILE__ ) ); |
| 730 |
} |
| 731 |
} |
| 732 |
|
| 733 |
register_activation_hook( __FILE__, 'srrl_plugin_activate' ); |
| 734 |
|
| 735 |
add_action( 'admin_menu', 'srrl_add_pages' ); |
| 736 |
add_action( 'network_admin_menu', 'srrl_add_pages' ); |
| 737 |
add_action( 'plugins_loaded', 'srrl_plugins_loaded' ); |
| 738 |
add_action( 'init', 'srrl_init' ); |
| 739 |
add_action( 'admin_init', 'srrl_admin_init' ); |
| 740 |
/* Calling a function add administrative menu. */ |
| 741 |
add_action( 'admin_enqueue_scripts', 'srrl_admin_head' ); |
| 742 |
/* Additional links on the plugin page */ |
| 743 |
add_filter( 'plugin_action_links', 'srrl_plugin_action_links', 10, 2 ); |
| 744 |
add_filter( 'plugin_row_meta', 'srrl_register_plugin_links', 10, 2 ); |
| 745 |
/* add notice about plugin license timeout */ |
| 746 |
add_action( 'admin_notices', 'srrl_plugin_banner' ); |
| 747 |
|