fix: Add WordPress media library support in standalone mode
🐛 Problem: - WordPress Media library not loaded in standalone mode - Error: 'wp.media is not available' - Image upload functionality broken ✅ Solution: - Added wp_enqueue_media() in render_standalone_admin() - Added wpApiSettings global for REST API compatibility - Print media-editor and media-audiovideo scripts - Print media-views and imgareaselect styles 📝 Changes: - StandaloneAdmin.php: - Enqueue media library - Output media styles in <head> - Output media scripts before app.js - Add wpApiSettings global 🎯 Result: - WordPress media library now available in standalone mode - Image upload works correctly - 'Choose from Media Library' button functional
This commit is contained in:
@@ -43,6 +43,9 @@ class StandaloneAdmin {
|
|||||||
* Render standalone admin interface
|
* Render standalone admin interface
|
||||||
*/
|
*/
|
||||||
private static function render_standalone_admin() {
|
private static function render_standalone_admin() {
|
||||||
|
// Enqueue WordPress media library (needed for image uploads)
|
||||||
|
wp_enqueue_media();
|
||||||
|
|
||||||
// Check if user is logged in and has permissions
|
// Check if user is logged in and has permissions
|
||||||
$is_logged_in = is_user_logged_in();
|
$is_logged_in = is_user_logged_in();
|
||||||
$has_permission = $is_logged_in && current_user_can( 'manage_woocommerce' );
|
$has_permission = $is_logged_in && current_user_can( 'manage_woocommerce' );
|
||||||
@@ -105,8 +108,14 @@ class StandaloneAdmin {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- WooNooW Assets Only - NO wp_head() -->
|
<!-- WooNooW Assets -->
|
||||||
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
|
<link rel="stylesheet" href="<?php echo esc_url( $css_url ); ?>">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Print WordPress media library styles and scripts
|
||||||
|
wp_print_styles( 'media-views' );
|
||||||
|
wp_print_styles( 'imgareaselect' );
|
||||||
|
?>
|
||||||
</head>
|
</head>
|
||||||
<body class="woonoow-standalone">
|
<body class="woonoow-standalone">
|
||||||
<div id="woonoow-admin-app"></div>
|
<div id="woonoow-admin-app"></div>
|
||||||
@@ -137,13 +146,22 @@ class StandaloneAdmin {
|
|||||||
|
|
||||||
// Navigation tree (single source of truth from PHP)
|
// Navigation tree (single source of truth from PHP)
|
||||||
window.WNW_NAV_TREE = <?php echo wp_json_encode( \WooNooW\Compat\NavigationRegistry::get_frontend_nav_tree() ); ?>;
|
window.WNW_NAV_TREE = <?php echo wp_json_encode( \WooNooW\Compat\NavigationRegistry::get_frontend_nav_tree() ); ?>;
|
||||||
|
|
||||||
|
// WordPress REST API settings (for media upload compatibility)
|
||||||
|
window.wpApiSettings = {
|
||||||
|
root: <?php echo wp_json_encode( untrailingslashit( rest_url() ) ); ?>,
|
||||||
|
nonce: <?php echo wp_json_encode( $nonce ); ?>,
|
||||||
|
versionString: 'wp/v2/'
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="module" src="<?php echo esc_url( $js_url ); ?>"></script>
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// NO wp_footer() - we don't want theme/plugin scripts
|
// Print WordPress media library scripts (needed for wp.media)
|
||||||
|
wp_print_scripts( 'media-editor' );
|
||||||
|
wp_print_scripts( 'media-audiovideo' );
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<script type="module" src="<?php echo esc_url( $js_url ); ?>"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
Reference in New Issue
Block a user