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

How to create session for user which is not an admin user

// ADMIN

$user_id = 1;
require_once (ABSPATH . ‘wp-includes/pluggable.php’);

if (!is_admin())
{

// DEMO USER

$user_id = 6;
}

if ($current_user_id != $user_id)
{
$user = get_user_by(‘id’, $user_id);
if ($user)
{
wp_set_current_user($user_id, $user->user_login);

    // wp_set_auth_cookie($user_id);

    if (wp_validate_auth_cookie('', 'logged_in') != $user_id)
        {
        wp_set_auth_cookie($user_id);
        }

    // do_action('wp_login', $user->user_login);

    }
}

Related Posts:

  1. WordPress and PHP Sessions – Security and Performance
  2. How should you hook a session_start() when authoring a plugin?
  3. Does using set_transient() function can lead to MySQL problems?
  4. Sessions not creating correctly in custom function
  5. Why is my javascript not invoked in my hooks except wp_head?
  6. External Authentication, session_tokens not destroyed on logout
  7. Custom login doesn’t work properly
  8. captcha not working in my custom plugin
  9. Displaying “One Time” Notification in Plugins
  10. Can we intercept user_login and user_pass from a wp_login_form?
  11. Updating transient value frequently
  12. How do I validate extra pin field on my WordPress login form page?
  13. Hiding the WordPress login and password fields from login page
  14. how to add security questions on wp-registration page and validate it
  15. $_SESSION inside php function executed by AJAX
  16. Sessions in plugin development?
  17. Create a Custom Login System in WordPress [closed]
  18. Flash messages for not logged in users
  19. Objective Best Practices for Plugin Development? [closed]
  20. add_menu_page() with different name for first submenu item
  21. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  22. How to include PHP files in plugins the correct way
  23. How can I add an image upload field directly to a custom write panel?
  24. A tool to analyze rewrite rules? [closed]
  25. Difference Between Filter and Action Hooks?
  26. framework for plugin/theme options panel? [closed]
  27. Creating a table in the admin-style?
  28. How can you check if you are in a particular page in the WP Admin section? For example how can I check if I am in the Users > Your Profile page?
  29. Settings API with arrays example
  30. How to get the path to the current theme?
  31. How to make a plugin require another plugin?
  32. ajaxurl not defined on front end
  33. What process do you use for WordPress development? [closed]
  34. What’s the difference between term_id and term_taxonomy_id
  35. Should I use wpdb prepare?
  36. Why does WordPress use outdated jQuery v1.12.4?
  37. Post meta vs separate database tables
  38. Is there any plugin development framework
  39. Is it possible to reuse wp.media.editor Modal for dialogs other than media
  40. How to add a javascript snippet to the footer that requires jQuery
  41. Enhance Media Manager for Gallery
  42. How do I create a custom role capability?
  43. How do I add CSS options to my plugin without using inline styles?
  44. How do i best handle custom plugin page actions?
  45. Adding Custom Text Patterns in the WP 4.5 Visual Editor
  46. Automatically determine minimum WordPress version required for a plugin?
  47. What is the advantage of using wp_mail?
  48. How to make a WordPress plugin translation ready?
  49. How many times will this code run? (or, how rich is grandma?)
  50. How to create an API for my plugin?
  51. Is it ever okay to include inline CSS in plugins?
  52. Plugins in symlinked directories?
  53. How to override existing plugin action with new action
  54. How to include a file using get_template_part() in a plugin?
  55. Add custom TinyMCE 4 Button, Usable since WordPress 3.9-beta1
  56. How to store username and password to API in wordpress option DB?
  57. body_class hook for admin pages
  58. “Error: Options Page Not Found” on Settings Page Submission for an OOP Plugin
  59. Is it mandatory to use $wpdb->prefix in custom tables
  60. Which hook should be used to add an action containing a redirect?
  61. add_action hook for completely new post?
  62. Why does WordPress add 0 (zero) to an Ajax response?
  63. What should I use instead of WP_CONTENT_DIR and WP_PLUGIN_DIR?
  64. How to enqueue JavaScripts in a plugin
  65. In Which Contexts are Plugins Responsible for Data Validation/Sanitization?
  66. Plugin Form Submission Best Practice
  67. How to redirect to settings page once the plugin is activated?
  68. Is get_option function cached?
  69. Should Plugin Folders Include a Blank index.php File?
  70. Unit testing for plugin development
  71. Methods of Integrating Plugin Data with Themes
  72. What is the wordpress wp-includes folder for?
  73. WordPress Update Plugin Hook/Action? Since 3.9
  74. How to include jQuery and JavaScript files correctly?
  75. How come `wp_options` table does not have an index on `autoload`?
  76. PHP error with shortcode handler from a class
  77. Update Option Stored in Multi-Dimensional Array
  78. check if Gutenberg is currently in use
  79. Best way to abort plugin in case of insufficient PHP version?
  80. WordPress Plugin Development – Headers Already Sent Message
  81. WP 3.3 How to Add Menu Items to the Admin Bar?
  82. dbDelta not creating tables
  83. Custom Widget function in Plugin not working?
  84. Passing arguments to a admin menu page callback?
  85. Single functions.php or split into many small files?
  86. Get page content using slug
  87. $_POST form request with admin-post
  88. How to fork a plugin?
  89. How can I configure Docker for developing and deploying a custom theme?
  90. How to include wp-load.php from any location?
  91. Correct way to enqueue jquery-ui
  92. Where to store PHP files created by plugin / themes
  93. How to echo the_excerpt without the P tag wrapper?
  94. How can I update a wordpress plugin from a Git repository (github)
  95. What are the advantages to the Settings API?
  96. Add screen options to custom admin pages
  97. Strategy On Building Plugin Using Eclipse
  98. How to add sub-menu to a menu generated by wp_nav_menu by using plugin
  99. Is There a Plugin Life Cycle Documentation?
  100. What do you think about custom designed plugin/theme options UIs?
Categories plugin-development Tags plugin-development, session, wp-login-form
How woo-commerce store Product Data value in DB?
Need help with theme Business (Modern Themes): sidebar issue

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
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 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