Skip to main content
7 events
when toggle format what by license comment
Nov 28, 2020 at 12:54 comment added Tom J Nowell Bosco is right, either your plugin is a single PHP file in the plugins folder, or, it's a PHP file inside a subfolder that has other files it includes. I cannot be a mixture of the two. If you have a single file in the plugins folder, it cannot require/include files from a subfolder. This isn't about the code inside the files, this is about the location of the files themselves
Nov 27, 2020 at 14:27 comment added bosco Tom's saying if your main plugin file was in the general plugins directory it would be incorrect - but your file structure does not meet this description. The path in plugins_url() needs to reference the main loaded plugin file. In this case, from the Shortcode.php file, that might look like plugins_url( 'Blocks/Pages/ShortcodeApi/ShortcodeScript.js', dirname( dirname( __DIR__ ) ) . '/Info-Wheel.php' ). Or you could expose Info-Wheel.php's path in a property or function, or pass it into the classes it constructs, etc.
Nov 27, 2020 at 13:13 comment added Mähnenwolf How is the plugin folder structure wrong? I'm using OOP. Inside my Ìnfo-Wheel.php file I run a class function from Init:: register_services(), which runs all of the needed functions for my plugin. Everything works, besides having to figure out how to load the CSS/JS file. Here is an image to my folder structure. I tried running the add_action(), to enqueue my files, but still nothing.
Nov 27, 2020 at 13:01 comment added Tom J Nowell it has to be the main plugin PHP file, aka the file with the plugin header at the top that WP loads first. Note that this is assuming your plugin is a PHP file in a subfolder e.g. wp-content/plugins/yourplugin/plugin.php. If your plugin is a file in the plugins folder that loads more files from a subfolder then that needs changing as the plugin folder structure is incorrect. As for your shortcode, that looks better
Nov 27, 2020 at 12:28 comment added Mähnenwolf So I now use the correct pathing for wp_register_script/style(), but it still doesn't do anything. Where do I write code so the style is being loaded?
Nov 27, 2020 at 11:49 comment added Mähnenwolf 1. The shortcode file is inside thisfolder: MyPlugin\Blocks\Pages\ShortcodeAPI\Shortcode.php Inside MyPLugin is MyPlugin.php. So does this mean, __FILE__ has to be the name of the main file, or would be the root enough? 2. I now wrote php public function layout() : string { ob_start(); require $this->iw_plugin_path . "URL"; return ob_get_clean(); } That should be correct, then.
Nov 27, 2020 at 11:08 history answered Tom J Nowell CC BY-SA 4.0