ACF qTranslate - Version 1.7.25

Version Description

  • Core: Added qTranslate suffix to field labels
  • Core: (asedano) Added ACF5 support for Post Object field
  • Bug Fix: Fixed issue with File fields
Download this release

Release Info

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

Code changes from version 1.7.24 to 1.7.25

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.7.24
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
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.7.25
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
assets/acf_5/main.js CHANGED
@@ -1,85 +1,154 @@
1
- /**
2
- * Clone functionality from standard Image field type
3
- */
4
- acf.registerFieldType(acf.models.ImageField.extend({
5
- type: 'qtranslate_image',
6
7
$control: function(){
8
- return this.$('.acf-image-uploader.current-language');
9
},
10
11
$input: function(){
12
- return this.$('.acf-image-uploader.current-language input[type="hidden"]');
13
},
14
15
render: function( attachment ){
16
- var control = this.$control();
17
18
// vars
19
attachment = this.validateAttachment( attachment );
20
21
// update image
22
- control.find('img').attr({
23
- src: attachment.url,
24
alt: attachment.alt,
25
title: attachment.title
26
});
27
28
// vars
29
var val = attachment.id || '';
30
31
// update val
32
- this.val( val );
33
34
// update class
35
if( val ) {
36
- control.addClass('has-value');
37
} else {
38
- control.removeClass('has-value');
39
}
40
}
41
}));
42
43
- /**
44
- * Clone functionality from standard File field type
45
- */
46
- acf.registerFieldType(acf.models.QtranslateImageField.extend({
47
- type: 'qtranslate_file',
48
render: function( attachment ){
49
- var control = this.$control();
50
-
51
// vars
52
attachment = this.validateAttachment( attachment );
53
54
// update image
55
- this.$control().find(' img').attr({
56
- src: attachment.icon,
57
alt: attachment.alt,
58
title: attachment.title
59
});
60
61
- // update elements
62
- control.find('[data-name="title"]').text( attachment.title );
63
- control.find('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url );
64
- control.find('[data-name="filesize"]').text( attachment.filesizeHumanReadable );
65
-
66
// vars
67
var val = attachment.id || '';
68
69
// update val
70
- acf.val( this.$input(), val );
71
72
// update class
73
if( val ) {
74
- control.addClass('has-value');
75
} else {
76
- control.removeClass('has-value');
77
}
78
},
79
}));
80
81
acf.registerFieldType(acf.models.WysiwygField.extend({
82
type: 'qtranslate_wysiwyg',
83
initializeEditor: function() {
84
var self = this;
85
this.$('.acf-editor-wrap').each(function() {
@@ -114,51 +183,3 @@ acf.registerFieldType(acf.models.WysiwygField.extend({
114
}
115
}));
116
117
- acf.registerFieldType(acf.models.UrlField.extend({
118
- type: 'qtranslate_url',
119
- $control: function(){
120
- return this.$('.acf-input-wrap.current-language');
121
- },
122
-
123
- $input: function(){
124
- return this.$('.acf-input-wrap.current-language input[type="url"]');
125
- },
126
- isValid: function(){
127
-
128
- // vars
129
- var val = this.val();
130
-
131
- // bail early if no val
132
- if( !val ) {
133
- return false;
134
- }
135
-
136
- // url
137
- if( val.indexOf('://') !== -1 ) {
138
- return true;
139
- }
140
-
141
- // protocol relative url
142
- if( val.indexOf('//') === 0 ) {
143
- return true;
144
- }
145
-
146
- // relative url
147
- if( val.indexOf('/') === 0 ) {
148
- return true;
149
- }
150
-
151
- // return
152
- return false;
153
- },
154
-
155
- render: function(){
156
-
157
- // add class
158
- if( this.isValid() ) {
159
- this.$control().addClass('-valid');
160
- } else {
161
- this.$control().removeClass('-valid');
162
- }
163
- },
164
- }));
1
+
2
+
3
+ acf.registerFieldType(acf.models.FileField.extend({
4
+ type: 'qtranslate_file',
5
6
$control: function(){
7
+ return this.$('.acf-file-uploader.current-language');
8
},
9
10
$input: function(){
11
+ return this.$('.acf-file-uploader.current-language input[type="hidden"]');
12
},
13
14
render: function( attachment ){
15
16
// vars
17
attachment = this.validateAttachment( attachment );
18
19
// update image
20
+ this.$control().find('img').attr({
21
+ src: attachment.icon,
22
alt: attachment.alt,
23
title: attachment.title
24
});
25
26
+ // update elements
27
+ this.$control().find('[data-name="title"]').text( attachment.title );
28
+ this.$control().find('[data-name="filename"]').text( attachment.filename ).attr( 'href', attachment.url );
29
+ this.$control().find('[data-name="filesize"]').text( attachment.filesizeHumanReadable );
30
+
31
// vars
32
var val = attachment.id || '';
33
34
// update val
35
+ acf.val( this.$input(), val );
36
37
// update class
38
if( val ) {
39
+ this.$control().addClass('has-value');
40
} else {
41
+ this.$control().removeClass('has-value');
42
}
43
}
44
}));
45
46
+
47
+ acf.registerFieldType(acf.models.ImageField.extend({
48
+ type: 'qtranslate_image',
49
+
50
+ $control: function(){
51
+ return this.$('.acf-image-uploader.current-language');
52
+ },
53
+
54
+ $input: function(){
55
+ return this.$('.acf-image-uploader.current-language input[type="hidden"]');
56
+ },
57
+
58
render: function( attachment ){
59
+
60
// vars
61
attachment = this.validateAttachment( attachment );
62
63
// update image
64
+ this.$control().find('img').attr({
65
+ src: attachment.url,
66
alt: attachment.alt,
67
title: attachment.title
68
});
69
70
// vars
71
var val = attachment.id || '';
72
73
// update val
74
+ this.val( val );
75
76
// update class
77
if( val ) {
78
+ this.$control().addClass('has-value');
79
} else {
80
+ this.$control().removeClass('has-value');
81
+ }
82
+ }
83
+ }));
84
+
85
+
86
+ acf.registerFieldType(acf.models.PostObjectField.extend({
87
+ type: 'qtranslate_post_object',
88
+
89
+ $input: function(){
90
+ return this.$('.acf-post-object.current-language select');
91
+ },
92
+
93
+ initialize: function(){
94
+ var self = this;
95
+
96
+ // vars
97
+ var $select = this.$input();
98
+
99
+ // inherit data
100
+ this.inherit( $select );
101
+
102
+ // select2
103
+ if( this.get('ui') ) {
104
+
105
+ // populate ajax_data (allowing custom attribute to already exist)
106
+ var ajaxAction = this.get('ajax_action');
107
+ if( !ajaxAction ) {
108
+ ajaxAction = 'acf/fields/' + this.get('type') + '/query';
109
+ }
110
+
111
+ // select2
112
+ this.select2 = [];
113
+ this.$('.acf-post-object select').each(function() {
114
+ self.select2.push(acf.newSelect2(self.$(this), {
115
+ field: self,
116
+ ajax: self.get('ajax'),
117
+ multiple: self.get('multiple'),
118
+ placeholder: self.get('placeholder'),
119
+ allowNull: self.get('allow_null'),
120
+ ajaxAction: ajaxAction,
121
+ }));
122
+ });
123
}
124
},
125
+
126
+ onRemove: function(){
127
+ if( this.select2 ) {
128
+ for (var i=0; i < this.select2.length; i++) {
129
+ this.select2[i].destroy();
130
+ }
131
+ }
132
+ }
133
}));
134
135
+
136
+ acf.registerFieldType(acf.models.UrlField.extend({
137
+ type: 'qtranslate_url',
138
+
139
+ $control: function(){
140
+ return this.$('.acf-input-wrap.current-language');
141
+ },
142
+
143
+ $input: function(){
144
+ return this.$('.acf-input-wrap.current-language input[type="url"]');
145
+ }
146
+ }));
147
+
148
+
149
acf.registerFieldType(acf.models.WysiwygField.extend({
150
type: 'qtranslate_wysiwyg',
151
+
152
initializeEditor: function() {
153
var self = this;
154
this.$('.acf-editor-wrap').each(function() {
183
}
184
}));
185
assets/acf_5/qtranslatex.js CHANGED
@@ -1,5 +1,6 @@
1
2
(function(){
3
var windowLoadCompleted = false;
4
jQuery(window).load(function() {
5
@@ -88,16 +89,22 @@
88
// Watch and remove content hooks when fields are removed
89
// however ACF removes the elements from the DOM early so
90
// we must hook into handler and perform updates there
91
- var _hooked_repeater_remove = acf.fields.repeater.remove;
92
- acf.fields.repeater.remove = function($el) {
93
var row = ($el.$el || $el).closest('.acf-row'); // support old versions of ACF5PRO as well
94
row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() {
95
qTranslateConfig.qtx.removeContentHook(this);
96
});
97
// call the original handler
98
- _hooked_repeater_remove.call(this, $el);
99
};
100
-
101
});
102
103
})();
1
2
(function(){
3
+
4
var windowLoadCompleted = false;
5
jQuery(window).load(function() {
6
89
// Watch and remove content hooks when fields are removed
90
// however ACF removes the elements from the DOM early so
91
// we must hook into handler and perform updates there
92
+ var repeaterFieldRemove;
93
+
94
+ if (acf.models) {
95
+ repeaterFieldRemove = acf.models.RepeaterField.prototype.remove;
96
+ } else {
97
+ repeaterFieldRemove = acf.fields.repeater.remove;
98
+ }
99
+
100
+ function repeaterRemove($el) {
101
var row = ($el.$el || $el).closest('.acf-row'); // support old versions of ACF5PRO as well
102
row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() {
103
qTranslateConfig.qtx.removeContentHook(this);
104
});
105
// call the original handler
106
+ repeaterFieldRemove.call(this, $el);
107
};
108
});
109
110
})();
assets/common.css CHANGED
@@ -35,11 +35,14 @@
35
z-index: 100;
36
border: 1px solid #ededed;
37
margin-left: -1px;
38
- padding: 6px 7px;
39
text-transform: uppercase;
40
cursor: pointer
41
}
42
43
.multi-language-field input,
44
.multi-language-field input:focus,
45
.multi-language-field textarea,
@@ -67,10 +70,11 @@
67
.multi-language-field > textarea,
68
.multi-language-field > fieldset,
69
.multi-language-field .acf_wysiwyg,
70
- .multi-language-field .acf-url,
71
.multi-language-field .acf-editor-wrap,
72
.multi-language-field .acf-file-uploader,
73
- .multi-language-field .acf-image-uploader { display: none }
74
75
.multi-language-field .acf_input input,
76
.multi-language-field .acf_input textarea,
@@ -80,8 +84,9 @@
80
margin-top: 0;
81
}
82
83
- .acf-input .acf-url input[type="text"] {
84
- padding-left: 25px;
85
}
86
87
.multi-language-field .acf-file-uploader,
@@ -104,4 +109,10 @@
104
.multi-language-field-wysiwyg .wp-switch-editor.current-language {
105
background-color: #f5f5f5;
106
border-bottom-color: #f5f5f5;
107
- }
35
z-index: 100;
36
border: 1px solid #ededed;
37
margin-left: -1px;
38
text-transform: uppercase;
39
cursor: pointer
40
}
41
42
+ .multi-language-field > .wp-switch-editor:last-of-type {
43
+ margin-left: 5px;
44
+ }
45
+
46
.multi-language-field input,
47
.multi-language-field input:focus,
48
.multi-language-field textarea,
70
.multi-language-field > textarea,
71
.multi-language-field > fieldset,
72
.multi-language-field .acf_wysiwyg,
73
+ .multi-language-field .acf-post-object,
74
.multi-language-field .acf-editor-wrap,
75
.multi-language-field .acf-file-uploader,
76
+ .multi-language-field .acf-image-uploader,
77
+ .multi-language-field .acf-url > input { display: none }
78
79
.multi-language-field .acf_input input,
80
.multi-language-field .acf_input textarea,
84
margin-top: 0;
85
}
86
87
+ .multi-language-field .acf-url {
88
+ position: relative;
89
+ clear: both;
90
}
91
92
.multi-language-field .acf-file-uploader,
109
.multi-language-field-wysiwyg .wp-switch-editor.current-language {
110
background-color: #f5f5f5;
111
border-bottom-color: #f5f5f5;
112
+ }
113
+
114
+ .multi-language-field-post-object .select2-container--default .select2-selection--multiple,
115
+ .multi-language-field-post-object .select2-container--default.select2-container--focus .select2-selection--multiple {
116
+ border-color: #ddd;
117
+ border-radius: 0;
118
+ }
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.5.0
5
- Tested up to: 4.7.2
6
- Version: 1.7.24
7
- Stable tag: 1.7.24
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -55,6 +55,11 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
55
56
== Changelog ==
57
58
= 1.7.24 =
59
* Core: (asedano) Added ACF5 support for URL field
60
* Bug Fix: (asedano) Added ACF 5.7 compatibility
@@ -188,4 +193,4 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
188
189
== Upgrade Notice ==
190
191
- Bug Fix: Fixed issue with saving File and Image fields after ACF 5.5.5 upgrade
2
Contributors: funkjedi
3
Tags: acf, advanced custom fields, qtranslate, add-on, admin
4
Requires at least: 3.5.0
5
+ Tested up to: 4.9.8
6
+ Version: 1.7.25
7
+ Stable tag: 1.7.25
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
55
56
== Changelog ==
57
58
+ = 1.7.25 =
59
+ * Core: Added qTranslate suffix to field labels
60
+ * Core: (asedano) Added ACF5 support for Post Object field
61
+ * Bug Fix: Fixed issue with File fields
62
+
63
= 1.7.24 =
64
* Core: (asedano) Added ACF5 support for URL field
65
* Bug Fix: (asedano) Added ACF 5.7 compatibility
193
194
== Upgrade Notice ==
195
196
+ Bug Fix: Fixed issue with File fields
src/acf_5/acf.php CHANGED
@@ -29,17 +29,19 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
29
public function include_fields() {
30
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/file.php';
31
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/image.php';
32
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/text.php';
33
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/textarea.php';
34
- require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php';
35
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/url.php';
36
37
acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin));
38
acf()->fields->register_field_type(new acf_qtranslate_acf_5_textarea($this->plugin));
39
- acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($this->plugin));
40
- acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));
41
- acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin));
42
acf()->fields->register_field_type(new acf_qtranslate_acf_5_url($this->plugin));
43
}
44
45
/**
@@ -56,7 +58,9 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
56
public function format_value($value) {
57
if (is_string($value)) {
58
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
59
}
60
return $value;
61
}
62
@@ -99,9 +103,11 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
99
'flexible_content',
100
'qtranslate_file',
101
'qtranslate_image',
102
'qtranslate_text',
103
'qtranslate_textarea',
104
- 'qtranslate_wysiwyg'
105
);
106
107
foreach (acf_get_field_groups($filter) as $field_group) {
29
public function include_fields() {
30
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/file.php';
31
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/image.php';
32
+ require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/post_object.php';
33
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/text.php';
34
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/textarea.php';
35
require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/url.php';
36
+ require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/fields/wysiwyg.php';
37
38
+ acf()->fields->register_field_type(new acf_qtranslate_acf_5_file($this->plugin));
39
+ acf()->fields->register_field_type(new acf_qtranslate_acf_5_image($this->plugin));
40
+ acf()->fields->register_field_type(new acf_qtranslate_acf_5_post_object($this->plugin));
41
acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin));
42
acf()->fields->register_field_type(new acf_qtranslate_acf_5_textarea($this->plugin));
43
acf()->fields->register_field_type(new acf_qtranslate_acf_5_url($this->plugin));
44
+ acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($this->plugin));
45
}
46
47
/**
58
public function format_value($value) {
59
if (is_string($value)) {
60
$value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
61
+ $value = maybe_unserialize($value);
62
}
63
+
64
return $value;
65
}
66
103
'flexible_content',
104
'qtranslate_file',
105
'qtranslate_image',
106
+ 'qtranslate_post_object',
107
'qtranslate_text',
108
'qtranslate_textarea',
109
+ 'qtranslate_url',
110
+ 'qtranslate_wysiwyg',
111
);
112
113
foreach (acf_get_field_groups($filter) as $field_group) {
src/acf_5/fields/file.php CHANGED
@@ -47,7 +47,7 @@ class acf_qtranslate_acf_5_file extends acf_field_file {
47
48
// vars
49
$this->name = 'qtranslate_file';
50
- $this->label = __("File",'acf');
51
$this->category = __("qTranslate", 'acf');
52
$this->defaults = array(
53
'return_format' => 'array',
47
48
// vars
49
$this->name = 'qtranslate_file';
50
+ $this->label = __("File (qTranslate)",'acf');
51
$this->category = __("qTranslate", 'acf');
52
$this->defaults = array(
53
'return_format' => 'array',
src/acf_5/fields/image.php CHANGED
@@ -8,6 +8,7 @@ class acf_qtranslate_acf_5_image extends acf_field_image {
8
*/
9
protected $plugin;
10
11
/*
12
* __construct
13
*
@@ -31,23 +32,22 @@ class acf_qtranslate_acf_5_image extends acf_field_image {
31
}
32
33
/*
34
- * __construct
35
- *
36
- * This function will setup the field type data
37
- *
38
- * @type function
39
- * @date 5/03/2014
40
- * @since 5.0.0
41
- *
42
- * @param n/a
43
- * @return n/a
44
- */
45
-
46
function initialize() {
47
48
// vars
49
$this->name = 'qtranslate_image';
50
- $this->label = __("Image",'acf');
51
$this->category = __("qTranslate", 'acf');
52
$this->defaults = array(
53
'return_format' => 'array',
8
*/
9
protected $plugin;
10
11
+
12
/*
13
* __construct
14
*
32
}
33
34
/*
35
+ * __construct
36
+ *
37
+ * This function will setup the field type data
38
+ *
39
+ * @type function
40
+ * @date 5/03/2014
41
+ * @since 5.0.0
42
+ *
43
+ * @param n/a
44
+ * @return n/a
45
+ */
46
function initialize() {
47
48
// vars
49
$this->name = 'qtranslate_image';
50
+ $this->label = __("Image (qTranslate)",'acf');
51
$this->category = __("qTranslate", 'acf');
52
$this->defaults = array(
53
'return_format' => 'array',
src/acf_5/fields/post_object.php ADDED
@@ -0,0 +1,164 @@
1
+ <?php
2
+
3
+ class acf_qtranslate_acf_5_post_object extends acf_field_post_object {
4
+
5
+ /**
6
+ * The plugin instance.
7
+ * @var \acf_qtranslate_plugin
8
+ */
9
+ protected $plugin;
10
+
11
+
12
+ /*
13
+ * __construct
14
+ *
15
+ * This function will setup the field type data
16
+ *
17
+ * @type function
18
+ * @date 5/03/2014
19
+ * @since 5.0.0
20
+ *
21
+ * @param n/a
22
+ * @return n/a
23
+ */
24
+ function __construct($plugin) {
25
+ $this->plugin = $plugin;
26
+
27
+ if (version_compare($plugin->acf_version(), '5.6.0') < 0) {
28
+ $this->initialize();
29
+ }
30
+
31
+ acf_field::__construct();
32
+ }
33
+
34
+ /*
35
+ * __construct
36
+ *
37
+ * This function will setup the field type data
38
+ *
39
+ * @type function
40
+ * @date 5/03/2014
41
+ * @since 5.0.0
42
+ *
43
+ * @param n/a
44
+ * @return n/a
45
+ */
46
+ function initialize() {
47
+
48
+ // vars
49
+ $this->name = 'qtranslate_post_object';
50
+ $this->label = __("Post Object (qTranslate)",'acf');
51
+ $this->category = 'qTranslate';
52
+ $this->defaults = array(
53
+ 'post_type' => array(),
54
+ 'taxonomy' => array(),
55
+ 'allow_null' => 0,
56
+ 'multiple' => 0,
57
+ 'return_format' => 'object',
58
+ 'ui' => 1,
59
+ );
60
+
61
+
62
+ // extra
63
+ add_action('wp_ajax_acf/fields/qtranslate_post_object/query', array($this, 'ajax_query'));
64
+ add_action('wp_ajax_nopriv_acf/fields/qtranslate_post_object/query', array($this, 'ajax_query'));
65
+
66
+ }
67
+
68
+ /*
69
+ * render_field()
70
+ *
71
+ * Create the HTML interface for your field
72
+ *
73
+ * @param $field - an array holding all the field's data
74
+ *
75
+ * @type action
76
+ * @since 3.6
77
+ * @date 10/07/18
78
+ */
79
+ function render_field($field) {
80
+ global $q_config;
81
+ $languages = qtrans_getSortedLanguages(true);
82
+ $values = array_map('maybe_unserialize', qtrans_split($field['value'], $quicktags = true));
83
+ $currentLanguage = $this->plugin->get_active_language();
84
+
85
+ // populate atts
86
+ $atts = array(
87
+ 'id' => $field['id'],
88
+ 'name' => $field['name'],
89
+ );
90
+
91
+ // render
92
+ echo '<div class="multi-language-field multi-language-field-post-object">';
93
+
94
+ foreach ($languages as $language) {
95
+ $class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
96
+ echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
97
+ }
98
+
99
+ foreach ($languages as $language) {
100
+ $class = ($language === $currentLanguage) ? 'acf-post-object current-language' : 'acf-post-object';
101
+ $field['id'] = $atts['id'] . "-$language";
102
+ $field['name'] = $atts['name'] . "[$language]";
103
+ $field['value'] = $values[$language];
104
+
105
+ echo '<div class="' . $class . '" data-language="' . $language . '">';
106
+ parent::render_field($field);
107
+ echo '</div>';
108
+ }
109
+
110
+ // return
111
+ echo '</div>';
112
+ }
113
+
114
+ /*
115
+ * format_value()
116
+ *
117
+ * This filter is appied to the $value after it is loaded from the db and before it is returned to the template
118
+ *
119
+ * @type filter
120
+ * @since 3.6
121
+ * @date 23/01/13
122
+ *
123
+ * @param $value (mixed) the value which was loaded from the database
124
+ * @param $post_id (mixed) the $post_id from which the value was loaded
125
+ * @param $field (array) the field array holding all the field options
126
+ *
127
+ * @return $value (mixed) the modified value
128
+ */
129
+ function format_value($value, $post_id, $field) {
130
+ $value = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($value);
131
+ $value = maybe_unserialize($value);
132
+
133
+ return parent::format_value($value, $post_id, $field);
134
+ }
135
+
136
+ /*
137
+ * update_value()
138
+ *
139
+ * This filter is appied to the $value before it is updated in the db
140
+ *
141
+ * @type filter
142
+ * @since 3.6
143
+ * @date 23/01/13
144
+ *
145
+ * @param $value - the value which will be saved in the database
146
+ * @param $post_id - the $post_id of which the value will be saved
147
+ * @param $field - the field array holding all the field options
148
+ *
149
+ * @return $value - the modified value
150
+ */
151
+ function update_value($values, $post_id, $field) {
152
+
153
+ // validate
154
+ if ( !is_array($values) ) return false;
155
+
156
+ foreach ($values as &$value) {
157
+ $value = parent::update_value($value, $post_id, $field);
158
+ $value = maybe_serialize($value);
159
+ }
160
+
161
+ return qtrans_join($values);
162
+ }
163
+
164
+ }
src/acf_5/fields/text.php CHANGED
@@ -47,7 +47,7 @@ class acf_qtranslate_acf_5_text extends acf_field_text {
47
48
// vars
49
$this->name = 'qtranslate_text';
50
- $this->label = __("Text",'acf');
51
$this->category = __("qTranslate",'acf');
52
$this->defaults = array(
53
'default_value' => '',
47
48
// vars
49
$this->name = 'qtranslate_text';
50
+ $this->label = __("Text (qTranslate)",'acf');
51
$this->category = __("qTranslate",'acf');
52
$this->defaults = array(
53
'default_value' => '',
src/acf_5/fields/textarea.php CHANGED
@@ -47,7 +47,7 @@ class acf_qtranslate_acf_5_textarea extends acf_field_textarea {
47
48
// vars
49
$this->name = 'qtranslate_textarea';
50
- $this->label = __("Text Area",'acf');
51
$this->category = __("qTranslate",'acf');
52
$this->defaults = array(
53
'default_value' => '',
47
48
// vars
49
$this->name = 'qtranslate_textarea';
50
+ $this->label = __("Text Area (qTranslate)",'acf');
51
$this->category = __("qTranslate",'acf');
52
$this->defaults = array(
53
'default_value' => '',
src/acf_5/fields/url.php CHANGED
@@ -1,18 +1,57 @@
1
<?php
2
3
- class acf_qtranslate_acf_5_url extends acf_qtranslate_acf_5_text {
4
function initialize() {
5
6
// vars
7
$this->name = 'qtranslate_url';
8
- $this->label = __("Url",'acf');
9
$this->category = __("qTranslate",'acf');
10
$this->defaults = array(
11
'default_value' => '',
12
- 'maxlength' => '',
13
'placeholder' => '',
14
- 'prepend' => '',
15
- 'append' => ''
16
);
17
18
}
@@ -35,90 +74,75 @@ class acf_qtranslate_acf_5_url extends acf_qtranslate_acf_5_text {
35
$currentLanguage = $this->plugin->get_active_language();
36
37
// vars
38
- $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' );
39
- $s = array( 'readonly', 'disabled' );
40
- $e = '';
41
42
- // maxlength
43
- if( $field['maxlength'] !== "" ) {
44
- $o[] = 'maxlength';
45
- }
46
47
- // populate atts
48
- $atts = array();
49
- foreach( $o as $k ) {
50
- $atts[ $k ] = $field[ $k ];
51
}
52
53
- // special atts
54
- foreach( $s as $k ) {
55
- if( isset($field[ $k ]) && $field[ $k ] ) {
56
- $atts[ $k ] = $k;
57
- }
58
}
59
60
// render
61
- $e .= '<div class="acf-url-wrap multi-language-field">';
62
63
foreach ($languages as $language) {
64
$class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
65
- $e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
66
}
67
68
foreach ($languages as $language) {
69
$atts['class'] = $field['class'];
70
-
71
- $atts['type'] = 'text';
72
- $atts['name'] = $field['name'] . "[$language]";
73
- $atts['value'] = $values[$language];
74
-
75
- $container_class = 'acf-input-wrap acf-url';
76
if ($language === $currentLanguage) {
77
- $container_class .= ' current-language';
78
}
79
-
80
- $e .= '<div class="' . $container_class . '" data-language="' . $language . '">';
81
- $e .= '<i class="acf-icon -globe -small"></i>';
82
- $e .= '<input ' . acf_esc_attr( $atts ) . ' />';
83
- $e .= '</div>';
84
-
85
}
86
87
- $e .= '</div>';
88
89
// return
90
- echo $e;
91
}
92
93
- function validate_value( $valid, $value, $field, $input ){
94
- foreach ($value as $valor) {
95
- // bail early if empty
96
- if ( empty( $valor ) ) {
97
-
98
- continue;
99
-
100
- }
101
-
102
- if ( strpos( $valor, '://' ) !== false ) {
103
-
104
- // url
105
-
106
- } elseif ( strpos( $valor, '//' ) === 0 ) {
107
-
108
- // protocol relative url
109
-
110
- } elseif ( strpos( $valor, '/' ) === 0 ) {
111
-
112
- // relative url
113
-
114
- } else {
115
-
116
- $valid = __( 'Value must be a valid URL', 'acf' );
117
-
118
- }
119
- }
120
-
121
- // return
122
- return $valid;
123
}
124
}
1
<?php
2
3
+ class acf_qtranslate_acf_5_url extends acf_field_url {
4
+
5
+ /**
6
+ * The plugin instance.
7
+ * @var \acf_qtranslate\plugin
8
+ */
9
+ protected $plugin;
10
+
11
+
12
+ /*
13
+ * __construct
14
+ *
15
+ * This function will setup the field type data
16
+ *
17
+ * @type function
18
+ * @date 5/03/2014
19
+ * @since 5.0.0
20
+ *
21
+ * @param n/a
22
+ * @return n/a
23
+ */
24
+ function __construct($plugin) {
25
+ $this->plugin = $plugin;
26
+
27
+ if (version_compare($plugin->acf_version(), '5.6.0') < 0) {
28
+ $this->initialize();
29
+ }
30
+
31
+ acf_field::__construct();
32
+ }
33
+
34
+ /*
35
+ * initialize
36
+ *
37
+ * This function will setup the field type data
38
+ *
39
+ * @type function
40
+ * @date 5/03/2014
41
+ * @since 5.0.0
42
+ *
43
+ * @param n/a
44
+ * @return n/a
45
+ */
46
function initialize() {
47
48
// vars
49
$this->name = 'qtranslate_url';
50
+ $this->label = __("Url (qTranslate)",'acf');
51
$this->category = __("qTranslate",'acf');
52
$this->defaults = array(
53
'default_value' => '',
54
'placeholder' => '',
55
);
56
57
}
74
$currentLanguage = $this->plugin->get_active_language();
75
76
// vars
77
+ $atts = array();
78
+ $keys = array( 'type', 'id', 'class', 'name', 'value', 'placeholder', 'pattern' );
79
+ $keys2 = array( 'readonly', 'disabled', 'required' );
80
+ $html = '';
81
82
83
+ // atts (value="123")
84
+ foreach( $keys as $k ) {
85
+ if( isset($field[ $k ]) ) $atts[ $k ] = $field[ $k ];
86
}
87
88
+
89
+ // atts2 (disabled="disabled")
90
+ foreach( $keys2 as $k ) {
91
+ if( !empty($field[ $k ]) ) $atts[ $k ] = $k;
92
}
93
94
+
95
+ // remove empty atts
96
+ $atts = acf_clean_atts( $atts );
97
+
98
+
99
// render
100
+ $html .= '<div class="acf-input-wrap multi-language-field">';
101
102
foreach ($languages as $language) {
103
$class = ($language === $currentLanguage) ? 'wp-switch-editor current-language' : 'wp-switch-editor';
104
+ $html .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>';
105
}
106
107
+ $html .= '<div class="acf-url">';
108
+ $html .= '<i class="acf-icon -globe -small"></i>';
109
+
110
foreach ($languages as $language) {
111
$atts['class'] = $field['class'];
112
if ($language === $currentLanguage) {
113
+ $atts['class'] .= ' current-language';
114
}
115
+ $atts['type'] = 'url';
116
+ $atts['name'] = $field['name'] . "[$language]";
117
+ $atts['value'] = $values[$language];
118
+ $atts['data-language'] = $language;
119
+ $html .= acf_get_text_input( $atts );
120
}
121
122
+ $html .= '</div>';
123
+ $html .= '</div>';
124
125
// return
126
+ echo $html;
127
}
128
129
+ /*
130
+ * update_value()
131
+ *
132
+ * This filter is appied to the $value before it is updated in the db
133
+ *
134
+ * @type filter
135
+ * @since 3.6
136
+ * @date 23/01/13
137
+ *
138
+ * @param $value - the value which will be saved in the database
139
+ * @param $post_id - the $post_id of which the value will be saved
140
+ * @param $field - the field array holding all the field options
141
+ *
142
+ * @return $value - the modified value
143
+ */
144
+ function update_value($value, $post_id, $field) {
145
+ return qtrans_join($value);
146
}
147
+
148
}
src/acf_5/fields/wysiwyg.php CHANGED
@@ -49,7 +49,7 @@ class acf_qtranslate_acf_5_wysiwyg extends acf_field_wysiwyg {
49
50
// vars
51
$this->name = 'qtranslate_wysiwyg';
52
- $this->label = __("Wysiwyg Editor",'acf');
53
$this->category = __("qTranslate",'acf');
54
$this->defaults = array(
55
'tabs' => 'all',
49
50
// vars
51
$this->name = 'qtranslate_wysiwyg';
52
+ $this->label = __("Wysiwyg Editor (qTranslate)",'acf');
53
$this->category = __("qTranslate",'acf');
54
$this->defaults = array(
55
'tabs' => 'all',