: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Abstract for user model
* @copyright Copyright (c) 2023, Code Atlantic LLC
if ( ! defined( 'ABSPATH' ) ) {
* Core class used to implement the custom WP_User object.
* @property string $nickname
* @property string $description
* @property string $user_description
* @property string $first_name
* @property string $user_firstname
* @property string $last_name
* @property string $user_lastname
* @property string $user_login
* @property string $user_pass
* @property string $user_nicename
* @property string $user_email
* @property string $user_url
* @property string $user_registered
* @property string $user_activation_key
* @property string $user_status
* @property int $user_level
* @property string $display_name
* @property string $deleted
* @property string $locale
abstract class PUM_Abstract_Model_User {
* The current model version.
* Used for compatibility testing.
public $model_version = 1;
* The version of the data currently stored for the current item.
* @var array An array of keys that can be accessed via the $this->user (WP_User) object.
public $core_data_keys = [
* The required permission|user_role|capability|user_level of the user.
protected $required_permission = '';
* @param WP_User|int $user
public function __construct( $user ) {
if ( ! is_a( $user, 'WP_User' ) ) {
$user = new WP_User( $user );
* Given the user data, let's set the variables
* @param WP_User $user The User Object
protected function setup( $user ) {
if ( ! is_a( $user, 'WP_User' ) || ( $this->required_permission && ! $user->has_cap( $this->required_permission ) ) ) {
if ( ! isset( $user->data->ID ) ) {
// Set $this->ID based on the users ID.
public function __isset( $key ) {
if ( in_array( $key, $this->core_data_keys ) ) {
return isset( $this->user->$key );
public function __unset( $key ) {
if ( in_array( $key, $this->core_data_keys ) ) {
unset( $this->user->$key );
* Magic __get function to dispatch a call to retrieve a private property
public function __get( $key ) {
if ( in_array( $key, $this->core_data_keys ) ) {
return $this->user->$key;
} elseif ( method_exists( $this, 'get_' . $key ) ) {
return call_user_func( [ $this, 'get_' . $key ] );
$meta = get_user_meta( $this->ID, $key, true );
return new WP_Error( 'user-invalid-property', sprintf( __( 'Can\'t get property %s' ), $key ) );
public function __call( $name, $arguments ) {
if ( method_exists( $this->user, $name ) ) {
return call_user_func_array( [ $this->user, $name ], $arguments );
* Get per site or global user options.
public function get_option( $key ) {
return get_user_option( $key, $this->ID );
* Used to set per site or global user options.
public function update_option( $key, $value, $global = false ) {
return update_user_option( $this->ID, $key, $value, $global );
* Used to delete per site or global user options.
public function delete_option( $key, $global = false ) {
return delete_user_option( $this->ID, $key, $global );
public function get_meta( $key, $single = true ) {
return get_user_meta( $this->ID, $key, $single );
public function add_meta( $key, $value, $unique = false ) {
return add_user_meta( $this->ID, $key, $value, $unique );
public function update_meta( $key, $value ) {
return update_user_meta( $this->ID, $key, $value );
public function delete_meta( $key, $value = '' ) {
return delete_user_meta( $this->ID, $key, $value );
public function get_avatar( $size = 35 ) {
return get_avatar( $this->ID, $size );
* Convert object to array.
* @return array Object as array.
public function to_array() {
$user = $this->user->to_array();
foreach ( get_object_vars( $this ) as $k => $v ) {