'; $return_button .= ''; $return_button .= ''; $all_languages_button = ' 'WPLNG_TRANSLATION_ID', 'action' => 'edit', ), get_admin_url() . 'post.php' ); $edit_link_button = ''; $html .= ''; $html .= ''; $html .= ''; $html .= ' '; $html .= esc_html__( 'Edit translation', 'wplingua' ); $html .= ''; $html .= $all_languages_button; $html .= $edit_link_button; $html .= $return_button; $html .= ''; $html .= ''; $html .= ''; $html .= ''; // End #wplng-translation-editor $html .= ''; $html .= esc_html__( 'Save', 'wplingua' ); $html .= ''; $html .= ''; // End #wplng-modal-edit-main $html .= ''; // End #wplng-modal-edit $html .= ''; // End #wplng-modal-edit-container return $html; } /** * Send the translation editor HTML for AJAX call * * @return void */ function wplng_ajax_edit_modal() { /** * Check and sanitize data */ if ( empty( $_POST['post_id'] ) || ! current_user_can( 'edit_post', absint( $_POST['post_id'] ) ) ) { wp_send_json_error( __( 'Invalid translation ID', 'wplingua' ) ); return; } /** * Get and check the translation post */ $translation_post = get_post( absint( $_POST['post_id'] ) ); if ( empty( $translation_post ) ) { wp_send_json_error( __( 'Invalid translation post', 'wplingua' ) ); return; } /** * Get the translation editor HTML */ $data['wplng_edit_html'] = wplng_translation_editor_get_html( $translation_post ); /** * Send the translation editor HTML */ wp_send_json_success( wp_json_encode( $data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) ); } /** * Save translation on AJAX call of modal edit * * Process the AJAX request to save a translation from modal edit, * validate and sanitize the input data, and call the function to * save the translation. * * @return void */ function wplng_ajax_save_modal() { /** * Check and sanitize data * * Check that the post ID and current user can edit the post * before attempting to save the translation. */ if ( empty( $_POST['post_id'] ) || ! current_user_can( 'edit_post', absint( $_POST['post_id'] ) ) ) { wp_send_json_error( __( 'Invalid translation ID', 'wplingua' ) ); return; } /** * Try to save the post * * Call the function to save the translation and store the result * in variable $saved. */ $saved = wplng_translation_save_meta_boxes_data( absint( $_POST['post_id'] ) ); /** * Send AJAX success or error * * If the saving was successful, send a JSON success response. * Otherwise, send a JSON error response with a message. */ if ( $saved ) { wp_send_json_success( null ); } else { wp_send_json_error( __( 'Translation saving failed', 'wplingua' ) ); return; } }