$user_id = $this->_make_user('author', 'user_login_name', 'password', '[email protected]');
wp_set_current_user( $user_id );
as long as the class that you define the testcase in inherits from WPTestCase
, then you can use the _make_user
function. The function is found in this svn repository, and is defined in wp-testlib/base.php
line 380.
NEW:
I switched to using wp_insert_user
.
the following is in my setUp:
$this->user_id = wp_insert_user(array('user_login'=>'test_administrator', 'role'=>'administrator'));
wp_set_current_user( $this->user_id , '');
and the following is in my teardown:
wp_delete_user($this->user_id);
$this->user_id = 0;
Related Posts:
- Changing user_nicename
- User management system similar to wordpress one?
- Programmatic Login from 3rd Party site
- Change CSS based on is_user_logged_in
- Admin Panel 404 Error after login
- How to block specific user id in custom login form?
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- is_user_logged_in() not working in homepage
- List users in a dropdown for login
- change Dashboard default page on login
- add_cap not working
- Do not execute If User is login as Administrator or any Specific Role
- wordpress archive a user
- Problem with login form
- Best practice for show data to one specific user?
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Call to undefined function get_userdata() in plugin
- Log in / Log Out Custom Button
- Should `wp_login` be used since it’s deprecated?
- How to redirect users based on role and content of redirect_to?
- get_users meta_query: REGEXP not working for matching new lines
- How to display login form anywhere, when user isn’t logged in, without redirecting?
- How to show a users bio on a page
- How can I open up my administrative panel to everyone?
- “operation successful” message
- php if username is role
- How do you create two separate Register pages?
- Is it possible to create new user from external form using REST API?
- Foreach loop inside an array_merge
- How can I add a new row in a separate database when someone registers via WordPress?
- Show current user posts only
- One account with multiple logins
- Change page password every day (predictable password ;) )
- Lost in trying to create user database system
- show something only when user comes from specific page at remote host?
- Get the users that my following users are following
- create front-end users post list by specific category
- Shortcode to log user into current URL
- Show site content based on user role
- PHP getting error when trying to access WP-Admin Dashboard
- ‘pre_user_query’ interfering with user export
- I installed WordPress locally now how do I login?
- If user is logged in not working
- Change homepage content if user is logged in – BuddyPress
- php return username of currently viewed author profile
- Show login greeting above sub-menu links?
- How to list users like an archive page 10 users on page and have navigations
- How can I call a specific file (via php) by referencing the logged-in username?
- Redirect to current user page upon link click
- is_user_logged_in returning nothing on custom page
- Use of antispambot with $curauth->email
- Uses for function: wp_update_user
- Display additional user fields
- Help with accessing wp-admin page and resolving error messages
- Generate a QR code when creating a new WordPress user
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- Change wordpress’ database data using ajax – how to get current user id?
- Sort new column in Users wp-admin
- Sort column in Users admin Tab
- Can’t log in to WordPress wp-admin after adding code to functions.php
- Allow a user or role to view drafts and previews, but not other admin privileges?
- Woocommerce display orders with products from specific categories to specific admins
- Storing huge number of users in wordpress
- Check if user had autologin & if so, logout
- PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
- Get current user id in function php
- Log out without confirmation request (nonce)
- How to count active users on a specific page
- how can I call a function when time expire
- Hide Approved status for certain users in users list
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Uploading/integrating custom user registration page
- If user has clicked link add class and store using PHP/WordPress
- Restrict wordpress access to logged users only
- Infinite loop when logging out using custom login form
- Menu not updating for logged in users after redirect
- Store data from JavaScript object to custom table in user account
- Export WordPress User Meta to CSV/Excel
- how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
- Issues adding Recaptcha v3 to WordPress Registration
- Page template not working when logged out
- Display specific page if user signed in
- Allow specific user to edit a specific page
- How to change the value of a variable using input field?
- Display current user metadata on WordPress page
- Change Login or Logout text based on status
- How do I track which user clicked my button?
- Refresh page after login with litespeed cache
- Help hooking into user_register
- Redirect after login depending on the URL
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Redirecting the lost password page request when using a custon login page
- How do I send a POST request with params with WordPress REST API
- Use WP user status (logged_in) to manage access to independent application
- wp-login.php?redirect_to=https problem
- Add another role to a user when they click a button?
- Query to show average # of months all accounts with specific role have been active
- wordpress more than one ajax request at the same time issue
- (Who to follow) Twitter widget
- Can’t get_users info by using json_encode