启用Forget About Shortcode Buttons插件时wp.media.view.settings为空问题求助
Hey there, sorry to hear you're stuck dealing with this plugin conflict—developer radio silence is the absolute worst when you’re dependent on their code. Let’s break down actionable fixes to get your site back on track without ditching the plugin entirely:
1. Diagnose the Root Cause
First off, this wp.media.view.settings empty error almost always stems from the plugin’s JavaScript interfering with WordPress’s updated media library initialization logic. Recent WP core changes adjusted how media settings are passed to the admin frontend, and the plugin hasn’t been updated to match.
2. Quick JS Patch to Restore Missing Settings
Add this snippet to your theme’s functions.php (or a custom mu-plugin for safer, theme-independent handling) to manually populate the empty settings object when needed:
add_action('admin_footer', function() { // Target pages where the plugin is active (post editor + plugin settings page) $current_screen = get_current_screen(); if (is_admin() && (isset($_GET['page']) && $_GET['page'] === 'forget-about-shortcode-buttons' || $current_screen->base === 'post')) { ?> <script> document.addEventListener('DOMContentLoaded', function() { // Check if wp.media exists and view.settings is empty if (typeof wp !== 'undefined' && wp.media && Object.keys(wp.media.view.settings).length === 0) { // Copy core media settings to the view.settings object wp.media.view.settings = {...wp.media.settings}; // Ensure critical ajaxurl is set if missing if (!wp.media.view.settings.ajaxurl) { wp.media.view.settings.ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; } } }); </script> <?php } });
This code checks relevant admin pages, detects when wp.media.view.settings is empty, and fills it with core WordPress media settings to restore functionality.
3. Adjust Plugin Script Loading Priority
If the plugin’s JavaScript loads before WordPress’s native media scripts, it can overwrite or break the settings. Locate the plugin’s main PHP file (usually forget-about-shortcode-buttons.php) and find where it enqueues media-related scripts.
Look for code like this:
wp_enqueue_script('fasb-media', plugins_url('js/media.js', __FILE__), array('wp-media'), '1.0', true);
Wrap it in an admin_enqueue_scripts hook with a lower priority (higher number) to ensure it loads after core media scripts:
add_action('admin_enqueue_scripts', function() { wp_enqueue_script('fasb-media', plugins_url('js/media.js', __FILE__), array('wp-media'), '1.0', true); }, 99); // Priority 99 ensures core scripts load first
4. Disable Plugin’s Custom Media Logic (Last Resort)
If the above fixes don’t work, the plugin might have a custom media selector that’s conflicting with WP’s updated system. You can try commenting out parts of the plugin that handle media selection: look for functions or hooks related to media_buttons or wp_enqueue_media in the plugin’s code, and temporarily comment them out to test if the issue resolves.
Long-Term Note
These fixes will get you up and running for now, but keep an eye on future WP updates—you might need to tweak the patches later. When you have time, consider migrating your buttons to a custom shortcode or a more actively maintained plugin, but for now, this should keep your site functional.
内容的提问来源于stack exchange,提问作者ConorBaumgart

