Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

automated tests as a user?

$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:

  1. Changing user_nicename
  2. User management system similar to wordpress one?
  3. Programmatic Login from 3rd Party site
  4. Change CSS based on is_user_logged_in
  5. Admin Panel 404 Error after login
  6. How to block specific user id in custom login form?
  7. Call WP Rest-Api to GET /users/me returned NOTHING in console
  8. is_user_logged_in() not working in homepage
  9. List users in a dropdown for login
  10. change Dashboard default page on login
  11. add_cap not working
  12. Do not execute If User is login as Administrator or any Specific Role
  13. wordpress archive a user
  14. Problem with login form
  15. Best practice for show data to one specific user?
  16. Login to wordpress by clicking a link and specifying usernaname and password in url
  17. Call to undefined function get_userdata() in plugin
  18. Log in / Log Out Custom Button
  19. Should `wp_login` be used since it’s deprecated?
  20. How to redirect users based on role and content of redirect_to?
  21. get_users meta_query: REGEXP not working for matching new lines
  22. How to display login form anywhere, when user isn’t logged in, without redirecting?
  23. How to show a users bio on a page
  24. How can I open up my administrative panel to everyone?
  25. “operation successful” message
  26. php if username is role
  27. How do you create two separate Register pages?
  28. Is it possible to create new user from external form using REST API?
  29. Foreach loop inside an array_merge
  30. How can I add a new row in a separate database when someone registers via WordPress?
  31. Show current user posts only
  32. One account with multiple logins
  33. Change page password every day (predictable password ;) )
  34. Lost in trying to create user database system
  35. show something only when user comes from specific page at remote host?
  36. Get the users that my following users are following
  37. create front-end users post list by specific category
  38. Shortcode to log user into current URL
  39. Show site content based on user role
  40. PHP getting error when trying to access WP-Admin Dashboard
  41. ‘pre_user_query’ interfering with user export
  42. I installed WordPress locally now how do I login?
  43. If user is logged in not working
  44. Change homepage content if user is logged in – BuddyPress
  45. php return username of currently viewed author profile
  46. Show login greeting above sub-menu links?
  47. How to list users like an archive page 10 users on page and have navigations
  48. How can I call a specific file (via php) by referencing the logged-in username?
  49. Redirect to current user page upon link click
  50. is_user_logged_in returning nothing on custom page
  51. Use of antispambot with $curauth->email
  52. Uses for function: wp_update_user
  53. Display additional user fields
  54. Help with accessing wp-admin page and resolving error messages
  55. Generate a QR code when creating a new WordPress user
  56. Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
  57. Change wordpress’ database data using ajax – how to get current user id?
  58. Sort new column in Users wp-admin
  59. Sort column in Users admin Tab
  60. Can’t log in to WordPress wp-admin after adding code to functions.php
  61. Allow a user or role to view drafts and previews, but not other admin privileges?
  62. Woocommerce display orders with products from specific categories to specific admins
  63. Storing huge number of users in wordpress
  64. Check if user had autologin & if so, logout
  65. PHP warning – Use of undefined constant ‘FORCE_SSL_LOGIN’ ‘FORCE_SSL_ADMIN’ on wp-config.php
  66. Get current user id in function php
  67. Log out without confirmation request (nonce)
  68. How to count active users on a specific page
  69. how can I call a function when time expire
  70. Hide Approved status for certain users in users list
  71. Having trouble creating two shortcodes, one for logged in user and one for visitors
  72. Uploading/integrating custom user registration page
  73. If user has clicked link add class and store using PHP/WordPress
  74. Restrict wordpress access to logged users only
  75. Infinite loop when logging out using custom login form
  76. Menu not updating for logged in users after redirect
  77. Store data from JavaScript object to custom table in user account
  78. Export WordPress User Meta to CSV/Excel
  79. how to use auth_redirect() redirect visitor to login page if they are not login when they click account and order page?
  80. Issues adding Recaptcha v3 to WordPress Registration
  81. Page template not working when logged out
  82. Display specific page if user signed in
  83. Allow specific user to edit a specific page
  84. How to change the value of a variable using input field?
  85. Display current user metadata on WordPress page
  86. Change Login or Logout text based on status
  87. How do I track which user clicked my button?
  88. Refresh page after login with litespeed cache
  89. Help hooking into user_register
  90. Redirect after login depending on the URL
  91. Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
  92. Redirecting the lost password page request when using a custon login page
  93. How do I send a POST request with params with WordPress REST API
  94. Use WP user status (logged_in) to manage access to independent application
  95. wp-login.php?redirect_to=https problem
  96. Add another role to a user when they click a button?
  97. Query to show average # of months all accounts with specific role have been active
  98. wordpress more than one ajax request at the same time issue
  99. (Who to follow) Twitter widget
  100. Can’t get_users info by using json_encode
Categories PHP Tags login, php, testing, users
WordPress with CAS+LDAP and standard WP accounts
Why load_textdomain work but not load_plugin_textdomain?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress