PluginProbe
Advanced Forms for ACF / trunk
Advanced Forms for ACF vtrunk
1.9.0 1.9.1 1.9.2.1 1.9.3 1.9.3.1 1.9.3.2 1.9.3.3 1.9.3.4 1.9.3.5 1.9.3.6 1.9.3.7 1.9.3.8 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.3.1 1.0.3.2 1.0.3.3 1.0.4 1.1.0 1.1.1 1.2.0 1.3.0 All 51 releases
advanced-forms / acf / acf-additions.php

acf-additions.php in Advanced Forms for ACF trunk, at acf/acf-additions.php

135 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 /**
5 * This class wraps all integrations with ACF such as custom location rules and fields
6 *
7 * @since 1.0.0
8 *
9 */
10 class AF_ACF_Additions {
11
12 function __construct() {
13
14 add_action('acf/render_field_settings', array( $this, 'field_settings'), 100 );
15 add_action('acf/prepare_field', array( $this, 'hide_field_from_admin'), 100 );
16
17 add_filter( 'acf/location/rule_types', array( $this, 'add_form_location_type' ), 10, 1 );
18 add_filter( 'acf/location/rule_values/af_form', array( $this, 'form_location_rule_values' ), 10, 1 );
19 add_filter( 'acf/location/rule_match/af_form', array( $this, 'form_location_rule_match' ), 10, 3 );
20
21 }
22
23
24 /**
25 * Add extra global field settings
26 *
27 * @since 1.3.1
28 *
29 */
30 function field_settings( $field ) {
31
32 acf_render_field_setting( $field, array(
33 'label' => __('Hide from admin?'),
34 'instructions' => 'Only show this field in forms',
35 'name' => 'hide_admin',
36 'type' => 'true_false',
37 'ui' => 1,
38 ), true);
39
40 }
41
42
43 /**
44 * Hide fields with the "Hide from admin?" setting
45 *
46 * @since 1.3.1
47 *
48 */
49 function hide_field_from_admin( $field ) {
50
51 if ( empty( $field['hide_admin'] ) ) {
52 return $field;
53 }
54
55
56 if ( $field['hide_admin'] && is_admin() ) {
57 return false;
58 }
59
60
61 return $field;
62
63 }
64
65
66 /**
67 * Adds a new location rule type "Form" to ACF
68 *
69 * @since 1.0.0
70 *
71 */
72 function add_form_location_type( $choices ) {
73
74 $choices['Advanced Forms']['af_form'] = 'Form';
75
76 return $choices;
77
78 }
79
80
81 /**
82 * Populates the choices for the location rule type "Form"
83 *
84 * @since 1.0.0
85 *
86 */
87 function form_location_rule_values( $choices ) {
88
89 $forms = af_get_forms();
90
91 foreach ( $forms as $form ) {
92 $choices[ $form['key'] ] = $form['title'];
93 }
94
95 return $choices;
96
97 }
98
99
100 function form_location_rule_match( $match, $rule, $options ) {
101
102
103 // Match with form object
104 if ( 'af_form' == $rule['param'] && isset( $options['af_form'] ) ) {
105
106 if( isset( $rule['value'] ) && $rule['value'] == $options['af_form'] ) {
107
108 $match = true;
109
110 }
111
112 }
113
114
115 // Match with entry
116 if ( isset( $options['post_type'] ) && 'af_entry' == $options['post_type'] ) {
117
118 $entry_form = get_post_meta( $options['post_id'], 'entry_form', true );
119
120 if ( $entry_form && $entry_form == $rule['value'] ) {
121
122 $match = true;
123
124 }
125
126 }
127
128
129 return $match;
130
131 }
132
133 }
134
135 return new AF_ACF_Additions();