ACF qTranslate - Version 1.7.4

Version Description

  • Bug Fix: Only load admin javascript when there are visible ACF fields
Download this release

Release Info

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

Code changes from version 1.7.3 to 1.7.4

Files changed (5) hide show
  1. acf-qtranslate.php +1 -1
  2. readme.txt +17 -11
  3. src/acf_4/acf.php +37 -5
  4. src/acf_5/acf.php +22 -7
  5. src/qtranslatex.php +2 -2
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.3
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.4
7
  Author: funkjedi
8
  Author URI: http://funkjedi.com
9
  License: GPLv2 or later
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.1.1
6
- Version: 1.7.3
7
- Stable tag: 1.7.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -13,7 +13,7 @@ Provides qTranslate compatible ACF field types for Text, Text Area, WYSIWYG, Ima
13
 
14
  == Description ==
15
 
16
- This plugin adds a new Field Type category called qTranslate. This contains qTranslate compatible fields for Text, Text Area, WYSIWYG, Image and File.
17
 
18
  = Field Types =
19
  * qTranslate Text (type text, api returns text)
@@ -31,16 +31,19 @@ https://github.com/funkjedi/acf-qtranslate/issues/
31
 
32
  == Installation ==
33
 
34
- **This plugins requires a qTranslate-based plugin to be installed:**
 
 
 
 
 
35
 
36
- * [qTranslate](http://wordpress.org/extend/plugins/qtranslate/)
 
37
  * [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
38
  * [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/)
39
  * [mqTranslate](https://wordpress.org/plugins/mqtranslate/)
40
- * [zTranslate](http://wordpress.org/extend/plugins/ztranslate/)
41
-
42
- 1. Upload `acf-qtranslate` directory to the `/wp-content/plugins/` directory
43
- 2. Activate the plugin through the 'Plugins' menu in WordPress
44
 
45
 
46
  == Frequently Asked Questions ==
@@ -56,6 +59,9 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
56
 
57
  == Changelog ==
58
 
 
 
 
59
  = 1.7.3 =
60
  * Core: Removed namespaces to make code compatible with PHP 5.2
61
 
@@ -103,5 +109,5 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
103
 
104
  == Upgrade Notice ==
105
 
106
- = 1.7.1 =
107
- Added qTranslate-X support for the standard WYSIWYG field type
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.4
7
+ Stable tag: 1.7.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
13
 
14
  == Description ==
15
 
16
+ This plugin provides qTranslate (qTranslate-X, qTranslate Plus and mqTranslate) compatible ACF4 and ACF5PRO field types for Text, Text Area, WYSIWYG, Image and File. When adding a field to a field group these new field types will be listed under the qTranslate category in the Field Type dropdown.
17
 
18
  = Field Types =
19
  * qTranslate Text (type text, api returns text)
31
 
32
  == Installation ==
33
 
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 ACF4 or ACF5PRO
38
+ * [ACF](https://wordpress.org/plugins/advanced-custom-fields/)
39
+ * [ACF5PRO](http://www.advancedcustomfields.com/pro/)
40
 
41
+ = Requires qTranslate (or qTranslate-based) Plugin =
42
+ * [qTranslate](https://wordpress.org/extend/plugins/qtranslate/)
43
  * [qTranslate-X](https://wordpress.org/plugins/qtranslate-x/)
44
  * [qTranslate Plus](https://wordpress.org/plugins/qtranslate-xp/)
45
  * [mqTranslate](https://wordpress.org/plugins/mqtranslate/)
46
+ * [zTranslate](https://wordpress.org/extend/plugins/ztranslate/)
 
 
 
47
 
48
 
49
  == Frequently Asked Questions ==
59
 
60
  == Changelog ==
61
 
62
+ = 1.7.4 =
63
+ * Bug Fix: Only load admin javascript when there are visible ACF fields
64
+
65
  = 1.7.3 =
66
  * Core: Removed namespaces to make code compatible with PHP 5.2
67
 
109
 
110
  == Upgrade Notice ==
111
 
112
+ = 1.7.3 =
113
+ Removed namespaces to make code compatible with PHP 5.2
src/acf_4/acf.php CHANGED
@@ -46,8 +46,10 @@ 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
- wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
50
- wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
 
 
51
  }
52
 
53
  /**
@@ -69,6 +71,8 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
69
  global $post, $pagenow, $typenow, $plugin_page;
70
 
71
  $filter = array();
 
 
72
  if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
73
  if ($typenow !== 'acf') {
74
  $filter['post_id'] = apply_filters('acf/get_post_id', false);
@@ -76,7 +80,9 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
76
  }
77
  }
78
  elseif ($pagenow === 'admin.php' && isset($plugin_page)) {
79
- $filter['post_id'] = apply_filters('acf/get_post_id', false);
 
 
80
  }
81
  elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) {
82
  $filter['ef_taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING);
@@ -95,7 +101,7 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
95
  }
96
 
97
  if (count($filter) === 0) {
98
- return array();
99
  }
100
 
101
  $supported_field_types = array(
@@ -106,7 +112,6 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
106
 
107
  $visible_field_groups = apply_filters('acf/location/match_field_groups', array(), $filter);
108
 
109
- $visible_fields = array();
110
  foreach (apply_filters('acf/get_field_groups', array()) as $field_group) {
111
  if (in_array($field_group['id'], $visible_field_groups)) {
112
  $fields = apply_filters('acf/field_group/get_fields', array(), $field_group['id']);
@@ -121,6 +126,33 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
121
  return $visible_fields;
122
  }
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  /**
125
  * Monkey patches to fix little qTranslate javascript issues.
126
  */
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'));
52
+ }
53
  }
54
 
55
  /**
71
  global $post, $pagenow, $typenow, $plugin_page;
72
 
73
  $filter = array();
74
+ $visible_fields = array();
75
+
76
  if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
77
  if ($typenow !== 'acf') {
78
  $filter['post_id'] = apply_filters('acf/get_post_id', false);
80
  }
81
  }
82
  elseif ($pagenow === 'admin.php' && isset($plugin_page)) {
83
+ if ($this->acf_get_options_page($plugin_page)) {
84
+ $filter['post_id'] = apply_filters('acf/get_post_id', false);
85
+ }
86
  }
87
  elseif ($pagenow === 'edit-tags.php' && isset($_GET['taxonomy'])) {
88
  $filter['ef_taxonomy'] = filter_var($_GET['taxonomy'], FILTER_SANITIZE_STRING);
101
  }
102
 
103
  if (count($filter) === 0) {
104
+ return $visible_fields;
105
  }
106
 
107
  $supported_field_types = array(
112
 
113
  $visible_field_groups = apply_filters('acf/location/match_field_groups', array(), $filter);
114
 
 
115
  foreach (apply_filters('acf/get_field_groups', array()) as $field_group) {
116
  if (in_array($field_group['id'], $visible_field_groups)) {
117
  $fields = apply_filters('acf/field_group/get_fields', array(), $field_group['id']);
126
  return $visible_fields;
127
  }
128
 
129
+ /**
130
+ * Get details about ACF Options page.
131
+ */
132
+ public function acf_get_options_page($slug) {
133
+ global $acf_options_page;
134
+
135
+ if (is_array($acf_options_page->settings) === false) {
136
+ return false;
137
+ }
138
+
139
+ if ($acf_options_page->settings['slug'] === $slug) {
140
+ return array(
141
+ 'title' => $acf_options_page->settings['title'],
142
+ 'menu' => $acf_options_page->settings['menu'],
143
+ 'slug' => $acf_options_page->settings['slug'],
144
+ 'capability' => $acf_options_page->settings['capability'],
145
+ 'show_parent' => $acf_options_page->settings['show_parent'],
146
+ );
147
+ }
148
+
149
+ foreach ($acf_options_page->settings['pages'] as $page) {
150
+ if ($page['slug'] === $slug) {
151
+ return $page;
152
+ }
153
+ }
154
+ }
155
+
156
  /**
157
  * Monkey patches to fix little qTranslate javascript issues.
158
  */
src/acf_5/acf.php CHANGED
@@ -44,9 +44,11 @@ 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
- wp_enqueue_style('acf_qtranslate_common', plugins_url('/assets/common.css', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
48
- wp_enqueue_script('acf_qtranslate_common', plugins_url('/assets/common.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
49
- wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
 
 
50
  }
51
 
52
  /**
@@ -64,10 +66,12 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
64
  * Get the visible ACF fields.
65
  * @return array
66
  */
67
- public function get_visible_acf_fields() {
68
- global $post, $pagenow, $typenow, $plugin_page;
69
 
70
  $filter = array();
 
 
71
  if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
72
  if ($typenow !== 'acf') {
73
  $filter['post_id'] = $post->ID;
@@ -97,9 +101,21 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
97
  elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') {
98
  $filter['attachment'] = 'All';
99
  }
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  if (count($filter) === 0) {
102
- return array();
103
  }
104
 
105
  $supported_field_types = array(
@@ -108,7 +124,6 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
108
  'textarea',
109
  );
110
 
111
- $visible_fields = array();
112
  foreach (acf_get_field_groups($filter) as $field_group) {
113
  $fields = acf_get_fields($field_group);
114
  foreach ($fields as $field) {
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'));
50
+ wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
51
+ }
52
  }
53
 
54
  /**
66
  * Get the visible ACF fields.
67
  * @return array
68
  */
69
+ public function get_visible_acf_fields($id = null) {
70
+ global $post, $pagenow, $typenow, $plugin_page, $wp_registered_widgets;
71
 
72
  $filter = array();
73
+ $visible_fields = array();
74
+
75
  if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
76
  if ($typenow !== 'acf') {
77
  $filter['post_id'] = $post->ID;
101
  elseif ($pagenow === 'media.php' || $pagenow === 'upload.php') {
102
  $filter['attachment'] = 'All';
103
  }
104
+ elseif (acf_is_screen('widgets') || acf_is_screen('customize')) {
105
+ if ($id) {
106
+ $filter['widget'] = _get_widget_id_base($id);
107
+ }
108
+ else {
109
+ // process each widget form individually for any visible fields
110
+ // required due to how acf_get_field_group_visibility() works
111
+ foreach ($wp_registered_widgets as $widget) {
112
+ $visible_fields += $this->get_visible_acf_fields($widget['id']);
113
+ }
114
+ }
115
+ }
116
 
117
  if (count($filter) === 0) {
118
+ return $visible_fields;
119
  }
120
 
121
  $supported_field_types = array(
124
  'textarea',
125
  );
126
 
 
127
  foreach (acf_get_field_groups($filter) as $field_group) {
128
  $fields = acf_get_fields($field_group);
129
  foreach ($fields as $field) {
src/qtranslatex.php CHANGED
@@ -88,9 +88,9 @@ class acf_qtranslate_qtranslatex {
88
  * @return string
89
  */
90
  public function qtranslate_custom_admin_js() {
91
- global $pagenow;
92
 
93
- if ($pagenow === 'admin.php' && isset($_GET['page'])) {
94
  return 'admin/js/edit-post';
95
  }
96
  }
88
  * @return string
89
  */
90
  public function qtranslate_custom_admin_js() {
91
+ global $pagenow, $plugin_page;
92
 
93
+ if ($pagenow === 'admin.php' && isset($plugin_page)) {
94
  return 'admin/js/edit-post';
95
  }
96
  }