Is there a way to hide user profiles in the front end, while still allowing their information to be accessible in the backend?
Something similar to setting posts or pages to "draft" but for users would function perfectly. Is there a way to do this?
The database table for users holds the user_status
as integer:
$users_single_table = "CREATE TABLE $wpdb->users (
ID bigint(20) unsigned NOT NULL auto_increment,
user_login varchar(60) NOT NULL default '',
user_pass varchar(255) NOT NULL default '',
user_nicename varchar(50) NOT NULL default '',
user_email varchar(100) NOT NULL default '',
user_url varchar(100) NOT NULL default '',
user_registered datetime NOT NULL default '0000-00-00 00:00:00',
user_activation_key varchar(255) NOT NULL default '',
user_status int(11) NOT NULL default '0',
display_name varchar(250) NOT NULL default '',
PRIMARY KEY (ID),
KEY user_login_key (user_login),
KEY user_nicename (user_nicename),
KEY user_email (user_email)
) $charset_collate;\n";
The WP_Users
class at the moment doesn't have anything that would alter the state property, nor even hold that property.
There is one function inside wp-admin/includes/ms.php
that may show you the path how to go.
update_user_status( $user_id, 'spam', '1' );
but loads only for multisite:
/wp-admin/includes/admin.php:
82 if ( is_multisite() ) {
83 require_once(ABSPATH . 'wp-admin/includes/ms-admin-filters.php');
84: require_once(ABSPATH . 'wp-admin/includes/ms.php');
85 require_once(ABSPATH . 'wp-admin/includes/ms-deprecated.php');
86 }
It looks like this:
function update_user_status( $id, $pref, $value, $deprecated = null ) {
global $wpdb;
if ( null !== $deprecated )
_deprecated_argument( __FUNCTION__, '3.0.2' );
$wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
$user = new WP_User( $id );
clean_user_cache( $user );
if ( $pref == 'spam' ) {
if ( $value == 1 ) {
/**
* Fires after the user is marked as a SPAM user.
*
* @since 3.0.0
*
* @param int $id ID of the user marked as SPAM.
*/
do_action( 'make_spam_user', $id );
} else {
/**
* Fires after the user is marked as a HAM user. Opposite of SPAM.
*
* @since 3.0.0
*
* @param int $id ID of the user marked as HAM.
*/
do_action( 'make_ham_user', $id );
}
}
return $value;
}
You could use something similar and create the action hook make_draft_user
, probable in your function _20161214_update_user_status( $user_id, 'draft', '1' );
Inside your very own make_draft_user
hook you could define what to do.
So WordPress out of the box doesn't provide draft users. Maybe it will one day with the clear use case scenario. Maybe the status will be a string, and not the int (This is the case for posts).
user_status
insideusers
table so technically yes.