Add an action hook in Save translations for editor api
-
Hello! Translatepress,
Thanks for your amazing creation. My colleagues love it.
At the moment, we are creating a plugin that could update Translatepress translation of custom fields in product inventory. This part works great by using functions in class-query.phpOn the other part, after customer edit same translated text in Translatepress editor, it saves the text through ajax API in class-editor-api-regular-strings.php with action method save_translations.
We would like to add support so that by the time the save translations is called, additional action could be done such as updating back to the custom fields in our case so that the 2-ways update(both direction) will be completed. As a result, the customer does not need to update the custom fields by jumping back to the product inventory. They could manage it in both place.
So we would like to propose the following changes for you to review.
The following is an example for regular text saving logic.
It might be good to add to gettext also for future use cases, there are lots of possibilities./* * Save translations from ajax post. * * Hooked to wp_ajax_trp_save_translations_regular. */ public function save_translations(){ if ( defined( 'DOING_AJAX' ) && DOING_AJAX && current_user_can( apply_filters( 'trp_translating_capability', 'manage_options' ) ) ) { check_ajax_referer( 'save_translations', 'security' ); if ( isset( $_POST['action'] ) && $_POST['action'] === 'trp_save_translations_regular' && !empty( $_POST['strings'] ) ) { $strings = json_decode(stripslashes($_POST['strings'])); $this->save_translations_of_strings( $strings ); } } do_actions( 'save_translations_extra_actions' ); echo trp_safe_json_encode( array() ); die(); }
`
do_actions( 'save_translations_extra_actions' );
will be very handy because it allows additional operation while allow custom checking and logic.Or if translatepress already have other way(s) to accomplish the same thing, it would be grateful if you could share and point the direction.
Thanks a lot!
- The topic ‘Add an action hook in Save translations for editor api’ is closed to new replies.