script_tag_filter_hooked ) { add_filter( 'script_loader_tag', array( $this, 'force_module_script_tag' ), 10, 3 ); $this->script_tag_filter_hooked = true; } if ( wp_script_is( 'heartbeat', 'enqueued' ) ) { wp_dequeue_script( 'heartbeat' ); } if ( wp_script_is( 'svg-painter', 'enqueued' ) ) { wp_dequeue_script( 'svg-painter' ); } wp_enqueue_script( 'common' ); wp_enqueue_script( 'wp-blocks' ); wp_enqueue_script( 'wp-hooks' ); wp_enqueue_script( 'wp-util' ); wp_enqueue_style( 'actionpanel-ai-main-page', trailingslashit( ACTIONPANEL_AI_PLUGIN_URL ) . 'assets/admin/main-page.css', array(), ACTIONPANEL_AI_PLUGIN_VERSION ); $asset_base = trailingslashit( ACTIONPANEL_AI_PLUGIN_URL . 'build' ); wp_register_script( 'actionpanel-ai-app', $asset_base . 'index.js', array( 'wp-blocks', 'wp-hooks', 'wp-util' ), ACTIONPANEL_AI_PLUGIN_VERSION, true ); // Hint module intent for modern WordPress script loading. wp_script_add_data( 'actionpanel-ai-app', 'type', 'module' ); wp_localize_script( 'actionpanel-ai-app', 'actionPanelAiConfig', array( 'restNonce' => wp_create_nonce( 'wp_rest' ), 'nonceRefreshUrl' => admin_url( 'admin-ajax.php?action=actionpanel_ai_refresh_rest_nonce' ), 'nonceRefreshNonce' => wp_create_nonce( 'actionpanel_ai_refresh_rest_nonce' ), 'chatEndpoint' => $this->api_endpoint_resolver->get_base_url(), 'cssUrl' => $asset_base . 'index.css', 'restEndpoints' => array( 'settings' => rest_url( 'actionpanel-ai/v1/settings' ), 'attachments' => rest_url( 'actionpanel-ai/v1/attachments' ), 'capabilities' => rest_url( 'actionpanel-ai/v1/capabilities' ), 'commands' => rest_url( 'actionpanel-ai/v1/commands' ), ), 'settings' => array( 'allowActionPanelAiRequests' => (bool) $this->settings->get_allow_requests(), 'assistantEnabled' => (bool) $this->settings->get_allow_requests(), 'allowLogReads' => (bool) $this->settings->get_allow_log_reads(), 'allowWriteOperations' => (bool) $this->settings->get_allow_write_operations(), 'autoApproveSafeWriteOperations' => (bool) $this->settings->get_auto_approve_safe_write_operations(), 'requireReadApproval' => (bool) $this->settings->get_require_read_approval(), 'setupCompleted' => (bool) $this->settings->is_setup_completed(), ), ) ); wp_enqueue_script( 'actionpanel-ai-app' ); } /** * Force the frontend bundle to load as an ES module. * * @param string $tag Generated script tag. * @param string $handle Script handle. * @param string $src Script source URL. */ public function force_module_script_tag( string $tag, string $handle, string $src ): string { unset( $src ); if ( 'actionpanel-ai-app' !== $handle ) { return $tag; } if ( false !== strpos( $tag, ' type=' ) ) { $updated = preg_replace( '/\stype=(["\']).*?\1/i', ' type="module"', $tag, 1 ); if ( is_string( $updated ) && '' !== $updated ) { return $updated; } } return str_replace( '