Merged in feature/117-dev-dev01 (pull request #8)
auto-patch 117-dev-dev01-2023-12-15T16_09_06 * auto-patch 117-dev-dev01-2023-12-15T16_09_06
This commit is contained in:
@@ -72,7 +72,7 @@ class Yoast_Notification {
|
||||
private $defaults = [
|
||||
'type' => self::UPDATED,
|
||||
'id' => '',
|
||||
'user' => null,
|
||||
'user_id' => null,
|
||||
'nonce' => null,
|
||||
'priority' => 0.5,
|
||||
'data_json' => [],
|
||||
@@ -112,10 +112,14 @@ class Yoast_Notification {
|
||||
/**
|
||||
* Retrieve the user to show the notification for.
|
||||
*
|
||||
* @deprecated 21.6
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @return WP_User The user to show this notification for.
|
||||
*/
|
||||
public function get_user() {
|
||||
return $this->options['user'];
|
||||
\_deprecated_function( __METHOD__, 'Yoast SEO 21.6' );
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,10 +130,7 @@ class Yoast_Notification {
|
||||
* @return int The user id
|
||||
*/
|
||||
public function get_user_id() {
|
||||
if ( $this->get_user() !== null ) {
|
||||
return $this->get_user()->ID;
|
||||
}
|
||||
return get_current_user_id();
|
||||
return ( $this->options['user_id'] ?? get_current_user_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +221,7 @@ class Yoast_Notification {
|
||||
*/
|
||||
public function match_capabilities() {
|
||||
// Super Admin can do anything.
|
||||
if ( is_multisite() && is_super_admin( $this->options['user']->ID ) ) {
|
||||
if ( is_multisite() && is_super_admin( $this->options['user_id'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -280,7 +281,15 @@ class Yoast_Notification {
|
||||
* @return bool
|
||||
*/
|
||||
private function has_capability( $capability ) {
|
||||
$user = $this->options['user'];
|
||||
$user_id = $this->options['user_id'];
|
||||
if ( ! is_numeric( $user_id ) ) {
|
||||
return false;
|
||||
}
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
if ( ! $user ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $user->has_cap( $capability );
|
||||
}
|
||||
|
||||
@@ -396,9 +405,9 @@ class Yoast_Notification {
|
||||
$options['capabilities'] = [ 'wpseo_manage_options' ];
|
||||
}
|
||||
|
||||
// Set to the current user if not supplied.
|
||||
if ( $options['user'] === null ) {
|
||||
$options['user'] = wp_get_current_user();
|
||||
// Set to the id of the current user if not supplied.
|
||||
if ( $options['user_id'] === null ) {
|
||||
$options['user_id'] = get_current_user_id();
|
||||
}
|
||||
|
||||
return $options;
|
||||
|
||||
Reference in New Issue
Block a user