ACF qTranslate - Version 1.4

Version Description

Updated with support for Advanced Customs Fields v5 Tested using mqTranslate in place of qTranslate

Download this release

Release Info

Developer funkjedi
Plugin Icon wp plugin ACF qTranslate
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

acf-qtranslate.php CHANGED
@@ -3,7 +3,7 @@
3
Plugin Name: Advanced Custom Fields: qTranslate
4
Plugin URI: http://github.com/funkjedi/acf-qtranslate
5
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
6
- Version: 1.3.0
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
@@ -12,39 +12,25 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
13
// http://support.advancedcustomfields.com/discussion/1181/prease-check-wp3-3-qtranslate-advance-custom-field/p1
14
15
16
- function acf_qtranslate_enabled() {
17
- return function_exists('qtrans_getSortedLanguages');
18
- }
19
-
20
- add_action('acf/register_fields', 'acf_qtranslate_plugin_register_fields');
21
- function acf_qtranslate_plugin_register_fields() {
22
-
23
- require_once dirname(__FILE__) . '/fields/text.php';
24
- require_once dirname(__FILE__) . '/fields/textarea.php';
25
- require_once dirname(__FILE__) . '/fields/wysiwyg.php';
26
- require_once dirname(__FILE__) . '/fields/image.php';
27
28
}
29
30
- add_action('admin_enqueue_scripts', 'acf_qtranslate_admin_enqueue_scripts');
31
- function acf_qtranslate_admin_enqueue_scripts() {
32
- wp_enqueue_style('acf_qtranslate_main', plugins_url('/assets/main.css', __FILE__));
33
- wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/main.js', __FILE__));
34
}
35
36
37
38
- // enable qtranslate quicktags for all string based fields
39
- add_filter('acf/format_value_for_api', 'acf_qtranslate_plugin_format_value_for_api');
40
- function acf_qtranslate_plugin_format_value_for_api($value) {
41
- if (acf_qtranslate_enabled() && is_string($value)) {
42
- $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
43
- }
44
-
45
- return $value;
46
- }
47
-
48
49
add_action('plugins_loaded', 'acf_qtranslate_monkey_patch', 3);
50
function acf_qtranslate_monkey_patch() {
3
Plugin Name: Advanced Custom Fields: qTranslate
4
Plugin URI: http://github.com/funkjedi/acf-qtranslate
5
Description: Provides multilingual versions of the text, text area, and wysiwyg fields.
6
+ Version: 1.4
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
12
13
// http://support.advancedcustomfields.com/discussion/1181/prease-check-wp3-3-qtranslate-advance-custom-field/p1
14
15
+ require_once dirname(__FILE__) . '/v4/init.php';
16
+ require_once dirname(__FILE__) . '/v5/init.php';
17
18
19
+ function acf_qtranslate_enabled() {
20
+ return function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage');
21
}
22
23
+ function acf_qtranslate_acf_major_version() {
24
+ if (function_exists('acf')) {
25
+ $acf = acf();
26
+ return (int) $acf->settings['version'][0];
27
+ }
28
+ return '';
29
}
30
31
32
33
+ // qTranslate Monkey Patches
34
35
add_action('plugins_loaded', 'acf_qtranslate_monkey_patch', 3);
36
function acf_qtranslate_monkey_patch() {
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
Contributors: funkjedi
3
Tags: acf, advanced custom fields, qtranslate, add-on, admin
4
Requires at least: 3.0.0
5
- Tested up to: 3.7.1
6
- Version: 1.3
7
- Stable tag: 1.3
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -48,6 +48,10 @@ The plugin is based on code samples posted to the [ACF support forums](http://ol
48
49
== Changelog ==
50
51
= 1.3 =
52
Updated styles for Wordpress 3.8
53
Updated monkey patch qTranslate to fix [bug with multiple WYSIWYG editors](https://github.com/funkjedi/acf-qtranslate/issues/2#issuecomment-37612918)
2
Contributors: funkjedi
3
Tags: acf, advanced custom fields, qtranslate, add-on, admin
4
Requires at least: 3.0.0
5
+ Tested up to: 3.9.2
6
+ Version: 1.4
7
+ Stable tag: 1.4
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
48
49
== Changelog ==
50
51
+ = 1.4 =
52
+ Updated with support for Advanced Customs Fields v5
53
+ Tested using mqTranslate in place of qTranslate
54
+
55
= 1.3 =
56
Updated styles for Wordpress 3.8
57
Updated monkey patch qTranslate to fix [bug with multiple WYSIWYG editors](https://github.com/funkjedi/acf-qtranslate/issues/2#issuecomment-37612918)
assets/main.css → v4/assets/input.css RENAMED
@@ -1,7 +1,5 @@
1
2
3
- #edit-slug-box { margin-top: -15px; }
4
-
5
.qtrans_title_wrap {
6
margin-bottom: 20px;
7
padding: 0 !important;
@@ -20,6 +18,14 @@
20
21
.acf_wysiwyg .wp-editor-container { border: 1px solid #e5e5e5 !important; }
22
23
.multi-language-field .wp-switch-editor {
24
border-color: #dedede;
25
position: relative;
1
2
3
.qtrans_title_wrap {
4
margin-bottom: 20px;
5
padding: 0 !important;
18
19
.acf_wysiwyg .wp-editor-container { border: 1px solid #e5e5e5 !important; }
20
21
+ .multi-language-field {
22
+ margin-top: -38px;
23
+ }
24
+
25
+ .acf-input-table .multi-language-field {
26
+ margin-top: -6px;
27
+ }
28
+
29
.multi-language-field .wp-switch-editor {
30
border-color: #dedede;
31
position: relative;
assets/main.js → v4/assets/input.js RENAMED
File without changes
{fields → v4/fields}/image.php RENAMED
File without changes
{fields → v4/fields}/text.php RENAMED
File without changes
{fields → v4/fields}/textarea.php RENAMED
File without changes
{fields → v4/fields}/wysiwyg.php RENAMED
File without changes
v4/init.php ADDED
@@ -0,0 +1,25 @@
1
+ <?php
2
+
3
+ add_action('admin_enqueue_scripts', 'acf_qtranslate_v4_admin_enqueue_scripts');
4
+ function acf_qtranslate_v4_admin_enqueue_scripts() {
5
+ if (acf_qtranslate_acf_major_version() === 4) {
6
+ wp_enqueue_style('acf_qtranslate_main', plugins_url('/assets/input.css', __FILE__));
7
+ wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/input.js', __FILE__));
8
+ }
9
+ }
10
+
11
+ add_action('acf/register_fields', 'acf_qtranslate_plugin_v4_register_fields');
12
+ function acf_qtranslate_plugin_v4_register_fields() {
13
+ require_once dirname(__FILE__) . '/fields/text.php';
14
+ require_once dirname(__FILE__) . '/fields/textarea.php';
15
+ require_once dirname(__FILE__) . '/fields/wysiwyg.php';
16
+ require_once dirname(__FILE__) . '/fields/image.php';
17
+ }
18
+
19
+ add_filter('acf/format_value_for_api', 'acf_qtranslate_plugin_v4_format_value_for_api');
20
+ function acf_qtranslate_plugin_v4_format_value_for_api($value) {
21
+ if (acf_qtranslate_enabled() && is_string($value)) {
22
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
23
+ }
24
+ return $value;
25
+ }
v5/assets/input.css ADDED
@@ -0,0 +1,90 @@
1
+
2
+
3
+ .qtrans_title_wrap {
4
+ margin-bottom: 20px;
5
+ padding: 0 !important;
6
+ border: 0 !important;
7
+ }
8
+
9
+ .qtrans_title_input {
10
+ padding: 3px 8px !important;
11
+ font-size: 1.7em;
12
+ line-height: 100%;
13
+ height: 1.7em;
14
+ outline: 0 !important;
15
+ margin: 0;
16
+ }
17
+
18
+
19
+ .acf-wysiwyg-wrap .wp-editor-container { border: 1px solid #e5e5e5 !important; }
20
+
21
+ .multi-language-field {
22
+ margin-top: -38px;
23
+ }
24
+
25
+ .acf-table .multi-language-field {
26
+ margin-top: -6px;
27
+ }
28
+
29
+ .multi-language-field .wp-switch-editor {
30
+ border-color: #dedede;
31
+ position: relative;
32
+ top: 1px;
33
+ z-index: 100;
34
+ }
35
+
36
+ .multi-language-field input,
37
+ .multi-language-field input:focus,
38
+ .multi-language-field textarea,
39
+ .multi-language-field textarea:focus {
40
+ border-color: #ddd;
41
+ box-shadow: none;
42
+ }
43
+
44
+ .multi-language-field.focused .wp-switch-editor {
45
+ border-bottom-color: #ddd;
46
+ }
47
+
48
+ .multi-language-field.focused .wp-switch-editor.current-language {
49
+ border-color: #ddd;
50
+ border-bottom-color: #fff;
51
+ }
52
+
53
+ .multi-language-field .wp-switch-editor.current-language {
54
+ background-color: #fff;
55
+ border-bottom-color: #fff;
56
+ color: #333;
57
+ }
58
+
59
+ .multi-language-field > input,
60
+ .multi-language-field > textarea,
61
+ .multi-language-field > fieldset,
62
+ .multi-language-field .acf-wysiwyg-wrap,
63
+ .multi-language-field .acf-image-uploader { display: none }
64
+
65
+ .multi-language-field .acf_input input,
66
+ .multi-language-field .acf_input textarea,
67
+ .multi-language-field .current-language { display: block !important }
68
+
69
+ .multi-language-field-wysiwyg { margin-top: 0 }
70
+
71
+ .multi-language-field .acf-image-uploader {
72
+ padding: 10px 10px 10px;
73
+ clear: right;
74
+ border: 1px solid #dfdfdf;
75
+ }
76
+
77
+ .multi-language-field .acf-image-uploader.current-language { background: #fff; }
78
+
79
+ .multi-language-field-wysiwyg .wp-switch-editor {
80
+ background-color: #ebebeb;
81
+ border-color: #dedede;
82
+ }
83
+
84
+ .multi-language-field-wysiwyg .html-active .switch-html,
85
+ .multi-language-field-wysiwyg .tmce-active .switch-tmce,
86
+ .multi-language-field-wysiwyg .wp-switch-editor.current-language {
87
+ background-color: #f5f5f5;
88
+ border-bottom-color: #f5f5f5;
89
+ }
90
+
v5/assets/input.js ADDED
@@ -0,0 +1,370 @@
1
+
2
+ jQuery(function($) {
3
+
4
+
5
+ $('body').on('click', '.wp-switch-editor[data-language]', function() {
6
+ var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
7
+
8
+ parent.find('.current-language').removeClass('current-language');
9
+ parent.find('[data-language="' + language + '"]').addClass('current-language');
10
+ parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
11
+
12
+ // if a TinyMCE hasn't been initalize for this language then initalize it
13
+ if (!parent.find('.current-language .mce-tinymce').length) {
14
+ acf.do_action('ready', parent.parents('.acf-field'));
15
+ }
16
+ });
17
+
18
+ $('body').on('focusin', '.multi-language-field input, .multi-language-field textarea', function() {
19
+ $(this).parent('.multi-language-field').addClass('focused');
20
+ });
21
+
22
+ $('body').on('focusout', '.multi-language-field input, .multi-language-field textarea', function() {
23
+ $(this).parent('.multi-language-field').removeClass('focused');
24
+ });
25
+
26
+
27
+ });
28
+
29
+
30
+
31
+ (function($){
32
+
33
+ acf.fields.qtranslate_wysiwyg = acf.field.extend({
34
+
35
+ type: 'qtranslate_wysiwyg',
36
+ $el: null,
37
+ $textarea: null,
38
+ toolbars: {},
39
+
40
+ actions: {
41
+ 'ready': 'initialize',
42
+ 'append': 'initialize',
43
+ 'remove': 'disable',
44
+ 'sortstart': 'disable',
45
+ 'sortstop': 'enable'
46
+ },
47
+
48
+ focus: function(){
49
+
50
+ // update vars
51
+ this.$el = this.$field.find('.wp-editor-wrap.current-language').last();
52
+ this.$textarea = this.$el.find('textarea');
53
+
54
+
55
+ // settings
56
+ this.settings = acf.get_data( this.$el );
57
+ this.settings.id = this.$textarea.attr('id');
58
+ },
59
+
60
+ initialize: function(){
61
+
62
+ // bail early if no tinymce
63
+ if( typeof tinyMCEPreInit === 'undefined' ) {
64
+
65
+ return false;
66
+
67
+ }
68
+
69
+
70
+ // vars
71
+ var mceInit = this.get_mceInit(),
72
+ qtInit = this.get_qtInit();
73
+
74
+
75
+ // append settings
76
+ tinyMCEPreInit.mceInit[ mceInit.id ] = mceInit;
77
+ tinyMCEPreInit.qtInit[ qtInit.id ] = qtInit;
78
+
79
+
80
+ // initialize mceInit
81
+ if( this.$el.hasClass('tmce-active') ) {
82
+
83
+ try {
84
+
85
+ tinymce.init( mceInit );
86
+
87
+ } catch(e){}
88
+
89
+ }
90
+
91
+
92
+ // initialize qtInit
93
+ try {
94
+
95
+ var qtag = quicktags( qtInit );
96
+
97
+ this._buttonsInit( qtag );
98
+
99
+ } catch(e){}
100
+
101
+ },
102
+
103
+
104
+ get_mceInit : function(){
105
+
106
+ // reference
107
+ var $field = this.$field;
108
+
109
+
110
+ // vars
111
+ var toolbar = this.get_toolbar( this.settings.toolbar ),
112
+ mceInit = $.extend({}, tinyMCEPreInit.mceInit.acf_content);
113
+
114
+
115
+ // selector
116
+ mceInit.selector = '#' + this.settings.id;
117
+
118
+
119
+ // id
120
+ mceInit.id = this.settings.id; // tinymce v4
121
+ mceInit.elements = this.settings.id; // tinymce v3
122
+
123
+
124
+ // toolbar
125
+ if( toolbar ) {
126
+
127
+ var k = (tinymce.majorVersion < 4) ? 'theme_advanced_buttons' : 'toolbar';
128
+
129
+ for( var i = 1; i < 5; i++ ) {
130
+
131
+ mceInit[ k + i ] = acf.isset(toolbar, i) ? toolbar[i] : '';
132
+
133
+ }
134
+
135
+ }
136
+
137
+
138
+ // events
139
+ if( tinymce.majorVersion < 4 ) {
140
+
141
+ mceInit.setup = function( ed ){
142
+
143
+ ed.onInit.add(function(ed, event) {
144
+
145
+ // focus
146
+ $(ed.getBody()).on('focus', function(){
147
+
148
+ acf.validation.remove_error( $field );
149
+
150
+ });
151
+
152
+ $(ed.getBody()).on('blur', function(){
153
+
154
+ // update the hidden textarea
155
+ // - This fixes a bug when adding a taxonomy term as the form is not posted and the hidden textarea is never populated!
156
+
157
+ // save to textarea
158
+ ed.save();
159
+
160
+
161
+ // trigger change on textarea
162
+ $field.find('textarea').trigger('change');
163
+
164
+ });
165
+
166
+ });
167
+
168
+ };
169
+
170
+ } else {
171
+
172
+ mceInit.setup = function( ed ){
173
+
174
+ ed.on('focus', function(e) {
175
+
176
+ acf.validation.remove_error( $field );
177
+
178
+ });
179
+
180
+ ed.on('blur', function(e) {
181
+
182
+ // update the hidden textarea
183
+ // - This fixes a but when adding a taxonomy term as the form is not posted and the hidden textarea is never populated!
184
+
185
+ // save to textarea
186
+ ed.save();
187
+
188
+
189
+ // trigger change on textarea
190
+ $field.find('textarea').trigger('change');
191
+
192
+ });
193
+
194
+ };
195
+
196
+ }
197
+
198
+
199
+ // hook for 3rd party customization
200
+ mceInit = acf.apply_filters('wysiwyg_tinymce_settings', mceInit, mceInit.id);
201
+
202
+
203
+ // return
204
+ return mceInit;
205
+
206
+ },
207
+
208
+ get_qtInit : function(){
209
+
210
+ // vars
211
+ var qtInit = $.extend({}, tinyMCEPreInit.qtInit.acf_content);
212
+
213
+
214
+ // id
215
+ qtInit.id = this.settings.id;
216
+
217
+
218
+ // hook for 3rd party customization
219
+ qtInit = acf.apply_filters('wysiwyg_quicktags_settings', qtInit, qtInit.id);
220
+
221
+
222
+ // return
223
+ return qtInit;
224
+
225
+ },
226
+
227
+ /*
228
+ * disable
229
+ *
230
+ * This function will disable the tinymce for a given field
231
+ * Note: txtarea_el is different from $textarea.val() and is the value that you see, not the value that you save.
232
+ * this allows text like <--more--> to wok instead of showing as an image when the tinymce is removed
233
+ *
234
+ * @type function
235
+ * @date 1/08/2014
236
+ * @since 5.0.0
237
+ *
238
+ * @param n/a
239
+ * @return n/a
240
+ */
241
+
242
+ disable: function(){
243
+
244
+ try {
245
+
246
+ // vars
247
+ var ed = tinyMCE.get( this.settings.id ),
248
+ txtarea_el = tinyMCE.DOM.get( this.settings.id );
249
+ val = txtarea_el.value;
250
+
251
+
252
+ // destory
253
+ ed.destroy();
254
+
255
+
256
+ // update value
257
+ if( this.$field.find('.wp-editor-wrap').hasClass('html-active') ) {
258
+
259
+ txtarea_el.value = val;
260
+
261
+ }
262
+
263
+
264
+ } catch(e) {}
265
+
266
+ },
267
+
268
+ enable: function(){
269
+
270
+ // bail early if html mode
271
+ if( this.$field.find('.wp-editor-wrap').hasClass('html-active') ) {
272
+
273
+ return;
274
+
275
+ }
276
+
277
+
278
+ try {
279
+
280
+ tinyMCE.init( tinyMCEPreInit.mceInit[ this.settings.id ] );
281
+
282
+ } catch(e) {}
283
+
284
+
285
+ },
286
+
287
+ get_toolbar : function( name ){
288
+
289
+ // bail early if toolbar doesn't exist
290
+ if( typeof this.toolbars[ name ] !== 'undefined' ) {
291
+
292
+ return this.toolbars[ name ];
293
+
294
+ }
295
+
296
+
297
+ // return
298
+ return false;
299
+
300
+ },
301
+
302
+
303
+ /*
304
+ * _buttonsInit
305
+ *
306
+ * This function will add the quicktags HTML to a WYSIWYG field. Normaly, this is added via quicktags on document ready,
307
+ * however, there is no support for 'append'. Source: wp-includes/js/quicktags.js:245
308
+ *
309
+ * @type function
310
+ * @date 1/08/2014
311
+ * @since 5.0.0
312
+ *
313
+ * @param ed (object) quicktag object
314
+ * @return n/a
315
+ */
316
+
317
+ _buttonsInit: function( ed ) {
318
+ var defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
319
+
320
+ canvas = ed.canvas;
321
+ name = ed.name;
322
+ settings = ed.settings;
323
+ html = '';
324
+ theButtons = {};
325
+ use = '';
326
+
327
+ // set buttons
328
+ if ( settings.buttons ) {
329
+ use = ','+settings.buttons+',';
330
+ }
331
+
332
+ for ( i in edButtons ) {
333
+ if ( !edButtons[i] ) {
334
+ continue;
335
+ }
336
+
337
+ id = edButtons[i].id;
338
+ if ( use && defaults.indexOf( ',' + id + ',' ) !== -1 && use.indexOf( ',' + id + ',' ) === -1 ) {
339
+ continue;
340
+ }
341
+
342
+ if ( !edButtons[i].instance || edButtons[i].instance === inst ) {
343
+ theButtons[id] = edButtons[i];
344
+
345
+ if ( edButtons[i].html ) {
346
+ html += edButtons[i].html(name + '_');
347
+ }
348
+ }
349
+ }
350
+
351
+ if ( use && use.indexOf(',fullscreen,') !== -1 ) {
352
+ theButtons.fullscreen = new qt.FullscreenButton();
353
+ html += theButtons.fullscreen.html(name + '_');
354
+ }
355
+
356
+
357
+ if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) {
358
+ theButtons.textdirection = new qt.TextDirectionButton();
359
+ html += theButtons.textdirection.html(name + '_');
360
+ }
361
+
362
+ ed.toolbar.innerHTML = html;
363
+ ed.theButtons = theButtons;
364
+
365
+ },
366
+
367
+ });
368
+
369
+ })(jQuery);
370
+
v5/fields/image.php ADDED
@@ -0,0 +1,130 @@
1
+ <?php
2
+
3
+ class acf_field_qtranslate_image extends acf_field_image
4
+ {
5
+
6
+ function __construct()
7
+ {
8
+ $this->name = 'qtranslate_image';
9
+ $this->label = __("Image", 'acf');
10
+ $this->category = __("qTranslate", 'acf');
11
+ $this->defaults = array(
12
+ 'return_format' => 'array',
13
+ 'preview_size' => 'thumbnail',
14
+ 'library' => 'all'
15
+ );
16
+ $this->l10n = array(
17
+ 'select' => __("Select Image",'acf'),
18
+ 'edit' => __("Edit Image",'acf'),
19
+ 'update' => __("Update Image",'acf'),
20
+ 'uploadedTo' => __("uploaded to this post",'acf'),
21
+ );
22
+
23
+ acf_field::__construct();
24
+
25
+ // filters
26
+ add_filter('get_media_item_args', array($this, 'get_media_item_args'));
27
+ add_filter('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3);
28
+ }
29
+
30
+ function render_field($field)
31
+ {
32
+ if (!acf_qtranslate_enabled()) {
33
+ acf_field_image::render_field($field);
34
+ return;
35
+ }
36
+
37
+ global $q_config;
38
+ $languages = qtrans_getSortedLanguages(true);
39
+ $values = qtrans_split($field['value'], $quicktags = true);
40
+ $currentLanguage = qtrans_getLanguage();
41
+
42
+
43
+ // enqueue
44
+ acf_enqueue_uploader();
45
+
46
+
47
+ // vars
48
+ $div_atts = array(
49
+ 'class' => 'acf-image-uploader acf-cf',
50
+ 'data-preview_size' => $field['preview_size'],
51
+ 'data-library' => $field['library']
52
+ );
53
+ $input_atts = array(
54
+ 'type' => 'hidden',
55
+ 'name' => $field['name'],
56
+ 'value' => $field['value'],
57
+ 'data-name' => 'value-id'
58
+ );
59
+ $url = '';
60
+
61
+
62
+ echo '<div class="multi-language-field multi-language-field-image">';
63
+
64
+ foreach ($languages as $language) {
65
+ $class = 'wp-switch-editor';
66
+ if ($language === $currentLanguage) {
67
+ $class .= ' current-language';
68
+ }
69
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
70
+ }
71
+
72
+ foreach ($languages as $language):
73
+
74
+ $input_atts['name'] = $field['name'] . '[' . $language . ']';
75
+ $field['value'] = $values[$language];
76
+ $div_atts['data-language'] = $language;
77
+ $div_atts['class'] = 'acf-image-uploader acf-cf';
78
+
79
+ // has value?
80
+ if( $field['value'] && is_numeric($field['value']) ) {
81
+
82
+ $url = wp_get_attachment_image_src($field['value'], $field['preview_size']);
83
+ $url = $url[0];
84
+
85
+ $div_atts['class'] .= ' has-value';
86
+
87
+ }
88
+
89
+ if ($language === $currentLanguage) {
90
+ $div_atts['class'] .= ' current-language';
91
+ }
92
+
93
+ ?>
94
+ <div <?php acf_esc_attr_e( $div_atts ); ?>>
95
+ <div class="acf-hidden">
96
+ <input <?php acf_esc_attr_e( $input_atts ); ?>/>
97
+ </div>
98
+ <div class="view show-if-value acf-soh">
99
+ <ul class="acf-hl acf-soh-target">
100
+ <li><a class="acf-icon dark" data-name="edit-button" href="#"><i class="acf-sprite-edit"></i></a></li>
101
+ <li><a class="acf-icon dark" data-name="remove-button" href="#"><i class="acf-sprite-delete"></i></a></li>
102
+ </ul>
103
+ <img data-name="value-url" src="<?php echo $url; ?>" alt=""/>
104
+ </div>
105
+ <div class="view hide-if-value">
106
+ <p><?php _e('No image selected','acf'); ?> <a data-name="add-button" class="acf-button" href="#"><?php _e('Add Image','acf'); ?></a></p>
107
+ </div>
108
+ </div>
109
+
110
+ <?php endforeach;
111
+
112
+ echo '</div>';
113
+ }
114
+
115
+
116
+ function update_value($value, $post_id, $field)
117
+ {
118
+ $value = acf_field_image::update_value($value, $post_id, $field);
119
+
120
+ if (acf_qtranslate_enabled()) {
121
+ $value = qtrans_join($value);
122
+ }
123
+
124
+ return $value;
125
+ }
126
+
127
+ }
128
+
129
+ new acf_field_qtranslate_image();
130
+
v5/fields/text.php ADDED
@@ -0,0 +1,140 @@
1
+ <?php
2
+
3
+ class acf_field_qtranslate_text extends acf_field_text
4
+ {
5
+
6
+ function __construct()
7
+ {
8
+ $this->name = 'qtranslate_text';
9
+ $this->label = __("Text",'acf');
10
+ $this->category = __("qTranslate",'acf');
11
+ $this->defaults = array(
12
+ 'default_value' => '',
13
+ 'maxlength' => '',
14
+ 'placeholder' => '',
15
+ 'prepend' => '',
16
+ 'append' => '',
17
+ 'readonly' => 0,
18
+ 'disabled' => 0,
19
+ );
20
+
21
+ acf_field::__construct();
22
+ }
23
+
24
+
25
+ function render_field($field)
26
+ {
27
+ if (!acf_qtranslate_enabled()) {
28
+ acf_field_text::render_field($field);
29
+ return;
30
+ }
31
+
32
+ global $q_config;
33
+ $languages = qtrans_getSortedLanguages(true);
34
+ $values = qtrans_split($field['value'], $quicktags = true);
35
+
36
+
37
+ // vars
38
+ $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
39
+ $s = array( 'readonly', 'disabled' );
40
+ $e = '';
41
+
42
+
43
+ // maxlength
44
+ if( $field['maxlength'] !== "" ) {
45
+
46
+ $o[] = 'maxlength';
47
+
48
+ }
49
+
50
+
51
+ // populate atts
52
+ $atts = array();
53
+ foreach( $o as $k ) {
54
+
55
+ $atts[ $k ] = $field[ $k ];
56
+
57
+ }
58
+
59
+
60
+ // special atts
61
+ foreach( $s as $k ) {
62
+
63
+ if( $field[ $k ] ) {
64
+
65
+ $atts[ $k ] = $k;
66
+
67
+ }
68
+
69
+ }
70
+
71
+
72
+ // render
73
+ $e .= '<div class="acf-input-wrap multi-language-field">';
74
+
75
+ foreach ($languages as $language) {
76
+ $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
77
+ $e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
78
+ }
79
+
80
+ foreach ($languages as $language) {
81
+ if ($language === end($languages)) {
82
+ $atts['class'] .= ' current-language';
83
+ }
84
+ $atts['type'] = 'text';
85
+ $atts['name'] = $field['name'] . "[$language]";
86
+ $atts['value'] = $values[$language];
87
+ $atts['data-language'] = $language;
88
+ $e .= '<input ' . acf_esc_attr( $atts ) . ' />';
89
+ }
90
+
91
+ $e .= '</div>';
92
+
93
+
94
+ // return
95
+ echo $e;
96
+ }
97
+
98
+
99
+ function render_field_settings( $field ) {
100
+
101
+ // default_value
102
+ acf_render_field_setting( $field, array(
103
+ 'label' => __('Default Value','acf'),
104
+ 'instructions' => __('Appears when creating a new post','acf'),
105
+ 'type' => 'text',
106
+ 'name' => 'default_value',
107
+ ));
108
+
109
+ // placeholder
110
+ acf_render_field_setting( $field, array(
111
+ 'label' => __('Placeholder Text','acf'),
112
+ 'instructions' => __('Appears within the input','acf'),
113
+ 'type' => 'text',
114
+ 'name' => 'placeholder',
115
+ ));
116
+
117
+ // maxlength
118
+ acf_render_field_setting( $field, array(
119
+ 'label' => __('Character Limit','acf'),
120
+ 'instructions' => __('Leave blank for no limit','acf'),
121
+ 'type' => 'number',
122
+ 'name' => 'maxlength',
123
+ ));
124
+
125
+ }
126
+
127
+
128
+ function update_value($value, $post_id, $field)
129
+ {
130
+ if (acf_qtranslate_enabled()) {
131
+ $value = qtrans_join($value);
132
+ }
133
+
134
+ return $value;
135
+ }
136
+
137
+ }
138
+
139
+
140
+ new acf_field_qtranslate_text;
v5/fields/textarea.php ADDED
@@ -0,0 +1,119 @@
1
+ <?php
2
+
3
+ class acf_field_qtranslate_textarea extends acf_field_textarea
4
+ {
5
+
6
+ function __construct()
7
+ {
8
+ $this->name = 'qtranslate_textarea';
9
+ $this->label = __("Text Area",'acf');
10
+ $this->category = __("qTranslate",'acf');
11
+ $this->defaults = array(
12
+ 'default_value' => '',
13
+ 'new_lines' => '',
14
+ 'maxlength' => '',
15
+ 'placeholder' => '',
16
+ 'readonly' => 0,
17
+ 'disabled' => 0,
18
+ 'rows' => ''
19
+ );
20
+
21
+ acf_field::__construct();
22
+ }
23
+
24
+
25
+ function render_field($field)
26
+ {
27
+ if (!acf_qtranslate_enabled()) {
28
+ acf_field_textarea::render_field($field);
29
+ return;
30
+ }
31
+
32
+ global $q_config;
33
+ $languages = qtrans_getSortedLanguages(true);
34
+ $values = qtrans_split($field['value'], $quicktags = true);
35
+
36
+
37
+ // vars
38
+ $o = array( 'id', 'class', 'name', 'placeholder', 'rows' );
39
+ $s = array( 'readonly', 'disabled' );
40
+ $e = '';
41
+
42
+
43
+ // maxlength
44
+ if( $field['maxlength'] !== '' ) {
45
+
46
+ $o[] = 'maxlength';
47
+
48
+ }
49
+
50
+
51
+ // rows
52
+ if( empty($field['rows']) ) {
53
+
54
+ $field['rows'] = 8;
55
+
56
+ }
57
+
58
+
59
+ // populate atts
60
+ $atts = array();
61
+ foreach( $o as $k ) {
62
+
63
+ $atts[ $k ] = $field[ $k ];
64
+
65
+ }
66
+
67
+
68
+ // special atts
69
+ foreach( $s as $k ) {
70
+
71
+ if( $field[ $k ] ) {
72
+
73
+ $atts[ $k ] = $k;
74
+
75
+ }
76
+
77
+ }
78
+
79
+
80
+ // render
81
+ $e .= '<div class="acf-input-wrap multi-language-field">';
82
+
83
+ foreach ($languages as $language) {
84
+ $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
85
+ $e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
86
+ }
87
+
88
+ foreach ($languages as $language) {
89
+ if ($language === end($languages)) {
90
+ $atts['class'] .= ' current-language';
91
+ }
92
+ $atts['name'] = $field['name'] . "[$language]";
93
+ $atts['data-language'] = $language;
94
+ $e .= '<textarea ' . acf_esc_attr( $atts ) . ' >';
95
+ $e .= esc_textarea( $values[$language] );
96
+ $e .= '</textarea>';
97
+ }
98
+
99
+ $e .= '</div>';
100
+
101
+
102
+ // return
103
+ echo $e;
104
+ }
105
+
106
+
107
+ function update_value($value, $post_id, $field)
108
+ {
109
+ if (acf_qtranslate_enabled()) {
110
+ $value = qtrans_join($value);
111
+ }
112
+
113
+ return $value;
114
+ }
115
+
116
+ }
117
+
118
+
119
+ new acf_field_qtranslate_textarea;
v5/fields/wysiwyg.php ADDED
@@ -0,0 +1,212 @@
1
+ <?php
2
+
3
+ class acf_field_qtranslate_wysiwyg extends acf_field_wysiwyg
4
+ {
5
+
6
+ function __construct()
7
+ {
8
+ $this->name = 'qtranslate_wysiwyg';
9
+ $this->label = __("Wysiwyg Editor",'acf');
10
+ $this->category = __("qTranslate",'acf');
11
+ $this->defaults = array(
12
+ 'tabs' => 'all',
13
+ 'toolbar' => 'full',
14
+ 'media_upload' => 1,
15
+ 'default_value' => '',
16
+ );
17
+
18
+
19
+ // Create an acf version of the_content filter (acf_the_content)
20
+ if( !empty($GLOBALS['wp_embed']) ) {
21
+
22
+ add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
23
+ add_filter( 'acf_the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
24
+
25
+ }
26
+
27
+ add_filter( 'acf_the_content', 'capital_P_dangit', 11 );
28
+ add_filter( 'acf_the_content', 'wptexturize' );
29
+ add_filter( 'acf_the_content', 'convert_smilies' );
30
+ add_filter( 'acf_the_content', 'convert_chars' );
31
+ add_filter( 'acf_the_content', 'wpautop' );
32
+ add_filter( 'acf_the_content', 'shortcode_unautop' );
33
+ add_filter( 'acf_the_content', 'prepend_attachment' );
34
+ add_filter( 'acf_the_content', 'do_shortcode', 11);
35
+
36
+ acf_field::__construct();
37
+ }
38
+
39
+
40
+ function render_field($field)
41
+ {
42
+ if (!acf_qtranslate_enabled()) {
43
+ acf_field_wysiwyg::render_field($field);
44
+ return;
45
+ }
46
+
47
+ // enqueue
48
+ acf_enqueue_uploader();
49
+
50
+
51
+ // vars
52
+ $id = $field['id'] . '-' . uniqid();
53
+ $mode = 'html';
54
+ $show_tabs = true;
55
+
56
+
57
+ // get height
58
+ $height = acf_get_user_setting('wysiwyg_height', 300);
59
+ $height = max( $height, 300 ); // minimum height is 300
60
+
61
+
62
+ // detect mode
63
+ if( $field['tabs'] == 'visual' ) {
64
+
65
+ // case: visual tab only
66
+ $mode = 'tmce';
67
+ $show_tabs = false;
68
+
69
+ } elseif( $field['tabs'] == 'text' ) {
70
+
71
+ // case: text tab only
72
+ $show_tabs = false;
73
+
74
+ } elseif( wp_default_editor() == 'tinymce' ) {
75
+
76
+ // case: both tabs
77
+ $mode = 'tmce';
78
+
79
+ }
80
+
81
+
82
+ // mode
83
+ $switch_class = $mode . '-active';
84
+
85
+
86
+ // filter value for editor
87
+ remove_all_filters( 'acf_the_editor_content' );
88
+
89
+ if( $mode == 'tmce' ) {
90
+
91
+ add_filter('acf_the_editor_content', 'wp_richedit_pre');
92
+
93
+ } else {
94
+
95
+ add_filter('acf_the_editor_content', 'wp_htmledit_pre');
96
+
97
+ }
98
+
99
+ $field['value'] = apply_filters( 'acf_the_editor_content', $field['value'] );
100
+
101
+
102
+ global $q_config, $wp_version;
103
+ $languages = qtrans_getSortedLanguages(true);
104
+ $values = qtrans_split($field['value'], $quicktags = true);
105
+
106
+ echo '<div class="multi-language-field multi-language-field-wysiwyg">';
107
+
108
+ foreach ($languages as $language) {
109
+ $class = ($language === end($languages)) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
110
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
111
+ }
112
+
113
+ $uid = $field['id'] . '-' . uniqid();
114
+ foreach ($languages as $language):
115
+ $value = $values[$language];
116
+ $id = $field['id'] . "-$language";
117
+ $name = $field['name'] . "[$language]";
118
+ if ($language === end($languages)) {
119
+ $switch_class .= ' current-language';
120
+ }
121
+
122
+ ?>
123
+ <div id="wp-<?php echo $id; ?>-wrap" class="acf-wysiwyg-wrap wp-core-ui wp-editor-wrap <?php echo $switch_class; ?>" data-toolbar="<?php echo $field['toolbar']; ?>" data-upload="<?php echo $field['media_upload']; ?>" data-language="<?php echo $language; ?>">
124
+ <div id="wp-<?php echo $id; ?>-editor-tools" class="wp-editor-tools hide-if-no-js">
125
+ <?php if( $field['media_upload'] ): ?>
126
+ <div id="wp-<?php echo $id; ?>-media-buttons" class="wp-media-buttons">
127
+ <?php do_action( 'media_buttons' ); ?>
128
+ </div>
129
+ <?php endif; ?>
130
+ <?php if( user_can_richedit() && $show_tabs ): ?>
131
+ <div class="wp-editor-tabs">
132
+ <a id="<?php echo $id; ?>-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);"><?php echo _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ); ?></a>
133
+ <a id="<?php echo $id; ?>-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);"><?php echo __('Visual'); ?></a>
134
+ </div>
135
+ <?php endif; ?>
136
+ </div>
137
+ <div id="wp-<?php echo $id; ?>-editor-container" class="wp-editor-container">
138
+ <textarea id="<?php echo $id; ?>" class="wp-editor-area" name="<?php echo $name; ?>" <?php if($height): ?>style="height:<?php echo $height; ?>px;"<?php endif; ?>><?php echo $value; ?></textarea>
139
+ </div>
140
+ </div>
141
+ <?php endforeach;
142
+
143
+ echo '</div>';
144
+ }
145
+
146
+
147
+ function input_form_data( $args ) {
148
+
149
+ // vars
150
+ $json = array();
151
+ $toolbars = $this->get_toolbars();
152
+
153
+
154
+ // loop through toolbars
155
+ if( !empty($toolbars) ) {
156
+
157
+ foreach( $toolbars as $label => $rows ) {
158
+
159
+ // vars
160
+ $label = sanitize_title( $label );
161
+ $label = str_replace('-', '_', $label);
162
+
163
+
164
+ // append to $json
165
+ $json[ $label ] = array();
166
+
167
+
168
+ // convert to strings
169
+ if( !empty($rows) ) {
170
+
171
+ foreach( $rows as $i => $row ) {
172
+
173
+ $json[ $label ][ $i ] = implode(',', $row);
174
+
175
+ }
176
+ // foreach
177
+
178
+ }
179
+ // if
180
+
181
+ }
182
+ // foreach
183
+
184
+ }
185
+ // if
186
+
187
+ ?>
188
+ <script type="text/javascript">
189
+ (function($) {
190
+
191
+ acf.fields.qtranslate_wysiwyg.toolbars = <?php echo json_encode( $json ); ?>;
192
+
193
+ })(jQuery);
194
+ </script>
195
+ <?php
196
+
197
+ }
198
+
199
+
200
+ function update_value($value, $post_id, $field)
201
+ {
202
+ if (acf_qtranslate_enabled()) {
203
+ $value = qtrans_join($value);
204
+ }
205
+
206
+ return $value;
207
+ }
208
+
209
+ }
210
+
211
+
212
+ new acf_field_qtranslate_wysiwyg;
v5/init.php ADDED
@@ -0,0 +1,31 @@
1
+ <?php
2
+
3
+ add_action('acf/input/admin_enqueue_scripts', 'acf_qtranslate_v5_admin_enqueue_scripts');
4
+ function acf_qtranslate_v5_admin_enqueue_scripts() {
5
+ if (acf_qtranslate_acf_major_version() === 5) {
6
+ wp_enqueue_style('editor-buttons');
7
+ wp_enqueue_style('acf_qtranslate_main', plugins_url('/assets/input.css', __FILE__));
8
+ wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/input.js', __FILE__));
9
+ }
10
+ }
11
+
12
+ add_action('acf/include_field_types', 'acf_qtranslate_plugin_v5_include_field_types');
13
+ function acf_qtranslate_plugin_v5_include_field_types($version) {
14
+ require_once dirname(__FILE__) . '/fields/text.php';
15
+ require_once dirname(__FILE__) . '/fields/textarea.php';
16
+ require_once dirname(__FILE__) . '/fields/wysiwyg.php';
17
+ require_once dirname(__FILE__) . '/fields/image.php';
18
+ }
19
+
20
+ add_filter('acf/format_value', 'acf_qtranslate_plugin_v5_format_value');
21
+ function acf_qtranslate_plugin_v5_format_value($value) {
22
+ // we must check the version here since acf/format_value is a valid filter
23
+ // ACF v4 however it serves a slightly different purpose
24
+ if (acf_qtranslate_acf_major_version() === 5) {
25
+ if (acf_qtranslate_enabled() && is_string($value)) {
26
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
27
+ }
28
+ return $value;
29
+ }
30
+ return $value;
31
+ }