(bool) $is_gutenberg, 'elementor' => (bool) $is_elementor, 'divi' => (bool) $is_divi, ); } /** * Enqueue admin scripts & styles. */ public static function enqueue_admin_assets( $hook ) { if ( self::$page_hook && $hook !== self::$page_hook && false === strpos( $hook, 'translatesense' ) && false === strpos( $hook, 'mlang' ) ) { return; } // Asset file metadata handling with fallback $asset_file = TRANSLATESENSE_PLUGIN_DIR . 'assets/build/dashboard/index.asset.php'; $asset = file_exists( $asset_file ) ? require $asset_file : array( 'dependencies' => array( 'wp-element', 'wp-components', 'wp-api-fetch', 'wp-i18n' ), 'version' => TRANSLATESENSE_VERSION, ); // Enqueue CSS wp_enqueue_style( 'translatesense-admin-css', TRANSLATESENSE_PLUGIN_URL . 'assets/build/dashboard/index.css', array( 'wp-components' ), $asset['version'] ); // Enqueue WordPress Script Dependencies wp_enqueue_script( 'wp-element' ); wp_enqueue_script( 'wp-components' ); wp_enqueue_script( 'wp-api-fetch' ); wp_enqueue_script( 'wp-i18n' ); // Enqueue App Script (Production React Bundle) $script_url = TRANSLATESENSE_PLUGIN_URL . 'assets/build/dashboard/index.js'; wp_enqueue_script( 'translatesense-admin-js', $script_url, $asset['dependencies'], $asset['version'], true ); $admin_url = admin_url(); // Localize Script (Step 1.1) wp_localize_script( 'translatesense-admin-js', 'TranslateSenseData', array( 'restUrl' => esc_url_raw( rest_url( 'translatesense/v1/' ) ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'polylangActive' => Polylang_Bridge::is_polylang_active(), 'connectorsUrl' => esc_url_raw( admin_url( 'options-connectors.php' ) ), 'pluginUrl' => TRANSLATESENSE_PLUGIN_URL, 'docsUrl' => defined( 'TRANSLATESENSE_DOCS_URL' ) ? TRANSLATESENSE_DOCS_URL : 'https://docs.dragwyb.com/', 'version' => TRANSLATESENSE_VERSION, 'adminUrl' => $admin_url, 'activeBuilders' => self::get_active_builders(), ) ); } /** * Get Dashboard Page URL with optional tab parameter. * * @param string $tab Optional tab name ('home', 'settings', 'gutenberg', 'elementor', 'cache') * @return string */ public static function get_dashboard_url( string $tab = '' ): string { $base_page = Polylang_Bridge::is_polylang_active() ? 'admin.php' : 'options-general.php'; $url = admin_url( $base_page . '?page=translatesense' ); if ( ! empty( $tab ) ) { $url = add_query_arg( 'tab', $tab, $url ); } return $url; } /** * Render React root container. */ public static function render_admin_root() { ?>

id === self::$page_hook ) { return true; } if ( false !== strpos( $screen->id, 'translatesense' ) ) { return true; } } } return false; } /** * Hide unrelated third-party and core admin notices on all plugin pages. * * @return void */ public static function hide_unrelated_admin_notices() { if ( ! self::is_plugin_admin_page() ) { return; } global $wp_filter; $notice_hooks = array( 'user_admin_notices', 'admin_notices', 'all_admin_notices', ); foreach ( $notice_hooks as $hook_name ) { if ( empty( $wp_filter[ $hook_name ] ) || empty( $wp_filter[ $hook_name ]->callbacks ) || ! is_array( $wp_filter[ $hook_name ]->callbacks ) ) { continue; } foreach ( $wp_filter[ $hook_name ]->callbacks as $priority => $callbacks ) { foreach ( $callbacks as $callback_id => $callback_data ) { if ( empty( $callback_data['function'] ) ) { continue; } unset( $wp_filter[ $hook_name ]->callbacks[ $priority ][ $callback_id ] ); } } } // Remove delayed admin notices generated by WordPress. if ( isset( $wp_filter['admin_footer']->callbacks ) && is_array( $wp_filter['admin_footer']->callbacks ) ) { foreach ( $wp_filter['admin_footer']->callbacks as $priority => $callbacks ) { foreach ( $callbacks as $callback_id => $callback_data ) { if ( isset( $callback_data['function'] ) && 'render_delayed_admin_notices' === $callback_data['function'] ) { unset( $wp_filter['admin_footer']->callbacks[ $priority ][ $callback_id ] ); } } } } // Register this plugin's notices after unrelated notices have been removed. // phpcs:ignore WordPress.Security.NonceVerification.Recommended $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; add_action( 'admin_notices', function () use ( $page ) { self::display_admin_notices( $page ); }, PHP_INT_MAX ); } /** * Display plugin-specific admin notices. * * @param string $current_page Current admin page slug. * @return void */ public static function display_admin_notices( $current_page = '' ) { do_action( 'translatesense_admin_notices', $current_page ); } }