0

In my pluging I created a file-1.php file which contains the plugin info and some functions for the plugin functionality, when the file was getting too long, I created a file-2.php file and put some functions there, my plan is to organise the plugin into several logical files, but the plugin could not process the functions in file-2.php, untill I include("file-2.php") in file-1.php, which is more or less having one long file-1.php

I thought plugins would be able to read functions from any file without the include directive.

Does the plugin info written in the first file gives it special privilege/priority?

1 Answer 1

0

Plugins, like any other functions file in a theme are just extensions to your theme's functions.php file. Any file that extends the main functions.php has to be manually included into the main functions file. The reason for this is, only files and templates within Wordpress file structure gets auto laoded. There is no logic to regocnize and to include custom files or templates

The main plugin file of a plugin however is autoloaded and need not to be manually included, although it is just an extension to the main functions.php file of your theme. A plugin is identified by the header of the main plugin file, and it is this header that wordpress uses to identify the plugin and according to that auto loads the main plugin file.

Again, Wordpress only loads the main plugin file as it only knows this file. Any extension to the main plugin file is ignored as Wordpress don't recognize it. To get Wordpress to load any other files, you need to include them into the main plugin file

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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