/    Sign up×
Bounties /Pin to ProfileBookmark

WordPress How to fix Fatal Error: Uncaught Error: Class … not found

To preface this, I have basically no experience in web development, so I’m trying earnestly to learn how to fix the issue.  I know there’s a lot that I simply don’t even understand even when it’s clear-as-day to a pro web developer. 

I’ve got a plugin that is crashing my website. I’ve asked the developer for help, but they’ve been less than helpful and saying it’s not the plugin. Maybe so, but I don’t know what I’m doing. I installed the WP Debugger plugin, and I was able to get a debug log that shows more issues than I can understand. However, at the end of it, this is what I’m getting:

Stack trace:#0 /home4/oldenha1/public_html/thebulletpros/wp-settings.php(462): include_once()#1 /home4/oldenha1/public_html/thebulletpros/wp-config.php(191): require_once(‘/home4/oldenha1…’)#2 /home4/oldenha1/public_html/thebulletpros/wp-load.php(50): require_once(‘/home4/oldenha1…’)#3 /home4/oldenha1/public_html/thebulletpros/wp-blog-header.php(13): require_once(‘/home4/oldenha1…’)#4 /home4/oldenha1/public_html/thebulletpros/index.php(17): require(‘/home4/oldenha1…’)#5 {main}thrown in /home4/oldenha1/public_html/thebulletpros/wp-content/plugins/gateway/gateway.php on line 27

The website is currently giving this below error when the debug plugin and the problematic plugin are both active (it says more to this error, but it bascially seems to be also saying what’s above):

Fatal error: Uncaught Error: Class “CustomPaymentGateway\Plugin” not found in /home4/oldenha1/public_html/thebulletpros/wp-content/plugins/gateway/gateway.php:27  

The debugging plugin itself was giving me problems with accessing the website, so I did learn how to get directly into it to deactivate it; pretty cool.  I’ve done a bunch of digging around trying to understand the error in more detail after that.  My understanding is that it might have something to do with the way things are named and what folders the different components landed in during installation of the plugin.  For instance, my understanding is that it’s looking for a Plugin.php file in a folder called CustomPaymentGateway (could be wrong on this), and there is supposed to be a reference of that CustomPaymentGateway\Plugin in the gateway.php file.  It’s there, but not sure what the “line 27” issue in the error message is.  I also don’t see anything at all in cPanel saying CustomPaymentGateway.  This below is the gateway.php file.

to post a answer
DebuggingWordPress

1 Replies

Davinci•003 auto-replyThe "Fatal Error: Uncaught Error: Class ... not found" in WordPress usually occurs when the PHP code refers to a class that is not available or not defined in the current scope. This could be due to several reasons such as:

1. The class file is not included or required correctly.
2. The class file is not present in the specified location.
3. The class file is not loaded yet when it's being used.
4. The class name is misspelled.

Here are some steps you can take to fix this issue:

1. **Check the class file location**: Make sure the class file is present in the specified location.

2. **Check the spelling of the class name**: PHP is case-sensitive. Make sure the class name is spelled correctly and respects the case.

3. **Include or require the class file correctly**: If the class is defined in a different file, you need to include or require that file before you use the class. Here's how you can do it:

``php
require_once 'path/to/your/class/file.php';
`

4. **Use an autoloader**: If your project has a lot of classes, it's a good practice to use an autoloader. An autoloader will automatically include or require the class file when the class is used. Here's a simple example of an autoloader:

`php
spl_autoload_register(function ($class_name) {
include 'classes/' . $class_name . '.php';
});
``

In this example, the autoloader assumes that all class files are located in the 'classes' directory and the file name is the same as the class name with a '.php' extension.

5. **Check the order of your code**: Make sure the class is not used before it's defined or included.

If you've checked all these and you're still having the issue, the problem might be more complex and specific to your project. In that case, you might need to provide more details or consult with a professional developer.

Was this helpful?

×

Success!

Help @whistlepig spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...