Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/helpers
File: capability-helper.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Helpers;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* A helper object for user capabilities.
[5] Fix | Delete
*/
[6] Fix | Delete
class Capability_Helper {
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Checks if the user has at least one of the proper capabilities.
[10] Fix | Delete
*
[11] Fix | Delete
* @param string $capability Capability to check.
[12] Fix | Delete
*
[13] Fix | Delete
* @return bool True if the user has at least one of the proper rights.
[14] Fix | Delete
*/
[15] Fix | Delete
public function current_user_can( $capability ) {
[16] Fix | Delete
if ( $capability === 'wpseo_manage_options' ) {
[17] Fix | Delete
return \current_user_can( $capability );
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
return $this->has_any( [ 'wpseo_manage_options', $capability ] );
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* Retrieves the users that have the specified capability.
[25] Fix | Delete
*
[26] Fix | Delete
* @param string $capability The name of the capability.
[27] Fix | Delete
*
[28] Fix | Delete
* @return array The users that have the capability.
[29] Fix | Delete
*/
[30] Fix | Delete
public function get_applicable_users( $capability ) {
[31] Fix | Delete
$applicable_roles = $this->get_applicable_roles( $capability );
[32] Fix | Delete
[33] Fix | Delete
if ( $applicable_roles === [] ) {
[34] Fix | Delete
return [];
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
return \get_users( [ 'role__in' => $applicable_roles ] );
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Retrieves the roles that have the specified capability.
[42] Fix | Delete
*
[43] Fix | Delete
* @param string $capability The name of the capability.
[44] Fix | Delete
*
[45] Fix | Delete
* @return array The names of the roles that have the capability.
[46] Fix | Delete
*/
[47] Fix | Delete
public function get_applicable_roles( $capability ) {
[48] Fix | Delete
$roles = \wp_roles();
[49] Fix | Delete
$role_names = $roles->get_names();
[50] Fix | Delete
[51] Fix | Delete
$applicable_roles = [];
[52] Fix | Delete
foreach ( \array_keys( $role_names ) as $role_name ) {
[53] Fix | Delete
$role = $roles->get_role( $role_name );
[54] Fix | Delete
[55] Fix | Delete
if ( ! $role ) {
[56] Fix | Delete
continue;
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
// Add role if it has the capability.
[60] Fix | Delete
if ( \array_key_exists( $capability, $role->capabilities ) && $role->capabilities[ $capability ] === true ) {
[61] Fix | Delete
$applicable_roles[] = $role_name;
[62] Fix | Delete
}
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
return $applicable_roles;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Checks if the current user has at least one of the supplied capabilities.
[70] Fix | Delete
*
[71] Fix | Delete
* @param array $capabilities Capabilities to check against.
[72] Fix | Delete
*
[73] Fix | Delete
* @return bool True if the user has at least one capability.
[74] Fix | Delete
*/
[75] Fix | Delete
private function has_any( array $capabilities ) {
[76] Fix | Delete
foreach ( $capabilities as $capability ) {
[77] Fix | Delete
if ( \current_user_can( $capability ) ) {
[78] Fix | Delete
return true;
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
return false;
[83] Fix | Delete
}
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function