I’d add a meta key and value to each user first and then add meta_key
and meta_value
to the get_users argument array.
Your meta key could for example be called showme
and value would be "yes"
. So wherever an author has a meta value of "no"
, get_users()
would exclude that author.
Add this code to your functions.php:
<?php // you might not need this line when pasting into functions.php
add_action( 'show_user_profile', 'so_show_extra_radios' );
add_action( 'edit_user_profile', 'so_show_extra_radios' );
function so_show_extra_radios( $user ) { ?>
<table class="form-table">
<tr>
<th>
<label for="showme">Show profile</label>
</th>
<td>
<input type="radio" name="showme" value="yes" <?php
if (esc_attr(get_the_author_meta('showme', $user->ID)) == "yes")
echo "checked";
?>></input> Yes<br>
<input type="radio" name="showme" value="no" <?php
if (esc_attr(get_the_author_meta('showme', $user->ID)) == "no")
echo "checked";
?>></input>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'so_save_profile' );
add_action( 'edit_user_profile_update', 'so_save_profile' );
function so_save_profile( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) return false;
if (wp_kses_post( $_POST['showme'] ) == 'yes')
update_usermeta( absint( $user_id ), 'showme', "yes" );
else
update_usermeta( absint( $user_id ), 'showme', "no" );
}
Then add your meta_key
and meta_value
arguments in your author.php (or wherever you retrieve your author profiles) as described here.