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


-1

I found out what was causing this problem. I had a plugin installed called Simple Posts Generator which I used to generate 10 sample posts for testing purposes. Since I generated the articles all at the same time, the post_date value in the database was the same for each post, which confused Wordpress as to what post should come first. I fixed it by going ...


0

The most obvious approach to this would be to first create a special user role for your students. Then for users with this role you can expand the profile with extra fields. Here you can store for every user which courses they follow. Next you define a custom post type that allows you to store the video labelled with the courses for which it is meant. ...


0

you can Disable users activation email: https://buddypress.org/support/topic/resolved-disable-users-activation-email/ and there is plugin to do its: https://timersys.com/free-plugins/bp-disable-activation-reloaded/


0

Seeing that the referenced answer stores users_online as an array of timestamps indexed by user ID, you can use the include argument for WP_User_Query: $args = array( 'include' => array_keys( $logged_in_users ), // Other arguments );


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


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


0

For wordpress versions > 3.4: Use: $current_user_id= get_current_user_id(); For wordpress versions < 3.4: Use: add_action('init', 'get_your_current_user_id'); function get_your_current_user_id(){ $your_current_user_id= get_current_user_id(); $_SESSION['your_current_user_id'] = $your_current_user_id; } You can check documention: ...


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


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


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


0

if you are trying to link up the post in the user profile area, the code below might be a good starting point. You could put this in your functions.php file. The first function displays a select tag with all the posts from your custom post type in the user profile section. The option value is the post id, and the title is the post name. The next function ...


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


0

The pre_user_query action hook in WordPress will allow you alter the SQL statements in the WP_User_Query object before they are run against the database. Note, this is an action, not a filter, so there's no need to return the $user_query that gets passed in. add_action( 'pre_user_query', 'add_my_custom_queries' ); function add_my_custom_queries( $...


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


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.


0

ACF is a very good option, it has specific options to create user fields. There are tons of tutorials and practical examples out there, just google it and you will find them. It is one of the most popular WP plugins, so don't be afraid of compatibility problems, it's well maintained. You can check its documentation for practical examples about getting it ...


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


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



Top 50 recent answers are included