Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpmlsupp_translate_global_section_id( $is_translatable, $job_translate ) {
- if ( strpos( $job_translate["field_type"], 'mfn_global_section_id' ) !== false ) {
- $data = $job_translate['field_data'];
- if ( 'base64' === $job_translate['field_format'] ) {
- $data = base64_decode( $data );
- }
- if ( is_numeric( $data ) ) {
- return true;
- }
- }
- return $is_translatable;
- }
- add_filter( 'wpml_tm_job_field_is_translatable', 'wpmlsupp_translate_global_section_id', 10, 2 );
- function set_tr_global_id( $job_id ) {
- global $wpdb;
- // Prepare the query to prevent SQL injection
- $results = $wpdb->get_results($wpdb->prepare(
- "SELECT `field_data`, `tid` FROM {$wpdb->prefix}icl_translate WHERE `field_type` LIKE %s AND `job_id` = %d",
- '%mfn_global_section_id',
- $job_id
- ));
- // Check if results are found
- if ($results) {
- foreach ($results as $row) {
- $data = base64_decode($row->field_data);
- $type = get_post_type($data);
- // Verify if the post type exists
- if ($type) {
- $language_code = isset($_GET["language_code"]) ? $_GET["language_code"] : null;
- // Apply the filter with additional checks
- $tr = base64_encode(apply_filters('wpml_object_id', $data, $type, true, $language_code));
- // Update the translated field data
- $wpdb->query($wpdb->prepare(
- "UPDATE {$wpdb->prefix}icl_translate SET `field_data_translated` = %s, `field_finished` = 1 WHERE `job_id` = %d AND `tid` = %d",
- $tr,
- $job_id,
- $row->tid
- ));
- }
- }
- }
- }
- add_action('wpml_added_local_translation_job', 'set_tr_global_id');
Add Comment
Please, Sign In to add comment