sitepress = $sitepress; } public function add_hooks() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'wpml_before_post_edit_translations_table', array( $this, 'add_ui' ) ); add_action( 'wpml_before_post_edit_translations_summary', array( $this, 'add_ui' ) ); add_action( 'wp_ajax_wpml-tm-editor-mode', array( $this, 'save_mode' ) ); } public function enqueue_scripts() { wp_register_script( self::SCRIPT_HANDLE, WPML_TM_URL . '/dist/js/postEditTranslationEditor/app.js', array( 'jquery-ui-dialog' ), WPML_TM_VERSION, true ); wp_enqueue_script( self::SCRIPT_HANDLE ); wp_enqueue_style( 'otgs-switcher' ); } public function add_ui( WP_Post $post ) { $this->prevent_displaying_ui_twice(); $is_source = $this->sitepress->is_original_content_filter( false, $post->ID, 'post_' . $post->post_type ); if ( $is_source ) { $this->add_checkbox( $post ); $this->add_dialog( $post ); } } private function prevent_displaying_ui_twice() { remove_action( 'wpml_before_post_edit_translations_table', array( $this, 'add_ui' ) ); remove_action( 'wpml_before_post_edit_translations_summary', array( $this, 'add_ui' ) ); } private function add_checkbox( WP_Post $post ) { $wpml_tm_editor = esc_html__( "Use WPML's Translation Editor", 'wpml-translation-management' ); $checked = WPML_TM_Post_Edit_TM_Editor_Mode::is_using_tm_editor( $this->sitepress, $post->ID ) ? 'checked' : ''; ?>
>
post_type ]->labels->singular_name ); $post_label_plural = sprintf( /* translators: %s: Post name plural */ esc_html__( 'All %s', 'wpml-translation-management' ), $wp_post_types[ $post->post_type ]->labels->name ); $all_site_content = esc_html__( "All the site's content", 'wpml-translation-management' ); $nonce = wp_create_nonce( self::NONCE_ACTION ); ?> sitepress->get_setting( 'translation-management' ); $use_native_editor = 'false' === $_POST['useTMEditor']; $post_id = filter_var( $_POST['postId'], FILTER_SANITIZE_NUMBER_INT ); switch ( $_POST['mode'] ) { case 'global': $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_GLOBAL_USE_NATIVE ] = $use_native_editor; $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_FOR_POST_TYPE_USE_NATIVE ] = array(); $this->sitepress->set_setting( 'translation-management', $tm_settings, true ); WPML_TM_Post_Edit_TM_Editor_Mode::delete_all_posts_option(); break; case 'all_posts_of_type': $post_type = get_post_type( $post_id ); $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_FOR_POST_TYPE_USE_NATIVE ][ $post_type ] = $use_native_editor; $this->sitepress->set_setting( 'translation-management', $tm_settings, true ); WPML_TM_Post_Edit_TM_Editor_Mode::delete_all_posts_option( $post_type ); break; case 'this_post': update_post_meta( $post_id, WPML_TM_Post_Edit_TM_Editor_Mode::POST_META_KEY_USE_NATIVE, $use_native_editor ? 'yes' : 'no' ); break; } } wp_send_json_success(); } }