I am trying to load WordPress options within a standalone PHP file. The file is located in /wp-content/plugins/plugin-name/file.php. I have used the following to open wp-load.php:

if (file_exists('../../../wp-load.php')) {
    require_once ('../../../wp-load.php');

Doing so outputs the following error:

Fatal error: Cannot redeclare some_plugin_function() (previously declared in /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/plugin-name/class-frontend.php:5) in /var/www/vhosts/domain.com/httpdocs/wp-content/plugins/plugin-name/class-frontend.php on line 12

Removing all code from class-frontend.php does solve the issue, but of course I need that file. class-frontend.php is not called within the standalone PHP file so am unsure why this is happening.

  • I have the same problem. If I don't delete everything from functions.php of my child theme it will say that I am re-declaring some function (even though it is declared only once). And the error seems the same - the lines are different for the paths though they point to the same function in the same file. Did you get it fixed somehow ? – Tolea Bivol Nov 24 '19 at 16:13

This error has nothing to do with wp-load.php. You are declaring the 'some_plugin_function' function twice within your plugin file. The error message tells you exactly where to look.

You don't need to call class-frontend.php from your stand-alone PHP file to get the error. It's in a plugin, so as long as that plugin is active, it will be parsed.

  • 1
    I looked there and it is not declared anywhere else. There is no error anywhere else on any other file. I find it odd as I don't call class-frontend.php in the file at all. – manc Mar 30 '13 at 15:54
  • Please post the code from class-frontend.php – vancoder Mar 30 '13 at 15:56
  • its a lot of code but know it has nothing to do with the error – manc Mar 30 '13 at 16:41
  • It has everything to do with the error. – vancoder Mar 30 '13 at 17:23
  • 1
    The question has been answered. The error message clearly states what the problem is (twice declaring the same function) and where this takes place (class-frontend.php lines 5 and 12). This error will always be thrown as long as the plugin is active. That's all there is to it. – vancoder Mar 31 '13 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.