ACF qTranslate - Version 1.7.5

Version Description

  • Core: Updates to README file
  • Bug Fix: Updated to visible ACF fields detection
Download this release

Release Info

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

Code changes from version 1.7.4 to 1.7.5

Files changed (4) hide show
  1. acf-qtranslate.php +1 -1
  2. readme.txt +7 -3
  3. src/acf_4/acf.php +36 -27
  4. src/acf_5/acf.php +52 -34
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.4
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.5
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.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
@@ -34,7 +34,7 @@ https://github.com/funkjedi/acf-qtranslate/issues/
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
@@ -59,6 +59,10 @@ The plugin is based on code samples posted to the ACF support forums by taeo bac
59
60
== Changelog ==
61
62
= 1.7.4 =
63
* Bug Fix: Only load admin javascript when there are visible ACF fields
64
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.5
7
+ Stable tag: 1.7.5
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
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
59
60
== Changelog ==
61
62
+ = 1.7.5 =
63
+ * Core: Updates to README file
64
+ * Bug Fix: Updated to visible ACF fields detection
65
+
66
= 1.7.4 =
67
* Bug Fix: Only load admin javascript when there are visible ACF fields
68
src/acf_4/acf.php CHANGED
@@ -46,7 +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'));
52
}
@@ -68,11 +68,43 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
68
* @return array
69
*/
70
public function get_visible_acf_fields() {
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);
@@ -100,30 +132,7 @@ class acf_qtranslate_acf_4 implements acf_qtranslate_acf_interface {
100
$filter['post_type'] = 'attachment';
101
}
102
103
- if (count($filter) === 0) {
104
- return $visible_fields;
105
- }
106
-
107
- $supported_field_types = array(
108
- 'email',
109
- 'text',
110
- 'textarea',
111
- );
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']);
118
- foreach ($fields as $field) {
119
- if (in_array($field['type'], $supported_field_types)) {
120
- $visible_fields[] = array('id' => $field['id']);
121
- }
122
- }
123
- }
124
- }
125
-
126
- return $visible_fields;
127
}
128
129
/**
46
* Load javascript and stylesheets on admin pages.
47
*/
48
public function admin_enqueue_scripts() {
49
+ if ($this->get_acf_field_group_filters()) {
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
}
68
* @return array
69
*/
70
public function get_visible_acf_fields() {
71
+ $visible_fields = array();
72
+
73
+ // build field group filters required for current screen
74
+ $filter = $this->get_acf_field_group_filters();
75
+ if (count($filter) === 0) {
76
+ return $visible_fields;
77
+ }
78
+
79
+ $supported_field_types = array(
80
+ 'email',
81
+ 'text',
82
+ 'textarea',
83
+ );
84
+
85
+ $visible_field_groups = apply_filters('acf/location/match_field_groups', array(), $filter);
86
+
87
+ foreach (apply_filters('acf/get_field_groups', array()) as $field_group) {
88
+ if (in_array($field_group['id'], $visible_field_groups)) {
89
+ $fields = apply_filters('acf/field_group/get_fields', array(), $field_group['id']);
90
+ foreach ($fields as $field) {
91
+ if (in_array($field['type'], $supported_field_types)) {
92
+ $visible_fields[] = array('id' => $field['id']);
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ return $visible_fields;
99
+ }
100
+
101
+ /**
102
+ * Get field group filters based on active screen.
103
+ */
104
+ public function get_acf_field_group_filters() {
105
global $post, $pagenow, $typenow, $plugin_page;
106
107
$filter = array();
108
if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
109
if ($typenow !== 'acf') {
110
$filter['post_id'] = apply_filters('acf/get_post_id', false);
132
$filter['post_type'] = 'attachment';
133
}
134
135
+ return $filter;
136
}
137
138
/**
src/acf_5/acf.php CHANGED
@@ -44,7 +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'));
50
wp_enqueue_script('acf_qtranslate_main', plugins_url('/assets/acf_5/main.js', ACF_QTRANSLATE_PLUGIN), array('acf-input'));
@@ -66,12 +66,58 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
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;
@@ -102,38 +148,10 @@ class acf_qtranslate_acf_5 implements acf_qtranslate_acf_interface {
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(
122
- 'email',
123
- 'text',
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) {
130
- if (in_array($field['type'], $supported_field_types)) {
131
- $visible_fields[] = array('id' => 'acf-' . $field['key']);
132
- }
133
- }
134
- }
135
-
136
- return $visible_fields;
137
}
138
139
}
44
* Load javascript and stylesheets on admin pages.
45
*/
46
public function admin_enqueue_scripts() {
47
+ if ($this->get_acf_field_group_filters()) {
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'));
66
* Get the visible ACF fields.
67
* @return array
68
*/
69
+ public function get_visible_acf_fields($widget_id = null) {
70
+ global $wp_registered_widgets;
71
72
$visible_fields = array();
73
74
+ // build field group filters required for current screen
75
+ $filter = $this->get_acf_field_group_filters();
76
+ if (count($filter) === 0) {
77
+ return $visible_fields;
78
+ }
79
+
80
+ // widgets need some special handling since they
81
+ // require multiple acf_get_field_group_visibility()
82
+ // calls in order to return all the visible fields
83
+ if (acf_is_screen('widgets') || acf_is_screen('customize')) {
84
+ if ($widget_id) {
85
+ $filter['widget'] = _get_widget_id_base($widget_id);
86
+ }
87
+ else {
88
+ // process each widget form individually for any visible fields
89
+ foreach ($wp_registered_widgets as $widget) {
90
+ $visible_fields += $this->get_visible_acf_fields($widget['id']);
91
+ }
92
+ return $visible_fields;
93
+ }
94
+ }
95
+
96
+ $supported_field_types = array(
97
+ 'email',
98
+ 'text',
99
+ 'textarea',
100
+ );
101
+
102
+ foreach (acf_get_field_groups($filter) as $field_group) {
103
+ $fields = acf_get_fields($field_group);
104
+ foreach ($fields as $field) {
105
+ if (in_array($field['type'], $supported_field_types)) {
106
+ $visible_fields[] = array('id' => 'acf-' . $field['key']);
107
+ }
108
+ }
109
+ }
110
+
111
+ return $visible_fields;
112
+ }
113
+
114
+ /**
115
+ * Get field group filters based on active screen.
116
+ */
117
+ public function get_acf_field_group_filters() {
118
+ global $post, $pagenow, $typenow, $plugin_page;
119
+
120
+ $filter = array();
121
if ($pagenow === 'post.php' || $pagenow === 'post-new.php') {
122
if ($typenow !== 'acf') {
123
$filter['post_id'] = $post->ID;
148
$filter['attachment'] = 'All';
149
}
150
elseif (acf_is_screen('widgets') || acf_is_screen('customize')) {
151
+ $filter['widget'] = 'all';
152
}
153
154
+ return $filter;
155
}
156
157
}