class-wpml-tm-post-edit-custom-field-settings-menu.php
3.45 KB
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
<?php
/**
* Class WPML_TM_Post_Edit_Custom_Field_Settings_Menu
*/
class WPML_TM_Post_Edit_Custom_Field_Settings_Menu {
/** @var WPML_Custom_Field_Setting_Factory $setting_factory */
private $setting_factory;
/** @var WP_Post $post */
private $post;
private $rendered = false;
/**
* WPML_TM_Post_Edit_Custom_Field_Settings_Menu constructor.
*
* @param WPML_Custom_Field_Setting_Factory $settings_factory
* @param WP_Post $post
*/
public function __construct( &$settings_factory, $post ) {
$this->setting_factory = &$settings_factory;
$this->post = $post;
}
/**
* @return string
*/
public function render() {
$custom_keys = get_post_custom_keys( $this->post->ID );
$custom_keys = $this->setting_factory->filter_custom_field_keys( $custom_keys );
ob_start();
if ( 0 !== count( $custom_keys ) ) {
?>
<table class="widefat">
<thead>
<tr>
<th colspan="2"><?php esc_html_e( 'Custom fields', 'sitepress' ); ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ( $custom_keys as $cfield ) {
$field_setting = $this->setting_factory->post_meta_setting( $cfield );
if ( $field_setting->excluded() ) {
continue;
}
$this->rendered = true;
$radio_disabled = $field_setting->get_html_disabled();
$status = (int) $field_setting->status();
$states = array(
array( 'value' => WPML_IGNORE_CUSTOM_FIELD, 'text' => __( "Don't translate", 'sitepress' ) ),
array( 'value' => WPML_COPY_CUSTOM_FIELD, 'text' => __( "Copy", 'sitepress' ) ),
array( 'value' => WPML_COPY_ONCE_CUSTOM_FIELD, 'text' => __( "Copy once", 'sitepress' ) ),
array( 'value' => WPML_TRANSLATE_CUSTOM_FIELD, 'text' => __( "Translate", 'sitepress' ) ),
);
?>
<tr>
<td id="icl_mcs_cf_<?php echo esc_attr( base64_encode( $cfield ) ); ?>">
<div class="icl_mcs_cf_name">
<?php echo esc_html( $cfield ); ?>
</div>
<?php
/**
* Filter for custom field description in multilingual content setup metabox on post edit screen
*
* @param string $custom_field_description custom field description
* @param string $custom_field_name custom field name
* @param int $post_id current post ID
*/
$cfield_description = apply_filters( 'wpml_post_edit_settings_custom_field_description', "", $cfield, $this->post->ID );
if ( !empty( $cfield_description ) ) {
printf( '<div class="icl_mcs_cf_description">%s</div>', esc_html( $cfield_description ) );
}
?>
</td>
<td align="right">
<?php
foreach ( $states as $state ) {
$checked = $status == $state['value'] ? ' checked="checked"' : '';
?>
<label>
<input class="icl_mcs_cfs"
name="icl_mcs_cf_<?php echo esc_attr( base64_encode( $cfield ) ); ?>"
type="radio"
value="<?php echo esc_attr( (string) $state['value'] ); ?>" <?php echo esc_attr( $radio_disabled . $checked ); ?>
/>
<?php echo esc_html( $state['text'] ) ?>
</label>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<br/>
<?php
}
return ob_get_clean();
}
/**
* @return bool true if there were actual custom fields to display options for
*/
public function is_rendered() {
return $this->rendered;
}
}