Skip to content

Commit 7a1f22a

Browse files
author
Miika Arponen
committed
Merged master
2 parents bb25bd7 + 5c4e48a commit 7a1f22a

File tree

8 files changed

+222
-114
lines changed

8 files changed

+222
-114
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1616
* `Geniem\ACF\Renderer\PHP`: Uses PHP files as templates.
1717
* `Geniem\ACF\Renderer\Dust`: Uses Dust.js template files.
1818

19+
## [1.20.0] - 2019-10-10
20+
21+
### Changed
22+
- Removed the dependency for the external plugin for the Gravity Forms field. *NOTE!* If you have used the field previously with the return format set as "object", this will change the behaviour.
23+
24+
## [1.19.0] - 2019-09-13
25+
26+
### Added
27+
- The ability to disable all or some of the options in the Checkbox field.
28+
29+
### Fixed
30+
- `acf/render_field` function wrapped to work only with the specific field the method is used on.
31+
32+
## [1.18.0] - 2019-08-05
33+
34+
### Added
35+
- Support for `acf/fields/taxonomy/result` filter.
36+
37+
## [1.17.0] - 2019-07-08
38+
39+
### Added
40+
- Ability to define the priority for field filter functions as a second parameter.
41+
42+
### Changed
43+
- Groupable export function's filter registration to resemble the one of normal fields.
44+
1945
## [1.16.0] - 2019-04-17
2046

2147
### Added

docs/classes.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
| public | <strong>add_wrapper_class(</strong><em>\string</em> <strong>$class</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Add a single wrapper class to be added for the field.</em> |
137137
| public | <strong>clone(</strong><em>string</em> <strong>$key</strong>, <em>string</em> <strong>$name=null</strong>)</strong> : <em>\Geniem\ACF\Geniem\ACF\Field</em><br /><em>Clone method Forces the developer to give new key to cloned field.</em> |
138138
| public | <strong>export(</strong><em>bool/boolean</em> <strong>$register=false</strong>)</strong> : <em>array</em><br /><em>Export field in ACF's native format.</em> |
139-
| public | <strong>format_value(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value formatting function for the field</em> |
139+
| public | <strong>format_value(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=11</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value formatting function for the field</em> |
140140
| public | <strong>get_conditional_logic()</strong> : <em>[\Geniem\ACF\ConditionalLogicGroup](#class-geniemacfconditionallogicgroup)</em><br /><em>Get the conditional logic group that have been added to the group.</em> |
141141
| public | <strong>get_default_value()</strong> : <em>mixed</em><br /><em>Get the default value of the field.</em> |
142142
| public | <strong>get_instructions()</strong> : <em>string</em><br /><em>Get the instruction text of the field.</em> |
@@ -150,9 +150,9 @@
150150
| public | <strong>get_wrapper_id()</strong> : <em>string</em><br /><em>Get the id that has been added for the field.</em> |
151151
| public | <strong>get_wrapper_width()</strong> : <em>int</em><br /><em>Get the wrapper width.</em> |
152152
| public | <strong>hide_label()</strong> : <em>\Geniem\ACF\self</em><br /><em>Hide the field label in the admin side</em> |
153-
| public | <strong>load_field(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a field loading function for the field</em> |
154-
| public | <strong>load_value(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value loading function for the field</em> |
155-
| public | <strong>prepare_field(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a field preparing function for the field</em> |
153+
| public | <strong>load_field(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=10</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a field loading function for the field</em> |
154+
| public | <strong>load_value(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=10</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value loading function for the field</em> |
155+
| public | <strong>prepare_field(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=10</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a field preparing function for the field</em> |
156156
| public | <strong>redipress_add_queryable(</strong><em>\string</em> <strong>$field_name=null</strong>, <em>\float</em> <strong>$weight=1</strong>, <em>\string</em> <strong>$method=`'use_last'`</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Add this field's value as a queryable value to RediSearch index.</em> |
157157
| public static | <strong>redipress_disable_indexing()</strong> : <em>void</em><br /><em>Disable indexing features for RediPress plugin.</em> |
158158
| public static | <strong>redipress_enable_indexing()</strong> : <em>void</em><br /><em>Enable indexing features for RediPress plugin.</em> |
@@ -163,7 +163,7 @@
163163
| public | <strong>redipress_include_search(</strong><em>\callable</em> <strong>$callback=null</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Include this field's value in the RediPress search index.</em> |
164164
| public | <strong>redipress_remove_queryable()</strong> : <em>\Geniem\ACF\self</em><br /><em>Remove this field from being queryable in RediSearch index.</em> |
165165
| public | <strong>remove_wrapper_class(</strong><em>\string</em> <strong>$class</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Remove a single wrapper class from the field.</em> |
166-
| public | <strong>render_field(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a field rendering function for the field</em> |
166+
| public | <strong>render_field(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=10</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a field rendering function for the field</em> |
167167
| public | <strong>set_default_value(</strong><em>mixed</em> <strong>$value</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Set the default value for the field.</em> |
168168
| public | <strong>set_instructions(</strong><em>\string</em> <strong>$instructions</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Set instruction text for the field.</em> |
169169
| public | <strong>set_key(</strong><em>\string</em> <strong>$key</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Set key for the field.</em> |
@@ -176,8 +176,8 @@
176176
| public | <strong>set_wrapper_width(</strong><em>integer/\int</em> <strong>$width</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Set the wrapper width in percents.</em> |
177177
| public | <strong>show_label()</strong> : <em>\Geniem\ACF\self</em><br /><em>Show the field label in the admin side</em> |
178178
| public | <strong>unset_filter(</strong><em>string</em> <strong>$filter</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Unset a previously set filter.</em> |
179-
| public | <strong>update_value(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value updating function for the field</em> |
180-
| public | <strong>validate_value(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value validation function for the field</em> |
179+
| public | <strong>update_value(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=10</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value updating function for the field</em> |
180+
| public | <strong>validate_value(</strong><em>\callable</em> <strong>$function</strong>, <em>\int</em> <strong>$priority=10</strong>)</strong> : <em>\Geniem\ACF\self</em><br /><em>Register a value validation function for the field</em> |
181181
| protected | <strong>__clone()</strong> : <em>void</em><br /><em>Prevent raw cloning.</em> |
182182
| protected | <strong>check_for_unique_key()</strong> : <em>void</em><br /><em>Checks if the field's key is unique within the project scope. Throws a notice if not.</em> |
183183
| protected static | <strong>redipress_additional_field(</strong><em>mixed</em> <strong>$value</strong>, <em>int</em> <strong>$post_id</strong>, <em>array</em> <strong>$field</strong>)</strong> : <em>mixed</em><br /><em>A helper function to use to enable indexing the post outside save action.</em> |
@@ -288,6 +288,7 @@
288288
| public | <strong>disallow_null()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Disallow null value</em> |
289289
| public | <strong>disallow_save_terms()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Disable saving terms to the post object</em> |
290290
| public | <strong>filter_arguments(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Register a arguments filtering function for the field</em> |
291+
| public | <strong>filter_results(</strong><em>\callable</em> <strong>$function</strong>)</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Register a function to filter the result texts for the field in admin</em> |
291292
| public | <strong>get_add_term()</strong> : <em>integer</em><br /><em>Get whether terms can be added</em> |
292293
| public | <strong>get_allow_null()</strong> : <em>integer</em><br /><em>Get allow null status</em> |
293294
| public | <strong>get_field_type()</strong> : <em>string</em><br /><em>Get displayed field type</em> |
@@ -989,16 +990,21 @@
989990
| public | <strong>allow_custom()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Allow custom values</em> |
990991
| public | <strong>allow_save_custom()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Allow saving custom values to default values</em> |
991992
| public | <strong>allow_toggle()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Allow toggle all checkbox</em> |
993+
| public | <strong>disable()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Disable all checkboxes</em> |
992994
| public | <strong>disallow_custom()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Disallow custom values</em> |
993995
| public | <strong>disallow_save_custom()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Disallow saving custom values to default values</em> |
994996
| public | <strong>disallow_toggle()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Disallow toggle all checkbox</em> |
997+
| public | <strong>enable()</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Set all checkboxes to be enabled</em> |
998+
| public | <strong>export(</strong><em>bool/boolean</em> <strong>$register=false</strong>)</strong> : <em>array</em><br /><em>Export field in ACF's native format.</em> |
995999
| public | <strong>get_choices()</strong> : <em>array</em><br /><em>Get all choices.</em> |
9961000
| public | <strong>get_custom()</strong> : <em>integer</em><br /><em>Get allow custom values status</em> |
1001+
| public | <strong>get_disabled()</strong> : <em>string/array</em><br /><em>Get the disabled checkboxes</em> |
9971002
| public | <strong>get_layout()</strong> : <em>string</em><br /><em>Get the current display style of the checkbox.</em> |
9981003
| public | <strong>get_save_custom()</strong> : <em>integer</em><br /><em>Get save custom status</em> |
9991004
| public | <strong>get_toggle()</strong> : <em>integer</em><br /><em>Get toggle all checkbox</em> |
10001005
| public | <strong>remove_choice(</strong><em>\string</em> <strong>$choice</strong>)</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Remove a choice.</em> |
10011006
| public | <strong>set_choices(</strong><em>array</em> <strong>$choices</strong>)</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Set choices for the checkbox</em> |
1007+
| public | <strong>set_disabled(</strong><em>array</em> <strong>$keys</strong>)</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Set the disabled checkboxes as array</em> |
10021008
| public | <strong>set_layout(</strong><em>\string</em> <strong>$layout=`'vertical'`</strong>)</strong> : <em>[\Geniem\ACF\Field](#class-geniemacffield-abstract)\self</em><br /><em>Set whether the checkboxes are displayed vertically or horizontally.</em> |
10031009

10041010
*This class extends [\Geniem\ACF\Field](#class-geniemacffield-abstract)*

plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: ACF Codifier
44
Plugin URI: https://github.com/devgeniem/acf-codifier
55
Description: A helper class to make defining ACF field groups and fields easier in the code.
6-
Version: 1.16.0
6+
Version: 1.20.0
77
Author: Miika Arponen / Geniem Oy
88
Author URI: https://geniem.fi
99
License: GPL-3.0

src/Field.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ public function export( $register = false ) {
262262
if ( $register && ! empty( $this->filters ) ) {
263263
array_walk( $this->filters, function( $filter ) {
264264
$filter = wp_parse_args( $filter, $this->default_filter_arguments );
265+
265266
if ( $filter['no_suffix'] ) {
266267
add_filter( $filter['filter'], $filter['function'], $filter['priority'], $filter['accepted_args'] );
267268
}
@@ -827,13 +828,14 @@ public function redipress_get_queryable_status() : bool {
827828
* Register a value validation function for the field
828829
*
829830
* @param callable $function A function to register.
831+
* @param int $priority The filter priority.
830832
* @return self
831833
*/
832-
public function validate_value( callable $function ) {
834+
public function validate_value( callable $function, int $priority = 10 ) {
833835
$this->filters['validate_value'] = [
834836
'filter' => 'acf/validate_value/key=',
835837
'function' => $function,
836-
'priority' => 10,
838+
'priority' => $priority,
837839
'accepted_args' => 4,
838840
];
839841

@@ -844,13 +846,14 @@ public function validate_value( callable $function ) {
844846
* Register a value formatting function for the field
845847
*
846848
* @param callable $function A function to register.
849+
* @param int $priority The filter priority.
847850
* @return self
848851
*/
849-
public function format_value( callable $function ) {
852+
public function format_value( callable $function, int $priority = 11 ) {
850853
$this->filters['format_value'] = [
851854
'filter' => 'acf/format_value/key=',
852855
'function' => $function,
853-
'priority' => 11,
856+
'priority' => $priority,
854857
'accepted_args' => 3,
855858
];
856859

@@ -861,13 +864,14 @@ public function format_value( callable $function ) {
861864
* Register a value loading function for the field
862865
*
863866
* @param callable $function A function to register.
867+
* @param int $priority The filter priority.
864868
* @return self
865869
*/
866-
public function load_value( callable $function ) {
870+
public function load_value( callable $function, int $priority = 10 ) {
867871
$this->filters['load_value'] = [
868872
'filter' => 'acf/load_value/key=',
869873
'function' => $function,
870-
'priority' => 10,
874+
'priority' => $priority,
871875
'accepted_args' => 3,
872876
];
873877

@@ -878,13 +882,14 @@ public function load_value( callable $function ) {
878882
* Register a value updating function for the field
879883
*
880884
* @param callable $function A function to register.
885+
* @param int $priority The filter priority.
881886
* @return self
882887
*/
883-
public function update_value( callable $function ) {
888+
public function update_value( callable $function, int $priority = 10 ) {
884889
$this->filters['update_value'] = [
885890
'filter' => 'acf/update_value/key=',
886891
'function' => $function,
887-
'priority' => 10,
892+
'priority' => $priority,
888893
'accepted_args' => 3,
889894
];
890895

@@ -895,13 +900,14 @@ public function update_value( callable $function ) {
895900
* Register a field preparing function for the field
896901
*
897902
* @param callable $function A function to register.
903+
* @param int $priority The filter priority.
898904
* @return self
899905
*/
900-
public function prepare_field( callable $function ) {
906+
public function prepare_field( callable $function, int $priority = 10 ) {
901907
$this->filters['prepare_field'] = [
902908
'filter' => 'acf/prepare_field/key=',
903909
'function' => $function,
904-
'priority' => 10,
910+
'priority' => $priority,
905911
'accepted_args' => 1,
906912
];
907913

@@ -912,13 +918,14 @@ public function prepare_field( callable $function ) {
912918
* Register a field loading function for the field
913919
*
914920
* @param callable $function A function to register.
921+
* @param int $priority The filter priority.
915922
* @return self
916923
*/
917-
public function load_field( callable $function ) {
924+
public function load_field( callable $function, int $priority = 10 ) {
918925
$this->filters['load_field'] = [
919926
'filter' => 'acf/load_field/key=',
920927
'function' => $function,
921-
'priority' => 10,
928+
'priority' => $priority,
922929
'accepted_args' => 1,
923930
];
924931

@@ -929,13 +936,26 @@ public function load_field( callable $function ) {
929936
* Register a field rendering function for the field
930937
*
931938
* @param callable $function A function to register.
939+
* @param int $priority The filter priority.
932940
* @return self
933941
*/
934-
public function render_field( callable $function ) {
935-
$this->filters['render_field'] = [
936-
'filter' => 'acf/render_field',
937-
'function' => $function,
938-
'priority' => 10,
942+
public function render_field( callable $function, int $priority = 10 ) {
943+
$this->codifier_unique_id = uniqid( '', true );
944+
945+
$this->filters['render_field_' . $this->codifier_unique_id ] = [
946+
'filter' => 'acf/render_field/type=' . $this->type,
947+
'function' => function( $field ) use ( $function ) {
948+
if (
949+
! empty( $field['codifier_unique_id'] ) &&
950+
$this->codifier_unique_id === $field['codifier_unique_id']
951+
) {
952+
return $function( $field );
953+
}
954+
else {
955+
return $field;
956+
}
957+
},
958+
'priority' => $priority,
939959
'accepted_args' => 1,
940960
'no_suffix' => true,
941961
];

0 commit comments

Comments
 (0)