C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\penci-smart-lists\lib\meta-box\inc\wpml.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
 * The WPML compatibility module, allowing all fields are translatable by WPML plugin.
 *
 * @package Meta Box
 */

/**
 * WPML compatibility class
 */
class RWMB_WPML {
    
/**
     * List of fields that need to translate values (because they're saved as IDs).
     *
     * @var array
     */
    
protected $field_types = array( 'post''taxonomy_advanced' );

    
/**
     * Initialize.
     */
    
public function init() {
        
/**
         * Run before meta boxes are registered so it can modify fields.
         *
         * @see modify_field()
         */
        
add_action'init', array( $this'register_hooks' ), );
    }

    
/**
     * Register hooks.
     */
    
public function register_hooks() {
        if ( ! 
defined'ICL_SITEPRESS_VERSION' ) ) {
            return;
        }
        
add_filter'wpml_duplicate_generic_string', array( $this'translate_ids' ), 10);
        
add_filter'rwmb_normalize_field', array( $this'modify_field' ) );
    }

    
/**
     * Translating IDs stored as field values upon WPML post/page duplication.
     *
     * @param mixed  $value           Meta value.
     * @param string $target_language Target language.
     * @param array  $meta_data       Meta arguments.
     * @return mixed
     */
    
public function translate_ids$value$target_language$meta_data ) {
        if ( 
'custom_field' !== $meta_data['context'] ) {
            return 
$value;
        }

        
$field rwmb_get_registry'field' )->get$meta_data['key'], get_post_type$meta_data['master_post_id'] ) );
        if ( 
false === $field || ! in_array$field['type'], $this->field_typestrue ) ) {
            return 
$value;
        }

        
// Object type needed for WPML filter differs between fields.
        
$object_type 'taxonomy_advanced' === $field['type'] ? $field['taxonomy'] : $field['post_type'];

        
// Translating values, whether are stored as comma separated strings or not.
        
if ( false === strpos$value',' ) ) {
            
$value apply_filters'wpml_object_id'$value$object_typetrue$target_language );
            return 
$value;
        }

        
// Dealing with IDs stored as comma separated strings.
        
$translated_values = array();
        
$values            explode','$value );

        foreach ( 
$values as $v ) {
            
$translated_values[] = apply_filters'wpml_object_id'$v$object_typetrue$target_language );
        }

        
$value implode','$translated_values );
        return 
$value;
    }

    
/**
     * Modified field depends on its translation status.
     * If the post is a translated version of another post and the field is set to:
     * - Do not translate: hide the field.
     * - Copy: make it disabled so users cannot edit.
     * - Translate: do nothing.
     *
     * @param array $field Field parameters.
     *
     * @return mixed
     */
    
public function modify_field$field ) {
        global 
$wpml_post_translations;

        if ( empty( 
$field['id'] ) ) {
            return 
$field;
        }

        
// Get post ID.
        
$post_id filter_inputINPUT_GET'post'FILTER_SANITIZE_NUMBER_INT );
        if ( ! 
$post_id ) {
            
$post_id filter_inputINPUT_POST'post_ID'FILTER_SANITIZE_NUMBER_INT );
        }

        
// If the post is the original one: do nothing.
        
if ( ! $wpml_post_translations->get_source_lang_code$post_id ) ) {
            return 
$field;
        }

        
// Get setting for the custom field translation.
        
$custom_fields_translation apply_filters'wpml_sub_setting'false'translation-management''custom_fields_translation' );
        if ( ! isset( 
$custom_fields_translation$field['id'] ] ) ) {
            return 
$field;
        }

        
$setting intval$custom_fields_translation$field['id'] ] );
        if ( 
=== $setting ) {           // Do not translate: hide it.
            
$field['class'] .= ' hidden';
        } elseif ( 
=== $setting ) {     // Copy: disable editing.
            
$field['disabled'] = true;
        }

        return 
$field;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586