Mirgrating a user at signon

I am migrating a wordpress site to another site. The users from the old site need to work with the new site. I am doing a staggered implementation, so do not want to bring all the users over at once. Basically, when a user attempts to sign in, before the login is authenticated, if the user does not exist on the new site, I am using an api call to grab the user details from the old site, and create …
Category: Web

Set user role, if an specific role created an user

Im Trying to set an user role. if an specific user role (sales-agents) create an user. the created user should have the role b2b instead of customer here is my try: add_action( 'init', 'b2b_set_user_role' ); function b2b_set_user_role() { if ( is_user_logged_in() && wcb2bsa_has_role( get_current_user_id(), 'sales_agent' ) ) { $user->remove_role( ‘customer’ ); $user->add_role( ‘b2b’ ); } } i hope someone can help me
Category: Web

How can I create a new user account while creating a new post, and then set that new user as the author of that new post?

I have a custom meta box with some user information fields, and when the post is published, the new user account is created, along with the new post. However, the new post's author is set as the current user. Is there a way to set that post's author to be the newly created user? I have the following code: function osb_save_meta_box( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( $parent_id = wp_is_post_revision( $post_id ) …
Category: Web

I want to submit multiple users if checkbox is checked

The following code is getting all terms and see if any one of them is checked or not. If any term is checked a form should show under the selected checkbox with email, the username(auto-generated) and password(auto-generated), and admin should be available to submit each form which will create a user for a specific term. The problem is The form is being submitted to options.php which I have to submit checkboxes in the options table <div class="wrap"> <?php screen_icon(); ?> …
Category: Web

On multisite, plugins are disabled prematurely when viewing the /wp-activate.php page file

On multisite, setting the WP_INSTALLING constant on wp-activate.php file disables all plugins prematurely. Why didn't the core create a way to bypass this. Though this may be required for activating new sites, but by default when activating a new user, the WP_INSTALLING constants should be disabled.
Category: Web

Custom Post Type & Author not associating, user post count is 0, api doesn't return author in post objects

When Users create custom post types, the author field does not seem to be passed back to WP posts functions. As the title says, I'm creating a user account programatically, and having that user log-in and write a post of custom post_type = 'job'. This all LOOKS good in the database - the user, and post are inserted. The post_author is indeed the same as the ID of the user who created it. But, in the User Accounts panel, that …
Category: Web

wp_insert_user - how to send verification email before logging in

Using below code, I am able to create an user. But when I am login, the user is directly logging in to dashboard and there is no email sent to verify the email address. Is there any way to send verification email once the wp_insert_user function is called and the user has to confirm his email address before logging in. I have tried wp_create_user and register_new_user, but I want the function in the way I have requested. $user_login = wp_slash( …
Category: Web

Help hooking into user_register

I'm trying to do a POST request to my API when a user is created. I've installed Code snippets and added the following: add_action('user_register','my_function'); function my_function($user_id){ echo("Code has been run."); echo("<script>console.log('test')"); } Now, when I register a new user, nothing is echoed. The snippet is set to "Run snippet everywhere". I hope I've been specific enough.
Category: Web

How do I edit disclaimer/contact information?

I inherited this wordpress website called RxStudyGuides to use as a study tool for pharmacy students. However, the owner and creator of the website still has there contact information on the website at the bottom of the page and I can't seem to find how to edit that information. It only seems that I can edit the actual content of the website. The creator made me an editor and maybe since I am not the owner of the site I …
Category: Web

Prevent wp_insert_user from creating duplicate users

I have a custom plugin that automatically creates a new user via wp_insert_user() if the current user does not exist yet. We use data from our remote ldap server to provide the new user's details (user_login, user_email, etc.) for the wp_insert_user() function call. This works without a hitch on most of our sites, but on a site that uses WP REST API to render the page, we have noticed that we are sometimes getting duplicate users in the database, same …
Category: Web

What's the difference between wp_insert_user() and wp_create_user()

I know the former allows additional parameters, so you can more user info, but other then that, why do both exist? The specific reason I want to know is that wp_insert_user() is happening REALLY slowly. Somewhere between 5 - 10 seconds. I don't remember having this problem in the past, when I was using create_user, so I'm wondering if there's a lot more happening behind the scenes with one as opposed to the other. Thanks.
Category: Web

Best way to create a user programatically

I want to create a user via a standalone script. I want an activation email to be sent out, in the same way that it is when a user is created from the Add User screen. An email is set out with a link to create the password. There is no password in the email. There seem to be various functions for creating new users. wp_insert_user wp_create_user [register_new_user][3] There's also wp-admin/user-new.php Below is the code I have. It creates a …
Category: Web

Create users via PHP

I'd like to update my users list with some user from a csv file generated by another database (witch i can access too) i'd like to create dynamically a user (with username, password and so on) and other custom fields (such as language, status, and other personal variables). I've fetched my csv (that works), but when i try to create user with wp_insert_user, nothing happens :/ here's the code: function clients_csv($file){ $csv = array_map('str_getcsv', file($file)); for($i=0;$i<count($csv);$i++){ if(!email_exists($csv[7]) ){ print "CREATE …
Category: Web

wp_create_user hook

I'm using UserUltra Pro plugin and I need to create a custom post type after user register in the site. UserUltra plugin uses wp_create_user() which I know is a wrapper for wp_insert_user(). Moreover, I know that 'user_register' is the hook called after wp_insert_user(). Beside this, I can't create new custom post type because it seems that user_register hook is not called. Is this possible? How can I manage it?
Category: Web

How to display user's nickname by default instead of username

I need to display the user's nickname by default after they are created in the DB, NOT the username. I am creating a user with: wp_create_user( $user_name, $random_password, $user_email ); updating the user nickname field directly after user creation: update_user_meta($user_id, 'nickname', $user_nickName); Now i need the "Display name publicly as" to be set to the nickname as default not the username. My WP is automatically defaulting the users display name as the username. How do i put the selected value …
Category: Web

Do I need to flush rewrite rules when creating new user if using custom author rewrite rules?

I am using custom urls for my author pages like this: http://site.com/author_name After I create a new user, that author page appears as not found; however, if I update my permalink structure from admin panel, the author page is found. So, is it necessary to flush rewrite rules after a new user is created? Is there any other way? From codex, I read that flushing rewrite rules is a very expensive task. So, I would like to avoid this. Is …
Category: Web

Assigning input to variable

I am trying to create a plugin that will generate users. I am pretty new to Wordpress and my PHP is ehhhh. I got some helpful help earlier but have made a few turns since... The plugin will generate a user when submit it clicked, the issue is it ignores anything put into the input field and doesn't require it to work. Even if I set $num_users to a number it still only generates one...Perhaps an issue with my for …
Category: Web

Generating User(s) with Settings API

I am trying to create a plugin that will generate users. I am pretty new to Wordpress and my PHP is ehhhh. The idea for it is for the plugin to generate multiple users when its finished. Right now though I am just trying to get it to generate one. But I am having issues trying to do so, any ideas? Once I click Submit, I get a 'Settings Saved'. So, I believe that means the form went through but …
Category: Web

Check to see if there a wordpress user account and create one if not outside of wordpress

Please note that this was posted on wp-hackers mailing list. Hi guys, Just wondering, does anyone know how I can go about checking to see if there a wordpress account and create one if there isn't? Script that I got: https://gist.github.com/Danielx64/7519092 There a marker in the file that has "// Somewhere here I want to put a check to see if there a wp account" What I want to happen there is that a check get done to see if …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.