$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
- User registration followed by automatic login
- PHP unit testing WordPress?
- Adding “Remember Me” in custom login
- How to change the wp-login.php page title?
- How build a custom login/register form with error handling?
- Add extra field to users
- Why Can’t PHPUnit UnitTest My WordPress Website
- Display user’s total comment count outside The Loop
- Change the footer text on the login page
- What is the most efficient way to search users by their display name?
- How do I create a WP user outside of WordPress and auto login?
- Network installation giving errors when viewing or adding a user
- How do I hide specific user profile fields?
- WordPress 4 invalid username special charachters issue
- How to place login logout link on menu that redirects users back to current page?
- Using a nonce in a Custom Login Form
- Constructing a custom login form using ajax
- get_users(…) only returns one user
- PHP If user is logged in & on home page redirect
- WordPress shows registration link for non logged users
- List User order by ID in Descending order (Backend)
- Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
- Admin username and password
- Get all user meta by meta key instead of ID
- Is it necessary to sanitize wp_set_password user input?
- WordPress custom login form using Ajax
- How to give new users two specific user role options upon WordPress user registration
- How to: PHP Log Out Link?
- Login/logout in header
- Why is my cookie not unsetting upon logout? [closed]
- Show all posts by author
- Custom user login page by creating a plugin
- getting logged in user info (wp-load.php) from parent directory
- Get users that likes the post
- custom user role wordpress – grant guest access to edit.php without insert/update/delete
- Problem with login form
- get_users meta_query: REGEXP not working for matching new lines
- How do you create two separate Register pages?
- 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
- PHP getting error when trying to access WP-Admin Dashboard
- ‘pre_user_query’ interfering with user export
- If user is logged in not working
- Show login greeting above sub-menu links?
- How can I call a specific file (via php) by referencing the logged-in username?
- Uses for function: wp_update_user
- Display additional user fields
- Help with accessing wp-admin page and resolving error messages
- Sort new column in Users wp-admin
- Storing huge number of users in wordpress
- PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
- Log out without confirmation request (nonce)
- How to count active users on a specific page
- Hide Approved status for certain users in users list
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Infinite loop when logging out using custom login form
- Menu not updating for logged in users after redirect
- 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
- Display specific page if user signed in
- Allow specific user to edit a specific page
- Display current user metadata on WordPress page
- Change Login or Logout text based on status
- 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
- (Who to follow) Twitter widget
- Can’t get_users info by using json_encode
- Check if a user is logged into my WordPress site which is on a different server
- Matching multi user
- Newbie question. Login/Registration. New PHP page
- Adding a sidebar to wp-login.php
- How to set max users to 17.000
- Trying to display user meta by “name” – not by “ID”
- White screen after login attempt
- Adapting a php array to WordPress
- Cross origin ajax request always returns 0 when calling get_current_user_id();
- Forbid certain users to access a specific page
- How to replace wp-admin login page to another location?
- One folder to be accessible by one user
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- Getting invalid user ID error when creating a new user with wp_insert_user
- How to change wp-admin and wp-login urls
- How do I do so that people can register on my wordpress site?
- I can’t log into my website , it says “Error: Cookies are blocked due to unexpected output”