Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordpres.../admin/capabili...
File: class-register-capabilities.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin\Capabilities
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Capabilities registration class.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Register_Capabilities implements WPSEO_WordPress_Integration {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Registers the hooks.
[13] Fix | Delete
*
[14] Fix | Delete
* @return void
[15] Fix | Delete
*/
[16] Fix | Delete
public function register_hooks() {
[17] Fix | Delete
add_action( 'wpseo_register_capabilities', [ $this, 'register' ] );
[18] Fix | Delete
[19] Fix | Delete
if ( is_multisite() ) {
[20] Fix | Delete
add_action( 'user_has_cap', [ $this, 'filter_user_has_wpseo_manage_options_cap' ], 10, 4 );
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Maybe add manage_privacy_options capability for wpseo_manager user role.
[25] Fix | Delete
*/
[26] Fix | Delete
add_filter( 'map_meta_cap', [ $this, 'map_meta_cap_for_seo_manager' ], 10, 2 );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* Registers the capabilities.
[31] Fix | Delete
*
[32] Fix | Delete
* @return void
[33] Fix | Delete
*/
[34] Fix | Delete
public function register() {
[35] Fix | Delete
$manager = WPSEO_Capability_Manager_Factory::get();
[36] Fix | Delete
[37] Fix | Delete
$manager->register( 'wpseo_bulk_edit', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
[38] Fix | Delete
$manager->register( 'wpseo_edit_advanced_metadata', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
[39] Fix | Delete
[40] Fix | Delete
$manager->register( 'wpseo_manage_options', [ 'administrator', 'wpseo_manager' ] );
[41] Fix | Delete
$manager->register( 'view_site_health_checks', [ 'wpseo_manager' ] );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Revokes the 'wpseo_manage_options' capability from administrator users if it should
[46] Fix | Delete
* only be granted to network administrators.
[47] Fix | Delete
*
[48] Fix | Delete
* @param array $allcaps An array of all the user's capabilities.
[49] Fix | Delete
* @param array $caps Actual capabilities being checked.
[50] Fix | Delete
* @param array $args Optional parameters passed to has_cap(), typically object ID.
[51] Fix | Delete
* @param WP_User $user The user object.
[52] Fix | Delete
*
[53] Fix | Delete
* @return array Possibly modified array of the user's capabilities.
[54] Fix | Delete
*/
[55] Fix | Delete
public function filter_user_has_wpseo_manage_options_cap( $allcaps, $caps, $args, $user ) {
[56] Fix | Delete
[57] Fix | Delete
// We only need to do something if 'wpseo_manage_options' is being checked.
[58] Fix | Delete
if ( ! in_array( 'wpseo_manage_options', $caps, true ) ) {
[59] Fix | Delete
return $allcaps;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
// If the user does not have 'wpseo_manage_options' anyway, we don't need to revoke access.
[63] Fix | Delete
if ( empty( $allcaps['wpseo_manage_options'] ) ) {
[64] Fix | Delete
return $allcaps;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
// If the user does not have 'delete_users', they are not an administrator.
[68] Fix | Delete
if ( empty( $allcaps['delete_users'] ) ) {
[69] Fix | Delete
return $allcaps;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$options = WPSEO_Options::get_instance();
[73] Fix | Delete
[74] Fix | Delete
if ( $options->get( 'access' ) === 'superadmin' && ! is_super_admin( $user->ID ) ) {
[75] Fix | Delete
unset( $allcaps['wpseo_manage_options'] );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
return $allcaps;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Maybe add manage_privacy_options capability for wpseo_manager user role.
[83] Fix | Delete
*
[84] Fix | Delete
* @param string[] $caps Primitive capabilities required of the user.
[85] Fix | Delete
* @param string[] $cap Capability being checked.
[86] Fix | Delete
*
[87] Fix | Delete
* @return string[] Filtered primitive capabilities required of the user.
[88] Fix | Delete
*/
[89] Fix | Delete
public function map_meta_cap_for_seo_manager( $caps, $cap ) {
[90] Fix | Delete
$user = wp_get_current_user();
[91] Fix | Delete
[92] Fix | Delete
// No multisite support.
[93] Fix | Delete
if ( is_multisite() ) {
[94] Fix | Delete
return $caps;
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
// User must be of role wpseo_manager.
[98] Fix | Delete
if ( ! in_array( 'wpseo_manager', $user->roles, true ) ) {
[99] Fix | Delete
return $caps;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
// Remove manage_options cap requirement if requested cap is manage_privacy_options.
[103] Fix | Delete
if ( $cap === 'manage_privacy_options' ) {
[104] Fix | Delete
return array_diff( $caps, [ 'manage_options' ] );
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
return $caps;
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function