menus-sync.php
10.2 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
global $icl_menus_sync, $sitepress;
/** @var SitePress $sitepress */
/** @var ICLMenusSync $icl_menus_sync */
$active_languages = $sitepress->get_active_languages();
$def_lang_code = $sitepress->get_default_language();
$def_lang = $sitepress->get_language_details( $def_lang_code );
$secondary_languages = array();
$documentation_link = 'https://wpml.org/documentation/getting-started-guide/translating-menus/?utm_source=plugin&utm_medium=gui&utm_campaign=menu-sync#option-3-automatic-menus-sync-by-wpml';
foreach ( $active_languages as $code => $lang ) {
if ( $code !== $def_lang_code ) {
$secondary_languages[] = $lang;
}
}
?>
<!--suppress HtmlFormInputWithoutLabel --><!--suppress HtmlUnknownAttribute -->
<div class="wrap">
<h2><?php esc_html_e( 'WP Menus Sync', 'sitepress' ); ?></h2>
<p>
<?php
echo wp_kses(
sprintf(
/* translators: %1$s and %2$s are opening and closing link tags, %3$s is the default language name. */
__( '%1$sMenu synchronization%2$s will sync the menu structure from the default language of %3$s to the secondary languages.', 'sitepress' ),
'<a href="' . esc_url( $documentation_link ) . '" target="_blank">',
'</a>',
esc_html( $def_lang['display_name'] )
),
[
'a' => [
'href' => [],
'target' => [],
],
]
);
?>
</p>
<br/>
<?php
if ( $icl_menus_sync->is_preview ) {
?>
<form id="icl_msync_confirm_form" method="post">
<input type="hidden" name="action" value="icl_msync_confirm"/>
<table id="icl_msync_confirm" class="widefat icl_msync">
<thead>
<tr>
<th scope="row" class="menu-check-all"><input type="checkbox"/></th>
<th><?php esc_html_e( 'Language', 'sitepress' ); ?></th>
<th><?php esc_html_e( 'Action', 'sitepress' ); ?></th>
</tr>
</thead>
<tbody>
<?php
$menu_id = null;
if ( empty( $icl_menus_sync->sync_data ) ) {
?>
<tr>
<td align="center" colspan="3"><?php esc_html_e( 'Nothing to sync.', 'sitepress' ); ?></td>
</tr>
<?php
} else {
// Menus
foreach ( $icl_menus_sync->menus as $menu_id => $menu ) {
$menu_sync_display = new WPML_Menu_Sync_Display( $menu_id, $icl_menus_sync );
?>
<tr class="icl_msync_menu_title">
<td colspan="3"><?php echo esc_html( $menu['name'] ); ?></td>
</tr>
<?php
// Display actions per menu
// menu translations
if ( isset( $icl_menus_sync->sync_data['menu_translations'], $icl_menus_sync->sync_data['menu_translations'][ $menu_id ] ) ) {
foreach ( $icl_menus_sync->sync_data['menu_translations'][ $menu_id ] as $language => $name ) {
$lang_details = $sitepress->get_language_details( $language );
?>
<tr>
<th scope="row" class="check-column">
<input type="checkbox"
name="sync[menu_translation][<?php echo esc_attr( $menu_id ); ?>][<?php echo esc_attr( $language ); ?>]"
value="<?php echo esc_attr( $name ); ?>"/>
</th>
<td><?php echo esc_html( $lang_details['display_name'] ); ?></td>
<td><?php printf( esc_html__( 'Add menu translation: %s', 'sitepress' ), '<strong>' . esc_html( $name ) . '</strong>' ); ?> </td>
</tr>
<?php
}
}
foreach (
array(
'add',
'mov',
'del',
'label_changed',
'url_changed',
'label_missing',
'url_missing',
'options_changed',
) as $sync_type
) {
$menu_sync_display->print_sync_field( $sync_type );
}
}
}
?>
</tbody>
</table>
<p class="submit">
<?php
$icl_menu_sync_submit_disabled = '';
if ( empty( $icl_menus_sync->sync_data ) || ( empty( $icl_menus_sync->sync_data['mov'] ) && empty( $icl_menus_sync->sync_data['mov'][ $menu_id ] ) ) ) {
$icl_menu_sync_submit_disabled = 'disabled="disabled"';
}
?>
<input id="icl_msync_submit"
class="button-primary"
type="button"
value="<?php esc_attr_e( 'Apply changes', 'sitepress' ); ?>"
data-message="<?php esc_attr_e( 'Syncing menus %1 of %2', 'sitepress' ); ?>"
data-message-complete="<?php esc_attr_e( 'The selected menus have been synchonized.', 'sitepress' ); ?>"
<?php echo $icl_menu_sync_submit_disabled; ?> />
<input id="icl_msync_cancel" class="button-secondary" type="button" value="<?php _e( 'Cancel', 'sitepress' ); ?>"/>
<span id="icl_msync_message"></span>
</p>
<?php wp_nonce_field( '_icl_nonce_menu_sync', '_icl_nonce_menu_sync' ); ?>
</form>
<?php
} else {
$need_sync = 0;
?>
<form method="post" action="">
<input type="hidden" name="action" value="icl_msync_preview"/>
<table class="widefat icl_msync">
<thead>
<tr>
<th><?php echo esc_html( $def_lang['display_name'] ); ?></th>
<?php
if ( ! empty( $secondary_languages ) ) {
foreach ( $secondary_languages as $lang ) {
?>
<th><?php echo esc_html( $lang['display_name'] ); ?></th>
<?php
}
}
?>
</tr>
</thead>
<tbody>
<?php
if ( empty( $icl_menus_sync->menus ) ) {
?>
<tr>
<td align="center" colspan="<?php echo count( $active_languages ); ?>"><?php esc_html_e( 'No menus found', 'sitepress' ); ?></td>
</tr>
<?php
} else {
foreach ( $icl_menus_sync->menus as $menu_id => $menu ) {
?>
<tr class="icl_msync_menu_title">
<td><strong><?php echo esc_html( $menu['name'] ); ?></strong></td>
<?php
foreach ( $secondary_languages as $l ) {
$input_name = sprintf( 'sync[menu_options][%s][%s][auto_add]', esc_attr( $menu_id ), esc_attr( $l['code'] ) );
?>
<td>
<?php
if ( isset( $menu['translations'][ $l['code'] ]['name'] ) ) {
echo esc_html( $menu['translations'][ $l['code'] ]['name'] );
} else { // menu is translated in $l[code]
$need_sync++;
?>
<input type="text" class="icl_msync_add"
name="sync[menu_translations][<?php echo esc_attr( $menu_id ); ?>][<?php echo esc_attr( $l['code'] ); ?>]"
value="<?php echo esc_attr( $menu['name'] ) . ' - ' . esc_attr( $l['display_name'] ); ?>"
/>
<small><?php esc_html_e( 'Auto-generated title. Click to edit.', 'sitepress' ); ?></small>
<input type="hidden" value=""
name="<?php echo $input_name; ?>"
/>
<?php
}
if ( isset( $menu['translations'][ $l['code'] ]['auto_add'] ) ) {
?>
<input type="hidden" name="<?php echo $input_name; ?>" value="<?php echo esc_attr( $menu['translations'][ $l['code'] ]['auto_add'] ); ?>"/>
<?php
}
?>
</td>
<?php
} //foreach($secondary_languages as $l):
?>
</tr>
<?php
$need_sync += $icl_menus_sync->render_items_tree_default( $menu_id );
} //foreach( $icl_menus_sync->menus as $menu_id => $menu):
}
?>
</tbody>
</table>
<p class="submit">
<?php
if ( $need_sync ) {
?>
<input id="icl_msync_sync" type="submit" class="button-primary"
value="<?php esc_attr_e( 'Sync', 'sitepress' ); ?>"
<?php disabled( ! $need_sync ); ?>
/>
<span id="icl_msync_max_input_vars"
style="display:none"
class="icl-admin-message-warning"
data-max_input_vars="
<?php
//phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound -- It never caused issues, but we should probably fix that
echo ini_get( 'max_input_vars' );
//phpcs:enable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
?>
">
<?php
printf(
esc_html__( 'The menus on this page may not sync because it requires more input variables. Please modify the %1$s setting in your php.ini or .htaccess files to %2$s or more.', 'sitepress' ),
'<strong>max_input_vars</strong>',
'<strong>!NUM!</strong>'
)
?>
</span>
<?php
} else {
?>
<input id="icl_msync_sync" type="submit" class="button-primary"
value="<?php esc_attr_e( 'Nothing Sync', 'sitepress' ); ?>"<?php disabled( ! $need_sync ); ?>
/>
<?php
}
?>
</p>
<?php wp_nonce_field( '_icl_nonce_menu_sync', '_icl_nonce_menu_sync' ); ?>
</form>
<?php
if ( ! empty( $icl_menus_sync->operations ) ) {
$show_string_translation_link = false;
foreach ( $icl_menus_sync->operations as $op => $c ) {
if ( 'add' === $op ) {
?>
<span class="icl_msync_item icl_msync_add"><?php esc_html_e( 'Item will be added', 'sitepress' ); ?></span>
<?php
} elseif ( 'del' === $op ) {
?>
<span class="icl_msync_item icl_msync_del"><?php esc_html_e( 'Item will be removed', 'sitepress' ); ?></span>
<?php
} elseif ( 'not' === $op ) {
?>
<span class="icl_msync_item icl_msync_not"><?php esc_html_e( 'Item cannot be added (parent not translated)', 'sitepress' ); ?></span>
<?php
} elseif ( 'mov' === $op ) {
?>
<span class="icl_msync_item icl_msync_mov"><?php esc_html_e( 'Item changed position', 'sitepress' ); ?></span>
<?php
} elseif ( 'copy' === $op ) {
?>
<span class="icl_msync_item icl_msync_copy"><?php esc_html_e( 'Item will be copied', 'sitepress' ); ?></span>
<?php
} elseif ( 'label_changed' === $op ) {
?>
<span class="icl_msync_item icl_msync_label_changed"><?php esc_html_e( 'Strings for menus will be updated', 'sitepress' ); ?></span>
<?php
} elseif ( 'url_changed' === $op ) {
?>
<span class="icl_msync_item icl_msync_url_changed"><?php esc_html_e( 'URLs for menus will be updated', 'sitepress' ); ?></span>
<?php
} elseif ( 'options_changed' === $op ) {
?>
<span class="icl_msync_item icl_msync_options_changed"><?php esc_html_e( 'Menu Options will be updated', 'sitepress' ); ?></span>
<?php
} elseif ( 'label_missing' === $op ) {
?>
<span class="icl_msync_item icl_msync_label_missing">
<?php esc_html_e( 'Untranslated strings for menus', 'sitepress' ); ?>
</span>
<?php
} elseif ( 'url_missing' === $op ) {
?>
<span class="icl_msync_item icl_msync_url_missing">
<?php esc_html_e( 'Untranslated URLs for menus', 'sitepress' ); ?>
</span>
<?php
}
}
}
$icl_menus_sync->display_menu_links_to_string_translation();
}
do_action( 'icl_menu_footer' );
?>
</div>