Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

2

You don’t give them IDs. The user ID column in the database is an ‘auto increment’ column, meaning that the value is automatically created whenever a row is added. So just add your users without an ID and the database will create one for you.


0

Tested with Wordpress 5.0.4 The first problem to solve it's the post_name value for pages that would share the same slug (e.g. about-me). The simpler solution I found is to add the author nicename (beware: in my solution it should not contain a hyphen!) as the first part of the slug: about-me page post_name for john: john-about-me about-me page post_name ...


0

I figured it out... $meta_value = get_user_meta( $atts['owner'], $meta_key, true ); $store_numbers = array(); foreach ($meta_value as $store_number) { $store_numbers[] = 'shop'.$store_number; } $usernames = $store_numbers;


2

There is an argument for this, and it is documented. If you look at the documentation for get_users() is says this: See WP_User_Query::prepare_query(). for more information on accepted arguments. If you follow that link you'll see the list of arguments, and one of those is: 'has_published_posts' (bool|array) Pass an array of post types to filter ...


-2

You can always use custom sql queries to perform things like that. function custom_query(){ global $wpdb; $tbl_users = $wpdb->prefix . "users"; $tbl_posts = $wpdb->prefix . "posts"; $sql = "SELECT ID, user_nicename FROM $tbl_users where ID in (SELECT post_author from tbl_posts WHERE post_status='publish' group by post_author);"; $...


0

You can set "orderby" and "who" in get_users: https://codex.wordpress.org/Function_Reference/get_users $usersList = get_users( 'orderby=post_count&who=authors' ); foreach ( $usersList as $user ) { echo '<li>' . esc_html( $user->display_name ) . '</li>'; }


2

The function for getting an author's RSS feed URL is get_author_feed_link(). You just need to pass it the user ID.


2

You can add the function to both hooks: add_action('wp_ajax_ajaxTest', 'ajaxTest'); add_action('wp_ajax_nopriv_ajaxTest', 'ajaxTest'); But, there's a better way to do it, use a REST API endpoint: add_action( 'rest_api_init', function () { register_rest_route( 'yourstuff/v1', '/test/', array( 'methods' => 'POST', '...


1

No. You have to write only one function. For example, function ajaxTest(){ //your code } add_action('wp_ajax_ajaxTest', 'ajaxTest'); add_action('wp_ajax_nopriv_ajaxTest', 'ajaxTest');


0

Follow this link, https://gist.github.com/magnific0/29c32c7dabc89ab9cae5, and it will show you how to adjust your functions.php file in your themes folder to show the custom UM metadata under the user menu. works like a charm :)


1

Ok here is how I did it: add_action( 'editable_roles' , 'hide_editable_roles' ); function hide_editable_roles( $roles ){ $blog_id = get_current_blog_id(); // Get current subsite id switch($blog_id) { // Define different max agents numbers depending on subsite id case 6: $max_agents = 10; //for subsite id#6 we can have maximum 10 agents break; ...


0

Please change $user = get_userdata(userID); To $user = get_userdata(YOUR_USER_ID_VARIABLE); And check using print_r($user->roles);


1

You can't see any roles printed, because the ->roles field is an Array, so you can't print it using echo. User print_r instead. You also have an error in this line: $user = get_userdata(userID); There is no such thing like userID - it should be $userID.


0

By the looks of it, there's a plugin to achieve exactly this, so save you rolling your own for it. The plugin is: https://wordpress.org/plugins/permalinks-customizer/ I installed it to test that it does what you're looking for. Here's a screenshot that shows what you'd do:


0

Maybe using insert_user_meta (inside wp_insert_user(), which is also called by wp_update_user()) could also be a viable method to block extra agents from being registered. set_user_role action might also be needed to prevent existing users from getting an agent role. // Maybe prevent setting new users to agent role function new_user_check_roles( $meta, $...


0

Update: There was a problem with my previous code based on some erroneous digging into WordPress roles and capabilities. The below code should work a little better now. You could maybe try hooking the map_meta_cap filter, something like this might work: add_filter( 'map_meta_cap', 'has_max_agents', 10, 2 ); function has_max_agents( $caps, $cap ) { ...


0

If you don't want to copy the entire site just export the tables wp_users and wp_usermeta from your old site's database and copy them into your new site's database.


0

Although you can put parameters on a URL link, be really careful about the parameters you use. For example, the other answer suggest using a parameter like this: https://www.example.com/somepage/?userid=12 Using the user ID number isn't really safe. What is to stop an unscrupulous person to use your link, but another user ID number? Bad things might (or ...


0

Not really sure, but you can pass a variable on that link, and load the desired page with the variable in URL. <?php $user_id = get_current_user_id(); ?> <a href="/my-plugin-url<?php echo $user_id; ?>">View/Download plugin</a> This will load /my-plugin-url page, with the user_id to track


0

The above code is now deprecated. <?php $user_data = get_userdata(get_current_user_id()); $registered_date = $user_data->user_registered; if (strtotime($registered_date) > strtotime('-30 days')){ //Text for users registered in the last 30 days } ?>


0

It’s not exactly WP question, I guess, but let me help anyway... You’re looking for this SQL query: UPDATE wp_users SET user_login = user_nicename The only problem with this is security - user_nicename is public, so it’s not the best value for logins, as you can easily list all logins in such case. Much better idea would be to use email addresses as ...


1

I've written this in a hurry and it's untested and probably sloppy code, but it gives you an idea of how to accomplish this with AJAX. <form id="update_user"> <div class="form-group"> <label for="firstname">Name</label> <input type="text" name="firstname" id="firstname" ...


0

The way you are thinking about it is to use two different identity providers (IdP), Firebase and WordPress, and keep them in sync. This is the most difficult solution to your problem. You really only want to have a single IdP and then use federation to allow users to log into another platform by using that single IdP. In your scenario you want WordPress to ...


0

i found the answer myself. i used wp_get_current_user() while wp_get_current_user() may not be set at this step then i tried the user_can with $user_signon that i defined before for user login. so the new codes: if( user_can($user_signon, 'author') ){ $redirect = site_url().'/pishkhan-teacher'; }elseif( user_can($user_signon, '...


0

You have a typo in your code: $info['emember'] = $remember; should be $info['remember'] = $remember; ("remember" is misspelled) but I don't think this is the source of the problem. wp_get_current_user(); returns either a WP_Error object or a WP_User object (the former if an error, the latter if an authenticated user exists). Rather than calling ...


0

Try this. It works for me. add_filter( 'login_redirect', 'redirect_non_admin_to_dashboard'), 10, 3 ); function redirect_non_admin_to_dashboard($redirect_to, $requested_redirect_to, $user ) { global $user; if( ! isset( $user->ID ) ) { return $redirect_to; } if ( ! in_array( 'author', (array) $user->roles ) ) { $...


Top 50 recent answers are included