Fatal error: cannot redeclare plugins_api()

I was configuring Wordfence for a site and found myself locked out. So I removed WF via FTP and was able to log back in.

However, since then I get the following error when clicking on either ‘Plugins > Upload’ or ‘Plugins > Add WP Plugin’:

Fatal error : Cannot redeclare plugins_api() (previously declared in /xxxsiteinfoxxx/wp-admin/includes/plugin-install.php:101) in /xxxsiteinfoxxx/wp-admin/includes/plugin-install.php on line 101

Any ideas about how to prevent a ‘redeclaration’ of plugins_api()?

That’s the first executable line in that file. Did yours get corrupted, or loaded twice? It seems like the message is saying that line 101 has two declarations on it.

@raygulick You should be able to reinstall WF via Add new plugins. Sometimes, if you removed plugin using ftp; that means there are still data hash(es) in the database and when it tries to reactivate WF the hashes do not match (anything).*

Also try making a clone/stage copy of the site. Check the wp-config file in your root. WF uses a Constant define('WFWAF_ENABLED', true) which of course, may be set to true False will disable it… there are “many” Constants WF writes to wp-config.php so be sure to examine and maybe comment out any.

Also TRY (this) FIRST: add WP_DEBUG to create a log. Then use your FTP to open and read any errors. To get full results with WP/CP errors logs use this in the wp-config; but don’t forget to remove when done (log will be in wp-content folder as “debug.log”:

`define(‘WP_DEBUG’, true);
define( ‘WP_DEBUG_DISPLAY’, false );
@ini_set( ‘display_errors’, 0 );
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_AUTO_UPDATE_CORE’, false );


define( ‘WP_DEBUG’, true );
if ( WP_DEBUG ) {
define( ‘WP_DEBUG_LOG’, true );
define( ‘WP_DEBUG_DISPLAY’, false );
@ini_set( ‘display_errors’, 0 );

Luck. Of course try https://wordpress.org/support/plugin/wordfence/ but I didn’t see anything pertinent there.

*Maybe try, load Better Search And Replace plugin to find any instances of WordFence that may contain meta and see how many returned results you get. This will at least tell you there is old data in the db.

Here’s the code that starts on line 101 in plugin-install.php (which is the first uncommented line in the file) and the closing return:

function plugins_api( $action, $args = array() ) {
	if ( is_array( $args ) ) {
		$args = (object) $args;
	if ( ! isset( $args->per_page ) ) {
		$args->per_page = 24;
	if ( ! isset( $args->locale ) ) {
		$args->locale = get_user_locale();

    A BUNCH OF CODE (cannot see where it would redeclare the function)

return apply_filters( 'plugins_api_result', $res, $action, $args );

No, I cannot reinstall WF or any other plugin via Add New. or via Upload. That’s the problem. I can only add plugins by uploading via FTP, then activating them.

After deleting WF, I used PHPMyAdmin to make sure all WF tables were gone.
Uploaded a backup of wp.config.php, and it contains no WF-related lines.

Added the code suggested (tried both versions offered), then tried installing plugins several times, but it did not create debug.log

1 Like

From a Google search, this seems to be something we’ve inherited from WP. So I don’t think it’s a plugin issue. I suspect something has corrupted your CP installation. I would first try re-installing the plugin-install.php file. If that doesn’t cure it, then you could try its whole folder or even re-uploading the whole wp-admin folder.

Did that (re-uploaded entire wp-admin folder). Did not fix the issue.

Then it sounds like there is something in the options table of the database that is causing this (presumably left behind by WF). I suggest asking them what entries they add to that table.

That’s a good thought. I’ll check it out and report back.

Wordfence had added a few rows in wp_options, but removing them did not resolve the issue.

Then the only other thing I can think of is a caching issue, either on site or in the browser.

The site has no caching plugin, and I’ve tried other browsers, so I think caching is an unlikely cause of the issue.

Google so far has not shown me any applicable information.

You don’t use transients, object caching, or something like Varnish or CloudFlare?

Go to the cp dashboard > updates > re-install ClassicPress

No data is lost doing that but still make a backup prior to perform.
It’ll most likely solve the issue if any file is corrupted somehow.

None of that.

Seems like a good idea, so I tried it. Didn’t fix the issue.

Seems like your best route is to install a brand new instance of CP and then start adding plugins, one at a time, saving WF for LAST. Maybe try loading new instance in sub domain just to be sure you are somewhat isolated from the current instance.

Maybe export your blog xml so you have some data to run but I’m thinking your host has a virus in a close by directory on your shared drive; or the PHP version is not fit for CP.

OK, I found the issue. It was an error being thrown by Stop Generating Unnecessary Thumbnails plugin. I thought I had disabled it and several others, but in reviewing plugins for possible conflicts, noticed it was not disabled; had to try 3 times before it disabled. Once done, plugin ‘uploads’ and ‘add’ are back to normal.

Thanks all for your suggestions.

Likely one of these lines:

/plugins/image-sizes/vendor/codexpert/plugin/src/Feature.php:51:  $this->filter( 'plugins_api_result', 'alter_api_result', 10, 3 );
/plugins/image-sizes/vendor/codexpert/plugin/src/Feature.php:61:  remove_filter( 'plugins_api_result', [ $this, 'alter_api_result' ] );
/plugins/image-sizes/vendor/codexpert/plugin/src/Feature.php:99:  $plugin_info = plugins_api( 'plugin_information', array(
/plugins/image-sizes/vendor/codexpert/plugin/src/Update.php:86:  add_filter( 'plugins_api', [ $this, 'plugins_api_filter' ], 10, 3 );
/plugins/image-sizes/vendor/codexpert/plugin/src/Update.php:86:  add_filter( 'plugins_api', [ $this, 'plugins_api_filter' ], 10, 3 );
/plugins/image-sizes/vendor/codexpert/plugin/src/Update.php:298:  public function plugins_api_filter( $_data, $_action = '', $_args = null ) {

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.