Guest User

Untitled

a guest
Feb 5th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. function wpmlsupp_translate_global_section_id( $is_translatable, $job_translate ) {
  2. if ( strpos( $job_translate["field_type"], 'mfn_global_section_id' ) !== false ) {
  3. $data = $job_translate['field_data'];
  4. if ( 'base64' === $job_translate['field_format'] ) {
  5. $data = base64_decode( $data );
  6. }
  7. if ( is_numeric( $data ) ) {
  8. return true;
  9. }
  10. }
  11.  
  12. return $is_translatable;
  13. }
  14.  
  15. add_filter( 'wpml_tm_job_field_is_translatable', 'wpmlsupp_translate_global_section_id', 10, 2 );
  16.  
  17. function set_tr_global_id( $job_id ) {
  18. global $wpdb;
  19.  
  20. // Prepare the query to prevent SQL injection
  21. $results = $wpdb->get_results($wpdb->prepare(
  22. "SELECT `field_data`, `tid` FROM {$wpdb->prefix}icl_translate WHERE `field_type` LIKE %s AND `job_id` = %d",
  23. '%mfn_global_section_id',
  24. $job_id
  25. ));
  26.  
  27. // Check if results are found
  28. if ($results) {
  29. foreach ($results as $row) {
  30. $data = base64_decode($row->field_data);
  31. $type = get_post_type($data);
  32.  
  33. // Verify if the post type exists
  34. if ($type) {
  35. $language_code = isset($_GET["language_code"]) ? $_GET["language_code"] : null;
  36.  
  37. // Apply the filter with additional checks
  38. $tr = base64_encode(apply_filters('wpml_object_id', $data, $type, true, $language_code));
  39.  
  40. // Update the translated field data
  41. $wpdb->query($wpdb->prepare(
  42. "UPDATE {$wpdb->prefix}icl_translate SET `field_data_translated` = %s, `field_finished` = 1 WHERE `job_id` = %d AND `tid` = %d",
  43. $tr,
  44. $job_id,
  45. $row->tid
  46. ));
  47. }
  48. }
  49. }
  50. }
  51.  
  52. add_action('wpml_added_local_translation_job', 'set_tr_global_id');
Add Comment
Please, Sign In to add comment