Forums / Contribution-Writing Guidelines / What is the correct way to include files inside Encapsulated Plugins?

What is the correct way to include files inside Encapsulated Plugins?

Views: 652

Results 1 to 4 of 4
25 Sep 2025, 5:43 AM
#1
cstdenis2 avatar

cstdenis2

New Zenner

Join Date:
Feb 2018
Posts:
21
Plugin Contributions:
0

What is the correct way to include files inside Encapsulated Plugins?

https://docs.zen-cart.com/dev/plugins/encapsulated_plugins/converting/

**Explicit include or require of storefront files **
TBD

TBD really isn't very helpful...

I've been trying to convert the addons I use to encapsulated for easier management and upgrading.

lots of them have lines like ```
require DIR_WS_CLASSES . 'sitemapxml.php';


I realize in the case of classes it should be using autoloading, but that doesn't solve all the "require" problems and it requires making huge changes that I don't want to deal with to sometimes very complex addons that just need small patches to work encapsulated.

What is the correct way to include files inside Encapsulated Plugins?
25 Sep 2025, 11:42 AM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: What is the correct way to include files inside Encapsulated Plugins?

While I agree that the TBD isn't very helpful, I've got a bunch of plugins that use DIR_WS_CLASSES and/or DIR_WS_FUNCTIONS to load plugin-specific classes and functions.

If you'd identify where within a plugin you're trying to use that constant and the 'require' is failing that would help me help you.

Note, too, that the in-core support for encapsulated plugins has significant changes in zc210 and later. What version of Zen Cart is in use?

26 Sep 2025, 12:32 AM
#3
cstdenis2 avatar

cstdenis2

New Zenner

Join Date:
Feb 2018
Posts:
21
Plugin Contributions:
0

Re: What is the correct way to include files inside Encapsulated Plugins?

Using zc210

When a plugin uses require what is the path relative to? is it relative to the directory with index.php or the plugin's directory?

In this case, I tried to make SitemapXML encapslicated and get this error when I try to generate

[24-Sep-2025 20:04:01 America/Vancouver] Request URI: /index.php?main_page=sitemapxml&rebuild=yes, IP address: 127.0.0.1, Language id 1
#0 /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php(29): zen_debug_error_handler()
#1 /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php(29): require()
#2 /usr/home/sites/zen21/www/index.php(35): require('/usr/home/sites...')
--> PHP Warning: require(includes/classes/sitemapxml.php): Failed to open stream: No such file or directory in /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php on line 29.


[24-Sep-2025 20:04:01 America/Vancouver] Request URI: /index.php?main_page=sitemapxml&rebuild=yes, IP address: 127.0.0.1
--> PHP Fatal error: Uncaught Error: Failed opening required 'includes/classes/sitemapxml.php' (include_path='.:/usr/local/share/pear') in /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php:29
Stack trace:
#0 /usr/home/sites/zen21/www/index.php(35): require()
#1 {main}
  thrown in /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php on line 29.

[24-Sep-2025 20:04:01 America/Vancouver] Request URI: /index.php?main_page=sitemapxml&rebuild=yes, IP address: 127.0.0.1
--> PHP Fatal error: Uncaught Error: Failed opening required 'includes/classes/sitemapxml.php' (include_path='.:/usr/local/share/pear') in /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php:29
Stack trace:
#0 /usr/home/sites/zen21/www/index.php(35): require()
#1 {main}
  thrown in /usr/home/sites/zen21/www/zc_plugins/sitemapXML/4.0.5/catalog/includes/modules/pages/sitemapxml/header_php.php on line 29.

zc_plugins/sitemapXML/4.0.5/catalog/includes/classes/sitemapxml.php does exist.

26 Sep 2025, 1:56 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: What is the correct way to include files inside Encapsulated Plugins?

The path is relative to the location of the calling script.