$is_aiutoma_wpml, 'isNativeWpmlJobs' => $is_native_wpml_jobs, 'injectButtons' => false, 'nonce' => wp_create_nonce('wp_rest'), 'restGetMissingUrl' => esc_url_raw(rest_url('aiutoma/v1/wpml-get-missing')), 'restTranslateUrl' => esc_url_raw(rest_url('aiutoma/v1/wpml-translate')), 'restStringsGetMissingUrl' => esc_url_raw(rest_url('aiutoma/v1/wpml-strings-get-missing')), 'restStringsTranslateUrl' => esc_url_raw(rest_url('aiutoma/v1/wpml-strings-translate')), 'restXliffGetJobsUrl' => esc_url_raw(rest_url('aiutoma/v1/wpml-xliff-jobs')), 'restXliffTranslateUrl' => esc_url_raw(rest_url('aiutoma/v1/wpml-xliff-translate')), 'textScanning' => __('Scanning...', 'aiutoma'), 'textTranslate' => __('Translate via AI', 'aiutoma'), 'textTranslateAll' => __('Translate all missing fields via AI', 'aiutoma'), 'textError' => __('Translation failed', 'aiutoma'), /* translators: %d: number of missing languages */ 'textConfirm' => __('Translate %d missing languages?', 'aiutoma'), 'textAutoTranslate' => __('Update translations via AI automatically on save', 'aiutoma'), 'autoTranslateChecked' => '' ]; wp_localize_script('aiutoma-wpml-script', 'aiutomaWpmlData', $aiutomaWpmlData); } public function register_wpml_translate_route() { register_rest_route('aiutoma/v1', '/wpml-translate', [ 'methods' => 'POST', 'callback' => [$this, 'handle_wpml_translate'], 'permission_callback' => function () { return current_user_can('manage_options'); } ]); register_rest_route('aiutoma/v1', '/wpml-get-missing', [ 'methods' => 'GET', 'callback' => [$this, 'handle_wpml_get_missing'], 'permission_callback' => function () { return current_user_can('manage_options'); } ]); register_rest_route('aiutoma/v1', '/wpml-strings-get-missing', [ 'methods' => 'GET', 'callback' => [$this, 'handle_wpml_strings_get_missing'], 'permission_callback' => function () { return current_user_can('manage_options'); } ]); register_rest_route('aiutoma/v1', '/wpml-strings-translate', [ 'methods' => 'POST', 'callback' => [$this, 'handle_wpml_strings_translate'], 'permission_callback' => function () { return current_user_can('manage_options'); } ]); if (method_exists($this, 'register_xliff_routes')) { $this->register_xliff_routes(); } } public function add_wpml_ai_menu() { // Register using WPML's native custom menu API do_action('wpml_admin_menu_register_item', [ 'order' => 800, 'page_title' => __('AI Translator', 'aiutoma'), 'menu_title' => __('AI Translator', 'aiutoma'), 'capability' => 'manage_options', 'menu_slug' => 'aiutoma-wpml', 'function' => [$this, 'render_wpml_bulk_page'] ]); } public function render_wpml_bulk_page() { // phpcs:ignore WordPress.Security.NonceVerification.Missing if (isset($_POST['aiutoma_wpml_settings_nonce'])) { $this->handle_settings_post(); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $active_tab = isset($_GET['tab']) ? sanitize_text_field(wp_unslash($_GET['tab'])) : 'translate'; $has_strings = method_exists($this, 'aiutoma_wpml_has_strings') && $this->aiutoma_wpml_has_strings(); if (defined('ICL_PLUGIN_URL')) { wp_enqueue_style('wpml-dashboard', ICL_PLUGIN_URL . '/vendor/wpml/wpml/public/css/dashboard.css', [], '1.0.0'); } elseif (defined('WPML_PLUGIN_URL')) { wp_enqueue_style('wpml-dashboard', WPML_PLUGIN_URL . '/vendor/wpml/wpml/public/css/dashboard.css', [], '1.0.0'); } ?>

render_content_tab(); } elseif ($active_tab === 'strings' && method_exists($this, 'render_strings_tab')) { $this->render_strings_tab(); } elseif ($active_tab === 'xliff' && method_exists($this, 'render_xliff_tab')) { $this->render_xliff_tab(); } elseif ($active_tab === 'context' && method_exists($this, 'render_context_tab')) { $this->render_context_tab(); } elseif ($active_tab === 'settings' && method_exists($this, 'render_settings_tab')) { $this->render_settings_tab(); } elseif ($active_tab === 'logs' && method_exists($this, 'render_logs_tab')) { $this->render_logs_tab(); } ?>
is_block_editor()) { return; } global $sitepress; if (!$sitepress) return; $post = get_post(); if (!$post) return; $el_type = 'post_' . $post->post_type; $default_lang = $sitepress->get_default_language(); $post_lang = $sitepress->get_language_for_element($post->ID, $el_type); if ($post_lang === $default_lang) { $trid = $sitepress->get_element_trid($post->ID, $el_type); if ($trid) { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $has_translations = $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}icl_translations WHERE trid = %d AND language_code != %s", $trid, $default_lang )); // Only show if the post has existing translations if ($has_translations > 0) { wp_nonce_field('aiutoma_wpml_auto_translate', 'aiutoma_wpml_auto_translate_nonce'); } } } } public function save_auto_translation_meta($post_id, $post) { if (!isset($_POST['aiutoma_wpml_auto_translate_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['aiutoma_wpml_auto_translate_nonce'])), 'aiutoma_wpml_auto_translate')) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (isset($_POST['aiutoma_wpml_auto_retranslate'])) { // We set a temporary transient or post meta so the post_updated hook (schedule_translation_updates) can read it update_post_meta($post_id, '_aiutoma_wpml_force_retranslate', '1'); } else { delete_post_meta($post_id, '_aiutoma_wpml_force_retranslate'); } } }