ACF qTranslate - Version 1.7.24

Version Description

  • Core: (asedano) Added ACF5 support for URL field
  • Bug Fix: (asedano) Added ACF 5.7 compatibility
  • Bug Fix: (asedano) Prevent PHP warnings about non-existent indexes
Download this release

Release Info

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

Code changes from version 1.7.23 to 1.7.24

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.23
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.24
7
Author: funkjedi
8
Author URI: http://funkjedi.com
9
License: GPLv2 or later
assets/acf_5/main.js CHANGED
@@ -1,51 +1,164 @@
1
-
2
/**
3
* Clone functionality from standard Image field type
4
*/
5
- acf.fields.qtranslate_image = acf.fields.image.extend({
6
- type: 'qtranslate_image',
7
- focus: function() {
8
- this.$el = this.$field.find('.acf-image-uploader.current-language');
9
- this.$input = this.$el.find('input[type="hidden"]');
10
- this.$img = this.$el.find('img');
11
-
12
- this.o = acf.get_data(this.$el);
13
}
14
- });
15
16
/**
17
* Clone functionality from standard File field type
18
*/
19
- acf.fields.qtranslate_file = acf.fields.file.extend({
20
- type: 'qtranslate_file',
21
- focus: function() {
22
- this.$el = this.$field.find('.acf-file-uploader.current-language');
23
- this.$input = this.$el.find('input[type="hidden"]');
24
25
- this.o = acf.get_data(this.$el);
26
}
27
- });
28
29
- /**
30
- * Clone functionality from standard WYSIWYG field type
31
- */
32
- acf.fields.qtranslate_wysiwyg = acf.fields.wysiwyg.extend({
33
- type: 'qtranslate_wysiwyg',
34
- focus: function() {
35
- this.$el = this.$field.find('.wp-editor-wrap.current-language').last();
36
- this.$textarea = this.$el.find('textarea');
37
- this.o = acf.get_data(this.$el);
38
- this.o.id = this.$textarea.attr('id');
39
- },
40
- initialize: function() {
41
- var self = this;
42
- this.$field.find('.wp-editor-wrap').each(function() {
43
- self.$el = jQuery(this);
44
- self.$textarea = self.$el.find('textarea');
45
- self.o = acf.get_data(self.$el);
46
- self.o.id = self.$textarea.attr('id');
47
- acf.fields.wysiwyg.initialize.call(self);
48
- });
49
- this.focus();
50
}
51
- });
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() {
86
+ var $wrap = $(this);
87
+ var $textarea = $wrap.find('textarea');
88
+ var args = {
89
+ tinymce: true,
90
+ quicktags: true,
91
+ toolbar: self.get('toolbar'),
92
+ mode: self.getMode(),
93
+ field: self
94
+ };
95
+
96
+ // generate new id
97
+ var oldId = $textarea.attr('id');
98
+ var newId = acf.uniqueId('acf-editor-');
99
+
100
+ // rename
101
+ acf.rename({
102
+ target: $wrap,
103
+ search: oldId,
104
+ replace: newId,
105
+ destructive: true
106
+ });
107
+
108
+ // update id
109
+ self.set('id', newId, true);
110
+
111
+ // initialize
112
+ acf.tinymce.initialize(newId, args);
113
+ });
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
+ }));
assets/common.css CHANGED
@@ -67,6 +67,7 @@
67
.multi-language-field > textarea,
68
.multi-language-field > fieldset,
69
.multi-language-field .acf_wysiwyg,
70
.multi-language-field .acf-editor-wrap,
71
.multi-language-field .acf-file-uploader,
72
.multi-language-field .acf-image-uploader { display: none }
@@ -79,6 +80,10 @@
79
margin-top: 0;
80
}
81
82
.multi-language-field .acf-file-uploader,
83
.multi-language-field .acf-image-uploader {
84
padding: 20px 10px 10px;
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 }
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,
88
.multi-language-field .acf-image-uploader {
89
padding: 20px 10px 10px;
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.23
7
- Stable tag: 1.7.23
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -21,6 +21,7 @@ This plugin provides qTranslate-X compatible ACF4 and ACF5PRO field types for Te
21
* qTranslate WYSIWYG (a wordpress wysiwyg editor, api returns html)
22
* qTranslate Image (upload an image, api returns the url)
23
* qTranslate File (upload a file, api returns the url)
24
25
The standard Text, Text Area and WYSIWYG field types can also be enabled for translation.
26
@@ -33,9 +34,9 @@ https://github.com/funkjedi/acf-qtranslate/issues/
33
1. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
34
2. Activate the plugin through the 'Plugins' menu in WordPress
35
36
- = Requires ACF4 or ACF5PRO =
37
* [ACF](https://wordpress.org/plugins/advanced-custom-fields/)
38
- * [ACF5PRO](http://www.advancedcustomfields.com/pro/)
39
40
= Requires qTranslate-X Plugin =
41
* [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
@@ -54,6 +55,11 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
54
55
== Changelog ==
56
57
= 1.7.23 =
58
* Bug Fix: Added ACF 5.6 compatibility
59
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
21
* qTranslate WYSIWYG (a wordpress wysiwyg editor, api returns html)
22
* qTranslate Image (upload an image, api returns the url)
23
* qTranslate File (upload a file, api returns the url)
24
+ * qTranslate URL (type text, api returns text)
25
26
The standard Text, Text Area and WYSIWYG field types can also be enabled for translation.
27
34
1. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
35
2. Activate the plugin through the 'Plugins' menu in WordPress
36
37
+ = Requires ACF or ACFPRO =
38
* [ACF](https://wordpress.org/plugins/advanced-custom-fields/)
39
+ * [ACFPRO](http://www.advancedcustomfields.com/pro/)
40
41
= Requires qTranslate-X Plugin =
42
* [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
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
61
+ * Bug Fix: (asedano) Prevent PHP warnings about non-existent indexes
62
+
63
= 1.7.23 =
64
* Bug Fix: Added ACF 5.6 compatibility
65
src/acf_5/acf.php CHANGED
@@ -32,12 +32,14 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
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
36
acf()->fields->register_field_type(new acf_qtranslate_acf_5_text($this->plugin));
37
acf()->fields->register_field_type(new acf_qtranslate_acf_5_textarea($this->plugin));
38
acf()->fields->register_field_type(new acf_qtranslate_acf_5_wysiwyg($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_file($this->plugin));
41
}
42
43
/**
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
/**
src/acf_5/fields/text.php CHANGED
@@ -94,7 +94,7 @@ class acf_qtranslate_acf_5_text extends acf_field_text {
94
95
// special atts
96
foreach( $s as $k ) {
97
- if( $field[ $k ] ) {
98
$atts[ $k ] = $k;
99
}
100
}
94
95
// special atts
96
foreach( $s as $k ) {
97
+ if( isset($field[ $k ]) && $field[ $k ] ) {
98
$atts[ $k ] = $k;
99
}
100
}
src/acf_5/fields/textarea.php CHANGED
@@ -99,7 +99,7 @@ class acf_qtranslate_acf_5_textarea extends acf_field_textarea {
99
100
// special atts
101
foreach( $s as $k ) {
102
- if( $field[ $k ] ) {
103
$atts[ $k ] = $k;
104
}
105
}
99
100
// special atts
101
foreach( $s as $k ) {
102
+ if( isset($field[ $k ]) && $field[ $k ] ) {
103
$atts[ $k ] = $k;
104
}
105
}
src/acf_5/fields/url.php ADDED
@@ -0,0 +1,124 @@
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
+ }
19
+
20
+ /*
21
+ * render_field()
22
+ *
23
+ * Create the HTML interface for your field
24
+ *
25
+ * @param $field - an array holding all the field's data
26
+ *
27
+ * @type action
28
+ * @since 3.6
29
+ * @date 23/01/13
30
+ */
31
+ function render_field($field) {
32
+ global $q_config;
33
+ $languages = qtrans_getSortedLanguages(true);
34
+ $values = qtrans_split($field['value'], $quicktags = true);
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
+ }
src/acf_5/fields/wysiwyg.php CHANGED
@@ -29,7 +29,6 @@ class acf_qtranslate_acf_5_wysiwyg extends acf_field_wysiwyg {
29
}
30
31
// actions
32
- add_action('acf/input/admin_footer', array($this, 'input_admin_footer'));
33
34
acf_field::__construct();
35
}
29
}
30
31
// actions
32
33
acf_field::__construct();
34
}