5

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?

  • 3
    there is user_status inside users table so technically yes. – prosti Dec 13 '16 at 13:14
  • What should user_status be set to? 0 is active 1 is spam i noticed. Is there a draft value? – NNCCBB Dec 14 '16 at 10:58
  • You mean for draft? I am not aware this is defined anywhere int the help docs, up to you. – prosti Dec 14 '16 at 11:02
2

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.

enter image description here

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).

| improve this answer | |
  • Hmm ok before i go programming new functions what would happen if i changed the user_status? what would the different numbers mean? 0 1 2? – NNCCBB Dec 14 '16 at 10:18
  • There is no table with special meaning for these numbers anywhere in the documentation. Sorry. At least I could not find anything. You may probably any number other than 0, which is set by default. I guess you may try 1000. – prosti Dec 14 '16 at 10:29
0

Setting user_status to 2 in the database appears to do the trick

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.