New answers tagged

0

plugin_basename may be what you want. If your plugin file is located at /wp-content/plugins/my-plugin/my-plugin.php this would return: $file = plugin_basename( __FILE__ ); // "my-plugin/my-plugin.php" If you called the same thing from a sub-directory in your plugin, such as /wp-content/plugins/my-plugin/inc/my-plugin-include.php it would return: ...


1

I think you are looking for plugin_dir_url: $url = plugin_dir_url(__FILE__); $imageurl = $url.'images/someimage.png'; EDIT: Sorry I misread the question... that is only an answer to the linked question. You could check the parent directory recursively until you find the right one: function base_plugin_dir($dirpath) { if (substr(dirname($dir),-7) == ...


0

Edit My bad, in that case I can think of this. $x = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)); It should return http://[url-path-to-plugins]/[custom-plugin]/ But straight forward class I don't think wordpress has one Yes it is from https://codex.wordpress.org/Function_Reference/plugin_basename $x = ...



Top 50 recent answers are included