siteorigin-panels icon indicating copy to clipboard operation
siteorigin-panels copied to clipboard

Loading assets fails when using SO Panels as must use plugin

Open Sharsie opened this issue 7 years ago • 3 comments

Hello there, I encountered an issue with the 2.5.11 version of SOPanels and WordPress 4.8.1 when used as a must use plugin

Expected behaviour: When SOPanels is used as a must-use plugin, the assets should be loaded from mu-plugins directory

Actual behaviour: Some assets are loaded from plugins directory while others are properly mapped to mu-plugins

Steps to reproduce:

  1. Install WordPress version 4.8.1
  2. Install SOPanels 2.5.11 to mu-plugins directory
  3. Go to administration
  4. Open JS console
  5. Create new post
  6. Console should show a syntax error because it loads a 404 page instead of the javascript file
  7. PageBuilder tab on the editor should not be loaded

In depth explanation: The PageBuilder tab would not load, after searching through failed requests I found that the issue lies in calls to plugin_url function from within SOPanels and the plugin is trying to fetch assets (js/css) from the plugins directory instead of mu-plugins

This is the list of files:

plugins/siteorigin-panels/css/admin.css
plugins/siteorigin-panels/js/siteorigin-panels-2511.min.js
plugins/siteorigin-panels/css/images/prebuilt-default.png
plugins/siteorigin-panels/posters/page-builder-tips.svg
plugins/siteorigin-panels/posters/addons.svg
plugins/siteorigin-panels/img/play.svg
plugins/siteorigin-panels/css/front-flex.css
plugins/siteorigin-panels/js/styling-2511.min.js
plugins/siteorigin-panels/js/siteorigin-parallax.min.js
plugins/siteorigin-panels/css/front-flex.css
plugins/siteorigin-panels/js/styling-2511.min.js
plugins/siteorigin-panels/js/siteorigin-parallax.min.js
plugins/siteorigin-panels/css/front-flex.css
plugins/siteorigin-panels/js/styling-2511.min.js
plugins/siteorigin-panels/js/siteorigin-parallax.min.js

My assumption is that the calls to a function siteorigin_panels_url always return the plugins directory https://github.com/siteorigin/siteorigin-panels/blob/2.5.11/inc/admin.php#L239 'js/siteorigin-panels' . SITEORIGIN_PANELS_VERSION_SUFFIX . SITEORIGIN_PANELS_JS_SUFFIX . '.js' expands to js/siteorigin-panels-2511.min.js Then it is run through the siteorigin_panels_url function which calls plugins_url( 'siteorigin-panels/js/siteorigin-panels-2511.min.js' ) Since the plugin parameter to plugins_url is not specified, it always returns plugins directory.

Possible solution: siteorigin_panels_url should call a second parameter, something along the lines of dirname(__FILE__, 2)

Not sure about backwards compatibility

Sharsie avatar Aug 31 '17 13:08 Sharsie

Hi @Sharsie Using PB in mu-plugins is not something we explicitly support. If your goal is to prevent sites from deactivating Page Builder, then I'd suggest using Network Activate to activate Page Builder for all your sites.

braamgenis avatar Sep 07 '17 10:09 braamgenis

Thank you @braamgenis for letting me know, as some of the sites are not multi-sites, we had to resort to using a plugins_url filter hack

If anyone stumbles upon this issue, here is a dirty and ugly solution :)

add_filter(
    'plugins_url',
    function ($url) {
        if (!strpos($url, '/plugins/siteorigin-panels') || !file_exists(\plugin_dir_path(\WP_CONTENT_DIR.\DIRECTORY_SEPARATOR.'mu-plugins'.\DIRECTORY_SEPARATOR.'siteorigin-panels'))) {
            return $url;
        }

        return str_replace("/plugins/siteorigin-panels", "/mu-plugins/siteorigin-panels", $url);
    }
);

Note that there might be other issues related to having PB as a must-use plugin (plugin activation hooks are not run afaik, although I might be wrong)

Sharsie avatar Sep 12 '17 17:09 Sharsie

+1 for adding this feature. Must-use plugins are a popular way for asserting integrity of an install and are fairly commonplace now.

zschuessler avatar Dec 10 '18 22:12 zschuessler

Hi Everyone,

This issue was resolved by https://github.com/siteorigin/siteorigin-panels/pull/1024. We still don't officially support PB being run as a MU Plugin but it should work without needing the workaround @Sharsie posted.

Kind regards, Alex

AlexGStapleton avatar Dec 25 '23 14:12 AlexGStapleton