ACF qTranslate - Version 1.7.7

Version Description

  • Core: Added configuration page
  • Core: Support for Standard Field Types when using qTranslate-X is disabled by default
  • Core: Display standard language toggles when using qTranslate-X
  • Bug Fix: qTranslate-X problem with content from languages being mixed
  • Bug Fix: Corrected repeater problems introduced by qTranslate-X update
Download this release

Release Info

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

Code changes from version 1.7.6 to 1.7.7

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.6
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.7
7
  Author: funkjedi
8
  Author URI: http://funkjedi.com
9
  License: GPLv2 or later
assets/acf_4/main.js CHANGED
@@ -1,60 +0,0 @@
1
-
2
- /**
3
- * Handle qTranslate-X integrations after jQuery.ready()
4
- */
5
- jQuery(function($) {
6
- $(window).load(function() {
7
-
8
- // only proceed if qTranslate is loaded
9
- if (!qTranslateConfig || !qTranslateConfig.qtx) {
10
- return;
11
- }
12
-
13
- // Add display hooks to ACF metaboxes
14
- $('.acf_postbox h3 span').each(function() {
15
- this.id = _.uniqueId('acf-postbox-h3-span');
16
- qTranslateConfig.qtx.addDisplayHookById(this.id);
17
- });
18
-
19
- // Selectors for supported field types
20
- var field_types = [
21
- '.field_type-text input:text',
22
- '.field_type-textarea textarea',
23
- '.field_type-wysiwyg .wp-editor-area'
24
- ].join(',');
25
-
26
- // Remove content hooks from ACF Repeater and Flexible Fields clones
27
- $('.row-clone .qtranxs-translatable').each(function() {
28
- qTranslateConfig.qtx.removeContentHook(this);
29
- });
30
-
31
- // Add content hooks for existing fields
32
- $('.field_type-repeater .row, .field_type-flexible_content .row').each(function() {
33
- var row = $(this);
34
- row.find(field_types).not('.qtranxs-translatable').each(function() {
35
- qTranslateConfig.qtx.addContentHookC(this, row.closest('form').get(0));
36
- });
37
- })
38
-
39
- // Watch and add content hooks when new fields are added
40
- $(document).on('acf/setup_fields', function(e, new_field) {
41
- new_field = $(new_field);
42
- if (new_field.hasClass('row')) {
43
- new_field.find(field_types).not('.qtranxs-translatable').each(function() {
44
- qTranslateConfig.qtx.addContentHookC(this, new_field.closest('form').get(0));
45
- });
46
- }
47
- });
48
-
49
- // Watch and remove content hooks when fields are removed
50
- $('body').on('click', '.row .acf-button-remove', function() {
51
- var row = $(this).closest('.row');
52
- row.find(field_types).filter('.qtranxs-translatable').each(function() {
53
- qTranslateConfig.qtx.removeContentHook(this);
54
- });
55
- });
56
-
57
- });
58
- });
59
-
60
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/acf_4/qtranslatex.js ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ jQuery(window).load(function() {
3
+
4
+ // Only proceed if qTranslate is loaded
5
+ if (typeof qTranslateConfig != 'object' || typeof qTranslateConfig.qtx != 'object') {
6
+ return;
7
+ }
8
+
9
+ // Enable the language switching buttons
10
+ qTranslateConfig.qtx.enableLanguageSwitchingButtons('block');
11
+
12
+ // Add display hooks to ACF metaboxes
13
+ jQuery('.acf_postbox h3 span').each(function() {
14
+ this.id = _.uniqueId('acf-postbox-h3-span');
15
+ qTranslateConfig.qtx.addDisplayHookById(this.id);
16
+ });
17
+
18
+
19
+ // Ensure that translation of standard field types is enabled
20
+ if (!window.acf_qtranslate_translate_standard_field_types) {
21
+ return;
22
+ }
23
+
24
+ // Selectors for supported field types
25
+ var field_types = [
26
+ '.field_type-text input:text',
27
+ '.field_type-textarea textarea',
28
+ '.field_type-wysiwyg .wp-editor-area'
29
+ ].join(',');
30
+
31
+ // Remove content hooks from ACF Fields
32
+ jQuery('.acf_postbox .field').find('.qtranxs-translatable').each(function() {
33
+ qTranslateConfig.qtx.removeContentHook(this);
34
+ });
35
+
36
+ // Watch and add content hooks when new fields are added
37
+ var timeoutContentHooksTinyMCE;
38
+ jQuery(document).on('acf/setup_fields', function(e, new_field) {
39
+ new_field = jQuery(new_field);
40
+ new_field.find(field_types).not('.qtranxs-translatable').each(function() {
41
+ var field = jQuery(this);
42
+
43
+ // Skip over fields inside of ACF Repeater
44
+ // and Flexible Content clone rows
45
+ if (field.parents('.row-clone').length) {
46
+ return;
47
+ }
48
+
49
+ qTranslateConfig.qtx.addContentHookC(this, field.closest('form').get(0));
50
+
51
+ // Since ACFv4 doesn't update tinyMCEPreInit.mceInit so we
52
+ // need to manully set it so that the translation hooks apply properly
53
+ if (field.hasClass('wp-editor-area')) {
54
+ if (typeof tinyMCEPreInit.mceInit[this.id] == 'undefined') {
55
+ var mceInit = jQuery.extend({}, tinyMCEPreInit.mceInit.acf_settings);
56
+ mceInit.id = this.id;
57
+ tinyMCEPreInit.mceInit[this.id] = mceInit;
58
+ }
59
+ }
60
+ });
61
+
62
+ // Run in a setTimeout block to give the tinyMCE instance
63
+ // enough time to initialize before setting the editor hooks
64
+ clearTimeout(timeoutContentHooksTinyMCE);
65
+ timeoutContentHooksTinyMCE = setTimeout(function(){
66
+ qTranslateConfig.qtx.addContentHooksTinyMCE();
67
+ jQuery.each(tinyMCE.editors, function(i, ed){
68
+ var mceInit = tinyMCEPreInit.mceInit[ed.id];
69
+ console.log('initEditors:',mceInit);
70
+ if (mceInit && mceInit.init_instance_callback) {
71
+ mceInit.init_instance_callback(ed);
72
+ }
73
+ });
74
+ }, 50);
75
+ });
76
+
77
+ // Watch and remove content hooks when fields are removed
78
+ jQuery('body').on('click', '.row .acf-button-remove', function() {
79
+ var row = jQuery(this).closest('.row');
80
+ row.find(field_types).filter('.qtranxs-translatable').each(function() {
81
+ qTranslateConfig.qtx.removeContentHook(this);
82
+ });
83
+ });
84
+
85
+ });
assets/acf_5/main.js CHANGED
@@ -44,74 +44,3 @@ acf.fields.qtranslate_wysiwyg = acf.fields.wysiwyg.extend({
44
  this.focus();
45
  }
46
  });
47
-
48
-
49
-
50
- /**
51
- * Handle qTranslate-X integrations after jQuery.ready()
52
- */
53
- jQuery(function($) {
54
- $(window).load(function() {
55
-
56
- // only proceed if qTranslate is loaded
57
- if (!qTranslateConfig || !qTranslateConfig.qtx) {
58
- return;
59
- }
60
-
61
- // Add display hooks to ACF metaboxes
62
- $('.acf-postbox h3 span').each(function() {
63
- this.id = _.uniqueId('acf-postbox-h3-span');
64
- qTranslateConfig.qtx.addDisplayHookById(this.id);
65
- });
66
-
67
- // Selectors for supported field types
68
- var field_types = {
69
- repeater: 'input:hidden',
70
- flexible_content: 'input:hidden',
71
- text: 'input:text',
72
- textarea: 'textarea',
73
- wysiwyg: '.wp-editor-area',
74
- };
75
-
76
- // Remove content hooks from ACF Repeater and Flexible Fields clones
77
- $('.acf-clone .wp-editor-area.qtranxs-translatable').each(function() {
78
- qTranslateConfig.qtx.removeContentHook(this);
79
- });
80
-
81
- // Setup field types
82
- $.each(field_types, function(field_type, selector) {
83
-
84
- // Add content hooks for existing fields
85
- acf.get_fields({ type: field_type }).each(function() {
86
- var form = $(this).closest('form').get(0);
87
- var field = $(this).find(selector).get(0);
88
- qTranslateConfig.qtx.addContentHookC(field, form);
89
- });
90
-
91
- // Watch and add content hooks when new fields are added
92
- acf.add_action('append_field/type=' + field_type, function($el) {
93
- var form = $el.closest('form').get(0);
94
- var field = $el.find(selector).get(0);
95
- qTranslateConfig.qtx.addContentHookC(field, form);
96
- // Run at higher integer priority than the default in case the ACF handlers
97
- // change the id of the underlying input
98
- }, 100);
99
-
100
- });
101
-
102
- // Watch and remove content hooks when fields are removed
103
- // however ACF removes the elements from the DOM early so
104
- // we must hook into handler and perform updates there
105
- var _hooked_repeater_remove = acf.fields.repeater.remove;
106
- acf.fields.repeater.remove = function(event) {
107
- var row = event.$el.closest('.acf-row');
108
- row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() {
109
- qTranslateConfig.qtx.removeContentHook(this);
110
- });
111
- // call the original handler
112
- _hooked_repeater_remove.call(this, event);
113
- }
114
-
115
- });
116
- });
117
-
44
  this.focus();
45
  }
46
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/acf_5/qtranslatex.js ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ (function(){
3
+ var windowLoadCompleted = false;
4
+ jQuery(window).load(function() {
5
+
6
+ // Prevent from being triggered again
7
+ if (windowLoadCompleted) {
8
+ return;
9
+ }
10
+
11
+ windowLoadCompleted = true;
12
+
13
+ // Only proceed if qTranslate is loaded
14
+ if (typeof qTranslateConfig != 'object' || typeof qTranslateConfig.qtx != 'object') {
15
+ return;
16
+ }
17
+
18
+ // Enable the language switching buttons
19
+ qTranslateConfig.qtx.enableLanguageSwitchingButtons('block');
20
+
21
+ // Add display hooks to ACF metaboxes
22
+ jQuery('.acf-postbox h3 span').each(function() {
23
+ this.id = _.uniqueId('acf-postbox-h3-span');
24
+ qTranslateConfig.qtx.addDisplayHookById(this.id);
25
+ });
26
+
27
+
28
+ // Ensure that translation of standard field types is enabled
29
+ if (!window.acf_qtranslate_translate_standard_field_types) {
30
+ return;
31
+ }
32
+
33
+ // Selectors for supported field types
34
+ var field_types = {
35
+ text: 'input:text',
36
+ textarea: 'textarea',
37
+ wysiwyg: '.wp-editor-area',
38
+ };
39
+
40
+ // Remove content hooks from ACF Fields
41
+ jQuery('.acf-postbox .acf-field').find('.qtranxs-translatable').each(function() {
42
+ qTranslateConfig.qtx.removeContentHook(this);
43
+ });
44
+
45
+ // Setup field types
46
+ jQuery.each(field_types, function(field_type, selector) {
47
+
48
+ // Add content hooks for existing fields
49
+ acf.get_fields({ type: field_type }).each(function() {
50
+ var form = jQuery(this).closest('form').get(0);
51
+ var field = jQuery(this).find(selector).get(0);
52
+ qTranslateConfig.qtx.addContentHookC(field, form);
53
+ });
54
+
55
+ // Watch and add content hooks when new fields are added
56
+ acf.add_action('append_field/type=' + field_type, function($el) {
57
+ var form = $el.closest('form').get(0);
58
+ var field = $el.find(selector).get(0);
59
+ qTranslateConfig.qtx.addContentHookC(field, form);
60
+
61
+ if (jQuery(field).hasClass('wp-editor-area')) {
62
+ qTranslateConfig.qtx.addContentHooksTinyMCE();
63
+
64
+ // We must manually trigger load event so that the
65
+ // loadTinyMceHooks function which calls setEditorHooks is executed
66
+ var loadEvent = document.createEvent('UIEvents');
67
+ loadEvent.initEvent('load',false,false,window);
68
+ window.dispatchEvent(loadEvent);
69
+ }
70
+
71
+ // Run at higher integer priority than the default in case the ACF handlers
72
+ // change the id of the underlying input
73
+ }, 100);
74
+
75
+ });
76
+
77
+ qTranslateConfig.qtx.addContentHooksTinyMCE();
78
+
79
+ // Watch and remove content hooks when fields are removed
80
+ // however ACF removes the elements from the DOM early so
81
+ // we must hook into handler and perform updates there
82
+ var _hooked_repeater_remove = acf.fields.repeater.remove;
83
+ acf.fields.repeater.remove = function(event) {
84
+ var row = event.$el.closest('.acf-row');
85
+ row.find(_.toArray(field_types).join(',')).filter('.qtranxs-translatable').each(function() {
86
+ qTranslateConfig.qtx.removeContentHook(this);
87
+ });
88
+ // call the original handler
89
+ _hooked_repeater_remove.call(this, event);
90
+ };
91
+
92
+ });
93
+
94
+ })();
assets/common.css CHANGED
@@ -23,7 +23,8 @@
23
  margin-top: -38px;
24
  }
25
 
26
- .acf-table .multi-language-field {
 
27
  margin-top: -6px;
28
  }
29
 
23
  margin-top: -38px;
24
  }
25
 
26
+ .acf-table .multi-language-field,
27
+ .acf-input-table .multi-language-field {
28
  margin-top: -6px;
29
  }
30
 
assets/common.js CHANGED
@@ -8,7 +8,6 @@ jQuery(function($) {
8
  */
9
  $body.on('click', '.qtranxs-lang-switch', function() {
10
  var parent = $('.multi-language-field'), language = $(this).attr('lang');
11
-
12
  parent.find('.current-language').removeClass('current-language');
13
  parent.find('[data-language="' + language + '"]').addClass('current-language');
14
  parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]');
@@ -19,7 +18,6 @@ jQuery(function($) {
19
  */
20
  $body.on('click', '.wp-switch-editor[data-language]', function() {
21
  var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
22
-
23
  parent.find('.current-language').removeClass('current-language');
24
  parent.find('[data-language="' + language + '"]').addClass('current-language');
25
  parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
@@ -40,27 +38,11 @@ jQuery(function($) {
40
  * Keep the selected editor in sync across languages.
41
  */
42
  $body.on('click', '.wp-editor-tabs .wp-switch-editor', function() {
43
- var parent = $(this).parents('.multi-language-field'), editor = $(this).hasClass('switch-tmce') ? 'tmce' : 'html';
 
44
  parent.find('.wp-editor-tabs .wp-switch-editor.switch-' + editor).not(this).each(function() {
45
  switchEditors.switchto(this);
46
  });
47
  });
48
 
49
-
50
- /**
51
- * Handle qTranslate-X integrations after jQuery.ready()
52
- */
53
- $(window).load(function() {
54
- // only proceed if qTranslate is loaded
55
- if (!qTranslateConfig || !qTranslateConfig.qtx) {
56
- return;
57
- }
58
-
59
- // Add display hooks to ACF metaboxes
60
- $('.acf_postbox h3 span, .acf-postbox h3 span').each(function() {
61
- this.id = _.uniqueId('acf-postbox-h3-span');
62
- qTranslateConfig.qtx.addDisplayHookById(this.id);
63
- });
64
- });
65
-
66
  });
8
  */
9
  $body.on('click', '.qtranxs-lang-switch', function() {
10
  var parent = $('.multi-language-field'), language = $(this).attr('lang');
 
11
  parent.find('.current-language').removeClass('current-language');
12
  parent.find('[data-language="' + language + '"]').addClass('current-language');
13
  parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]');
18
  */
19
  $body.on('click', '.wp-switch-editor[data-language]', function() {
20
  var parent = $(this).parent('.multi-language-field'), language = $(this).data('language');
 
21
  parent.find('.current-language').removeClass('current-language');
22
  parent.find('[data-language="' + language + '"]').addClass('current-language');
23
  parent.find('input[data-language="' + language + '"], textarea[data-language="' + language + '"]').focus();
38
  * Keep the selected editor in sync across languages.
39
  */
40
  $body.on('click', '.wp-editor-tabs .wp-switch-editor', function() {
41
+ var parent = $(this).parents('.multi-language-field'),
42
+ editor = $(this).hasClass('switch-tmce') ? 'tmce' : 'html';
43
  parent.find('.wp-editor-tabs .wp-switch-editor.switch-' + editor).not(this).each(function() {
44
  switchEditors.switchto(this);
45
  });
46
  });
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  });
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.1.1
6
- Version: 1.7.6
7
- Stable tag: 1.7.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -23,7 +23,7 @@ This plugin provides qTranslate (qTranslate-X, qTranslate Plus and mqTranslate)
23
  * qTranslate File (upload a file, api returns the url)
24
 
25
  = qTranslate-X =
26
- If using qTranslate-X the standard Text, Text Area and WYSIWYG field types all automatically support translation out of the box.
27
 
28
  = Bug Submission =
29
  https://github.com/funkjedi/acf-qtranslate/issues/
@@ -59,6 +59,13 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
59
 
60
  == Changelog ==
61
 
 
 
 
 
 
 
 
62
  = 1.7.6 =
63
  * Core: qTranslate-X support for Text, Text Area and WYSIWYG inside repeater
64
  * Bug Fix: Display qTranslate-X switcher for qTranslate Field Types
@@ -118,5 +125,8 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
118
 
119
  == Upgrade Notice ==
120
 
 
 
 
121
  = 1.7.3 =
122
  Removed namespaces to make code compatible with PHP 5.2
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.2.1
6
+ Version: 1.7.7
7
+ Stable tag: 1.7.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
23
  * qTranslate File (upload a file, api returns the url)
24
 
25
  = qTranslate-X =
26
+ If using qTranslate-X the standard Text, Text Area and WYSIWYG field types can be enabled for translation.
27
 
28
  = Bug Submission =
29
  https://github.com/funkjedi/acf-qtranslate/issues/
59
 
60
  == Changelog ==
61
 
62
+ = 1.7.7 =
63
+ * Core: Added configuration page
64
+ * Core: Support for Standard Field Types when using qTranslate-X is disabled by default
65
+ * Core: Display standard language toggles when using qTranslate-X
66
+ * Bug Fix: qTranslate-X problem with content from languages being mixed
67
+ * Bug Fix: Corrected repeater problems introduced by qTranslate-X update
68
+
69
  = 1.7.6 =
70
  * Core: qTranslate-X support for Text, Text Area and WYSIWYG inside repeater
71
  * Bug Fix: Display qTranslate-X switcher for qTranslate Field Types
125
 
126
  == Upgrade Notice ==
127
 
128
+ = 1.7.7 =
129
+ If using qTranslate-X translation of the standard Text, Text Area and WYSIWYG field types is now disabled by default.
130
+
131
  = 1.7.3 =
132
  Removed namespaces to make code compatible with PHP 5.2
src/acf_4/acf.php CHANGED
@@ -18,9 +18,9 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
18
  public function __construct($plugin) {
19
  $this->plugin = $plugin;
20
 
21
- add_filter('acf/format_value_for_api', array($this, 'format_value_for_api'));
22
- add_action('acf/register_fields', array($this, 'register_fields'));
23
- add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
24
 
25
  $this->monkey_patch_qtranslate();
26
  }
@@ -46,11 +46,7 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
46
  * Load javascript and stylesheets on admin pages.
47
  */
48
  public function admin_enqueue_scripts() {
49
- if ($this->get_visible_acf_fields()) {
50
- wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
51
- wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
52
- wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_4/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
53
- }
54
  }
55
 
56
  /**
18
  public function __construct($plugin) {
19
  $this->plugin = $plugin;
20
 
21
+ add_filter('acf/format_value_for_api', array($this, 'format_value_for_api'));
22
+ add_action('acf/register_fields', array($this, 'register_fields'));
23
+ add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
24
 
25
  $this->monkey_patch_qtranslate();
26
  }
46
  * Load javascript and stylesheets on admin pages.
47
  */
48
  public function admin_enqueue_scripts() {
49
+ wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_4/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
 
 
 
 
50
  }
51
 
52
  /**
src/acf_5/acf.php CHANGED
@@ -44,11 +44,7 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
44
  * Load javascript and stylesheets on admin pages.
45
  */
46
  public function admin_enqueue_scripts() {
47
- if ($this->get_visible_acf_fields()) {
48
- wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
49
- wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
50
- wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
51
- }
52
  }
53
 
54
  /**
44
  * Load javascript and stylesheets on admin pages.
45
  */
46
  public function admin_enqueue_scripts() {
47
+ wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
 
 
 
 
48
  }
49
 
50
  /**
src/plugin.php CHANGED
@@ -2,12 +2,24 @@
2
 
3
  class acf_qtranslate_plugin {
4
 
 
 
 
 
 
 
 
5
  /**
6
  * Create an instance.
7
  * @return void
8
  */
9
  public function __construct() {
10
- add_action('plugins_loaded', array($this, 'plugins_loaded'), 3);
 
 
 
 
 
11
  }
12
 
13
  /**
@@ -20,25 +32,25 @@ class acf_qtranslate_plugin {
20
  // setup qtranslate fields for ACF 4
21
  if ($this->acf_major_version() === 4) {
22
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/acf.php';
23
- $acf = new acf_qtranslate_acf_4($this);
24
  }
25
 
26
  // setup qtranslate fields for ACF 5
27
  if ($this->acf_major_version() === 5) {
28
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/acf.php';
29
- $acf = new acf_qtranslate_acf_5($this);
30
  }
31
 
32
  // setup ppqtranslate integration
33
  if ($this->ppqtranslate_enabled()) {
34
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/ppqtranslate.php';
35
- new acf_qtranslate_ppqtranslate($this, $acf);
36
  }
37
 
38
  // setup qtranslatex integration
39
  if ($this->qtranslatex_enabled()) {
40
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/qtranslatex.php';
41
- new acf_qtranslate_qtranslatex($this, $acf);
42
  }
43
 
44
  }
@@ -138,4 +150,117 @@ class acf_qtranslate_plugin {
138
  return apply_filters('acf_qtranslate_get_active_language', qtrans_getLanguage());
139
  }
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
2
 
3
  class acf_qtranslate_plugin {
4
 
5
+ /**
6
+ * An ACF instance.
7
+ * @var \acf_qtranslate_acf_interface
8
+ */
9
+ protected $acf;
10
+
11
+
12
  /**
13
  * Create an instance.
14
  * @return void
15
  */
16
  public function __construct() {
17
+ add_action('plugins_loaded', array($this, 'plugins_loaded'), 3);
18
+ add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
19
+ add_action('admin_menu', array($this, 'admin_menu'));
20
+ add_action('admin_init', array($this, 'admin_init'));
21
+
22
+ add_filter('plugin_action_links_' . plugin_basename(ACF_QTRANSLATE_PLUGIN), array($this, 'plugin_action_links'));
23
  }
24
 
25
  /**
32
  // setup qtranslate fields for ACF 4
33
  if ($this->acf_major_version() === 4) {
34
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_4/acf.php';
35
+ $this->acf = new acf_qtranslate_acf_4($this);
36
  }
37
 
38
  // setup qtranslate fields for ACF 5
39
  if ($this->acf_major_version() === 5) {
40
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/acf_5/acf.php';
41
+ $this->acf = new acf_qtranslate_acf_5($this);
42
  }
43
 
44
  // setup ppqtranslate integration
45
  if ($this->ppqtranslate_enabled()) {
46
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/ppqtranslate.php';
47
+ new acf_qtranslate_ppqtranslate($this, $this->acf);
48
  }
49
 
50
  // setup qtranslatex integration
51
  if ($this->qtranslatex_enabled()) {
52
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'src/qtranslatex.php';
53
+ new acf_qtranslate_qtranslatex($this, $this->acf);
54
  }
55
 
56
  }
150
  return apply_filters('acf_qtranslate_get_active_language', qtrans_getLanguage());
151
  }
152
 
153
+ /**
154
+ * Load javascript and stylesheets on admin pages.
155
+ */
156
+ public function admin_enqueue_scripts() {
157
+ wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
158
+ wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input','underscore'));
159
+ }
160
+
161
+ /**
162
+ * Add settings link on plugin page.
163
+ * @param array
164
+ * @return array
165
+ */
166
+ public function plugin_action_links($links) {
167
+ array_unshift($links, '<a href="options-general.php?page=acf-qtranslate">Settings</a>');
168
+ return $links;
169
+ }
170
+
171
+ /**
172
+ * Retrieve the value of a plugin setting.
173
+ */
174
+ function get_plugin_setting($name, $default = null) {
175
+ $options = get_option('acf_qtranslate');
176
+ if (isset($options[$name]) === true) {
177
+ return $options[$name];
178
+ }
179
+ return $default;
180
+ }
181
+
182
+ /**
183
+ * Register the options page with the Wordpress menu.
184
+ */
185
+ function admin_menu() {
186
+ add_options_page('ACF qTranslate', 'ACF qTranslate', 'manage_options', 'acf-qtranslate', array($this, 'options_page'));
187
+ }
188
+
189
+ /**
190
+ * Register settings and default fields.
191
+ */
192
+ function admin_init() {
193
+ register_setting('acf_qtranslate', 'acf_qtranslate');
194
+
195
+ add_settings_section(
196
+ 'qtranslatex_section',
197
+ 'qTranslate-X',
198
+ array($this, 'render_section_qtranslatex'),
199
+ 'acf_qtranslate'
200
+ );
201
+
202
+ add_settings_field(
203
+ 'translate_standard_field_types',
204
+ 'Enable translation for Standard Field Types',
205
+ array($this, 'render_setting_translate_standard_field_types'),
206
+ 'acf_qtranslate',
207
+ 'qtranslatex_section'
208
+ );
209
+
210
+ add_settings_field(
211
+ 'show_language_tabs',
212
+ 'Display language tabs',
213
+ array($this, 'render_setting_show_language_tabs'),
214
+ 'acf_qtranslate',
215
+ 'qtranslatex_section'
216
+ );
217
+ }
218
+
219
+ /**
220
+ * Render the options page.
221
+ */
222
+ function options_page() {
223
+ ?>
224
+ <form action="options.php" method="post">
225
+ <h2>ACF qTranslate Settings</h2>
226
+ <br>
227
+ <?php
228
+
229
+ settings_fields('acf_qtranslate');
230
+ do_settings_sections('acf_qtranslate');
231
+ submit_button();
232
+
233
+ ?>
234
+ </form>
235
+ <?php
236
+ }
237
+
238
+ /**
239
+ * Render the qTranslate-X section.
240
+ */
241
+ function render_section_qtranslatex() {
242
+ ?>
243
+ The following options represent additional functionality that is available when
244
+ using qTranslate-X. These functionality is off by default and must be enabled below.
245
+ <?php
246
+ }
247
+
248
+ /**
249
+ * Render setting.
250
+ */
251
+ function render_setting_translate_standard_field_types() {
252
+ ?>
253
+ <input type="checkbox" name="acf_qtranslate[translate_standard_field_types]" <?php checked($this->get_plugin_setting('translate_standard_field_types'), 1); ?> value="1">
254
+ <?php
255
+ }
256
+
257
+ /**
258
+ * Render setting.
259
+ */
260
+ function render_setting_show_language_tabs() {
261
+ ?>
262
+ <input type="checkbox" name="acf_qtranslate[show_language_tabs]" <?php checked($this->get_plugin_setting('show_language_tabs'), 1); ?> value="1">
263
+ <?php
264
+ }
265
+
266
  }
src/ppqtranslate.php CHANGED
@@ -27,7 +27,6 @@ class acf_qtranslate_ppqtranslate {
27
 
28
  // include compatibility functions
29
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/ppqtranslate.php';
30
-
31
  }
32
 
33
  }
27
 
28
  // include compatibility functions
29
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/ppqtranslate.php';
 
30
  }
31
 
32
  }
src/qtranslatex.php CHANGED
@@ -29,58 +29,43 @@ class acf_qtranslate_qtranslatex {
29
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/qtranslatex.php';
30
 
31
  add_action('admin_head', array($this, 'admin_head'));
32
- add_action('admin_footer', array($this, 'admin_footer'), 9999); //after qTranslate-X
33
  add_filter('qtranslate_custom_admin_js', array($this, 'qtranslate_custom_admin_js'));
34
- add_filter('qtranslate_load_admin_page_config', array($this, 'qtranslate_load_admin_page_config'));
35
  add_filter('acf_qtranslate_get_active_language', array($this, 'get_active_language'));
 
36
  }
37
 
38
  /**
39
- * Add class to the body element.
40
  */
41
  public function admin_head() {
42
- ?>
43
- <style>
44
- .multi-language-field {margin-top:0!important;}
45
- .multi-language-field .wp-switch-editor[data-language] {display:none!important;}
46
- </style>
47
- <?php
48
- }
49
-
50
- /**
51
- * Load custom version of edit-post.js if needed.
52
- */
53
- public function admin_footer() {
54
- if (wp_script_is('qtranslate-admin-edit')) {
55
-
56
- //$handle = wp_script_is('qtranslate-admin-edit', 'registered');
57
-
58
- //wp_register_script('qtranslate-admin-edit', $script_url, array(), QTX_VERSION);
59
- //wp_enqueue_script('qtranslate-admin-edit');
60
 
 
 
 
 
 
 
 
 
61
  }
62
  }
63
 
64
  /**
65
- * Load ACF form element ids into qTranslate-X.
66
- * @return void
67
  */
68
- public function qtranslate_load_admin_page_config($configs) {
69
- global $pagenow;
70
-
71
- $fields = $this->acf->get_visible_acf_fields();
72
- if (count($fields)) {
73
- // ACF uses a single tinyMCE editor mceInit
74
- // for all it's WYSIWYG fields
75
- $fields[] = array('id' => 'acf_settings');
76
-
77
- array_push($configs, array(
78
- 'pages' => array($pagenow => ''),
79
- 'forms' => array(array('fields' => $fields))
80
- ));
81
- }
82
-
83
- return $configs;
84
  }
85
 
86
  /**
29
  require_once ACF_QTRANSLATE_PLUGIN_DIR . 'compatibility/qtranslatex.php';
30
 
31
  add_action('admin_head', array($this, 'admin_head'));
 
32
  add_filter('qtranslate_custom_admin_js', array($this, 'qtranslate_custom_admin_js'));
 
33
  add_filter('acf_qtranslate_get_active_language', array($this, 'get_active_language'));
34
+ add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
35
  }
36
 
37
  /**
38
+ * Add additional styles and scripts to head.
39
  */
40
  public function admin_head() {
41
+ // Hide the language tabs if they shouldn't be displayed
42
+ $show_language_tabs = $this->plugin->get_plugin_setting('show_language_tabs');
43
+ if (!$show_language_tabs) {
44
+ ?>
45
+ <style>
46
+ .multi-language-field {margin-top:0!important;}
47
+ .multi-language-field .wp-switch-editor[data-language] {display:none!important;}
48
+ </style>
49
+ <?php
50
+ }
 
 
 
 
 
 
 
 
51
 
52
+ // Enable translation of standard field types
53
+ $translate_standard_field_types = $this->plugin->get_plugin_setting('translate_standard_field_types');
54
+ if ($translate_standard_field_types) {
55
+ ?>
56
+ <script>
57
+ var acf_qtranslate_translate_standard_field_types = <?= json_encode($translate_standard_field_types) ?>;
58
+ </script>
59
+ <?php
60
  }
61
  }
62
 
63
  /**
64
+ * Load javascript and stylesheets on admin pages.
 
65
  */
66
+ public function admin_enqueue_scripts() {
67
+ $version = $this->plugin->acf_major_version();
68
+ wp_enqueue_script('acf_qtranslatex', plugins_url("/assets/acf_{$version}/qtranslatex.js", ACF_QTRANSLATE_PLUGIN), array('acf_qtranslate_common'));
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  }
70
 
71
  /**