benhuson / Taxonomy-Images

Enables WordPress users to easily associate images from the media library to categories, tags and custom taxonomies.
https://wordpress.org/plugins/taxonomy-images/
21 stars 5 forks source link

Resource loading outside of the WP plugins directory #35

Open xsynaptic opened 7 years ago

xsynaptic commented 7 years ago

I encountered a minor issue while directly integrating this plugin into a theme using Composer + WPackagist: admin-side resources (CSS/images) don't load properly, something I traced back to the taxonomy_image_plugin_url function. It turns out the core plugin_dir_path function returns a malformed URL (absolute URL + relative path) when the file calling it isn't in the WP plugins folder. An easy fix would be to add a filter to the taxonomy_image_plugin_url function... but for the time being, and in case anyone else encounters the issue, this little workaround seems to do the trick:

add_filter( 'plugins_url', function($url) {
  if ( strpos($url, 'taxonomy-images') !== false )
    return get_template_directory_uri() . '/vendor/wp-plugins/taxonomy-images/';
  return $url;
});
benhuson commented 6 years ago

Hi,

It is not recommended to bundle a plugin directly with a theme. Doing this means that it won't be updatable via the WordPress admin should any important updates become available, such as security fixes.

One method which many themes now use is to provide prompts to install and activate required plugins when a theme is activate which requires certain plugins. The TGM Plugin Activation PHP library can help with this.

See: https://make.wordpress.org/themes/handbook/review/required/#plugins http://tgmpluginactivation.com https://wordimpress.com/how-to-easily-require-plugins-for-your-wordpress-themes/

I will consider making the plugin less dependent on being in the plugins folder, perhaps via a filter, but I would advise against this for the reasons above.