Hot answers tagged

4

You're wanting to hide a user from WordPress in three places: The user list in the admin The count above that user list The user's author archive on the front-end As you mentioned, you've already solved item 1 and you've included the code for that. So, I'll provide the solutions for items 2 and 3. The user you want to hide is an administrator with a ...


3

I have just made this code you can try out: add_filter( 'the_content', 'restrict_access' ); function restrict_access( $content ) { $user_info = wp_get_current_user(); // Get logged in user info $registered = $user_info->user_registered; if( !is_user_logged_in() ) { $content = __( "You are not logged in.", 'your_textdomain' ); ...


3

As an alternative to my other answer, you can also use the get_avatar filter. Props to Sumit to alerting me to this one. The benefit of using the get_avatar filter is your custom avatar should be applied anywhere Wordpress uses it, rather than just in this users list like my other answer deals with. If you use plugins that display user avatars, this ...


3

You can use register_new_user hook which is the last hook before WordPress perform the redirect to check your email page. In the callback function you will get user ID, using it get the user data and check if user belongs to specific role. Example:- function wpse_228545_register_redirect( $user_id ) { $user_data = get_userdata($user_id); //Get the ...


2

the_permalink(), the_title() by default echo their value. As you want to store that value in a variable you will need to return the values instead. get_the_permalink(), get_the_title() are two similar functions that return the value instead of echo. So you new code may look something like this: $list = '<li class="ubermenu-submenu ubermenu-submenu-id-...


2

By default, WordPress uses $wp_object_cache which is an instance of WP_Object_Cache to save on trips to the database. Trace back username_exists() function, you will notice that get_user_by() uses WP_User::get_data_by() which return user data from $wp_object_cache immediately without checking if that user exists in database. Note that $wp_object_cache is ...


2

We could also use one of the following filters, available since WordPress 4.2: pre_get_avatar_data get_avatar_url get_avatar_data Regarding how to get the user ID from the $id_or_email we can see how it's done in the core: $email_hash = ''; $user = $email = false; if ( is_object( $id_or_email ) && isset( $id_or_email->comment_ID ) ) { $...


2

Yes, this is really very basic. If you are the admin, you can create new users and asign them a role. You could make your friend 'author', which would allow him to write and edit his own posts only, or make him an 'editor' if you also want him to edit other people's post.


1

You can use the user_register hook and then mail all your subscribers. Something like: add_action('user_register','notify_new_member'); function notify_new_member(){ global $wpdb; $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;"); $users = implode(",", $usersarray); mail($users, "New Member", 'A new member has just ...


1

EDIT: My original solution is below, but Sumit alerted me in the comments to the existence of the get_avatar filter. I've posted an additional answer that shows how to implement that option as well. Yes, you can do this. The columns displayed in any of these 'list tables' in Wordpress admin are filterable - so using a custom function in your theme's ...


1

Caching can be anywhere, starting with request caching on mysql components side (unlikely to impact in this case), and object caching on wordpress side. You are probably doing something wrong in your code, but it is always better to use the API (or wordpress admin as a front end to it) to delete things then to try to delete them by directly accessing the DB....


1

The obvious method would be to write a custom WP-CLI script to run through the table, extract the first and last names, use sanitize_title to create a new nicename and update the record. You'd also need to copy the first and last names in wp_usermeta as you mention, at the same time. I'm not sure I'm telling you anything you don't already know here.


1

I don't see anywhere in your code that the query is being modified. Just flagging a column to be sortable doesn't mean it knows how to sort the data - it will just add the little up/down arrow and make the column clickable but you have to intercept the query var accordingly and tell WP what to do. You'll want to hook into pre_get_users and modify the query ...



Only top voted, non community-wiki answers of a minimum length are eligible