Frage


Warning: require_once(/assets/MCAPI.class.php): failed to open stream: No such file or directory in /home2/....../wp-content/plugins/bplugin/shortcodes.php on line 148

Fatal error: require_once(): Failed opening required '/assets/MCAPI.class.php' (include_path='.:/opt/php54/lib/php') in /......./wp-content/plugins/bplugin/shortcodes.php on line 148

require_once(plugin_dir_path( __FILE__ ) . '/assets/MCAPI.class.php');

Am I not using the correct path method?

This file is called inside a rest API function → https://www.screencast.com/t/5mhWur8hmR

Update: If I transfer file from assets to the plugin directory then things work →

require_once(plugin_dir_path(__FILE__).'MCAPI.class.php');

but that's not the very clean method of handling files.

War es hilfreich?

Lösung

https://developer.wordpress.org/reference/functions/plugin_dir_path/

It looks like this function adds a trailing slash, so starting your string with a slash is not required try;

require_once(plugin_dir_path( __FILE__ ) . 'assets/MCAPI.class.php');
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top