404 styles/ assets when installed as mu-plugin
-
When viewing the migrate db page none of the styles/ assets or wp-migrate-db are loaded.
Visually this is apparent because none of the tabs for setting groups display correctly, and all possible error messages are visible.
Wordpress Version: 5.0.3
Migrate DB Version: 1.0.10
Location: Multisite network migrate db page (should also be replicable in none multisite setup)Steps to reproduce: Install WP Migrate DB as an mu-plugin. Activate plugin. Navigate to migrate DB page.
More information:
The issue appears to be the invocation of plugins_url on line 45 of
mu-plugins/wp-migrate-db/class/Common/Plugin/Assets.php
Because there’s no ‘optional’ second argument passed through wrong branch of this conditional runs:
if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) ) $url = WPMU_PLUGIN_URL; else $url = WP_PLUGIN_URL;
So any scripts/ assets are loaded onto a page referencing the plugins directory, not the mu-plugins directory.
Locally, we’ve found that updating the invocation to the following:
$plugins_url = trailingslashit( plugins_url( $this->props->plugin_folder_name, $this->props->plugin_dir_path) );
Fixes the issue with the 404’ing resources. But we’re unsure if this has other consequences.
Interestingly, we think this is also a bit of a kludge around what is essentially a flaw in the WordPress code:
function plugins_url( $path = '', $plugin = '' ) { $path = wp_normalize_path( $path ); $plugin = wp_normalize_path( $plugin ); $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) ) $url = WPMU_PLUGIN_URL; else $url = WP_PLUGIN_URL;
I can’t think why the decision to use the WPMU_PLUGIN_URL or WP_PLUGIN_URL would be inferred from the value of
$plugin
. Even if I don’t explicitly pass it, the plugin is installed undermu-plugin
, and the default empty string value botches the logic and tells WordPress to consider it otherwise.Regardless, wp-migrate-db can fix the problem from their code by explicitly passing the appropriate value to the the second parameter for that function.
- The topic ‘404 styles/ assets when installed as mu-plugin’ is closed to new replies.