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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / acf-form-functions.php
advanced-custom-fields / includes Last commit date
admin 1 month ago ajax 3 months ago api 2 weeks ago fields 4 weeks ago forms 4 weeks ago legacy 5 months ago locations 1 month ago post-types 5 months ago rest-api 4 weeks ago walkers 5 months ago acf-bidirectional-functions.php 5 months ago acf-field-functions.php 5 months ago acf-field-group-functions.php 5 months ago acf-form-functions.php 5 months ago acf-helper-functions.php 5 months ago acf-hook-functions.php 5 months ago acf-input-functions.php 5 months ago acf-internal-post-type-functions.php 5 months ago acf-meta-functions.php 2 months ago acf-post-functions.php 5 months ago acf-post-type-functions.php 5 months ago acf-taxonomy-functions.php 5 months ago acf-user-functions.php 5 months ago acf-utility-functions.php 5 months ago acf-value-functions.php 5 months ago acf-wp-functions.php 5 months ago assets.php 5 months ago class-acf-data.php 5 months ago class-acf-internal-post-type.php 5 months ago compatibility.php 5 months ago deprecated.php 5 months ago fields.php 5 months ago index.php 2 years ago l10n.php 5 months ago local-fields.php 5 months ago local-json.php 3 months ago local-meta.php 5 months ago locations.php 5 months ago loop.php 5 months ago media.php 6 days ago rest-api.php 5 months ago revisions.php 3 months ago third-party.php 5 months ago upgrades.php 2 months ago validation.php 5 months ago wpml.php 5 months ago
acf-form-functions.php
181 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 // Register store for form data.
13 acf_register_store( 'form' );
14
15 /**
16 * acf_set_form_data
17 *
18 * Sets data about the current form.
19 *
20 * @date 6/10/13
21 * @since 5.0.0
22 *
23 * @param string $name The store name.
24 * @param array $data Array of data to start the store with.
25 * @return ACF_Data
26 */
27 function acf_set_form_data( $name = '', $data = false ) {
28 return acf_get_store( 'form' )->set( $name, $data );
29 }
30
31 /**
32 * acf_get_form_data
33 *
34 * Gets data about the current form.
35 *
36 * @date 6/10/13
37 * @since 5.0.0
38 *
39 * @param string $name The store name.
40 * @return mixed
41 */
42 function acf_get_form_data( $name = '' ) {
43 return acf_get_store( 'form' )->get( $name );
44 }
45
46 /**
47 * acf_form_data
48 *
49 * Called within a form to set important information and render hidden inputs.
50 *
51 * @date 15/10/13
52 * @since 5.0.0
53 *
54 * @param void
55 * @return void
56 */
57 function acf_form_data( $data = array() ) {
58
59 // Apply defaults.
60 $data = wp_parse_args(
61 $data,
62 array(
63
64 /** @type string The current screen (post, user, taxonomy, etc). */
65 'screen' => 'post',
66
67 /** @type int|string The ID of current post being edited. */
68 'post_id' => 0,
69
70 /** @type bool Enables AJAX validation. */
71 'validation' => true,
72 )
73 );
74
75 // Create nonce using screen.
76 $data['nonce'] = wp_create_nonce( $data['screen'] );
77
78 // Append "changed" input used within "_wp_post_revision_fields" action.
79 $data['changed'] = 0;
80
81 // Set data.
82 acf_set_form_data( $data );
83
84 // Render HTML.
85 ?>
86 <div id="acf-form-data" class="acf-hidden">
87 <?php
88
89 // Create hidden inputs from $data
90 foreach ( $data as $name => $value ) {
91 acf_hidden_input(
92 array(
93 'id' => '_acf_' . $name,
94 'name' => '_acf_' . $name,
95 'value' => $value,
96 )
97 );
98 }
99
100 /**
101 * Fires within the #acf-form-data element to add extra HTML.
102 *
103 * @date 15/10/13
104 * @since 5.0.0
105 *
106 * @param array $data The form data.
107 */
108 do_action( 'acf/form_data', $data );
109 do_action( 'acf/input/form_data', $data );
110
111 ?>
112 </div>
113 <?php
114 }
115
116
117 /**
118 * acf_save_post
119 *
120 * Saves the $_POST data.
121 *
122 * @date 15/10/13
123 * @since 5.0.0
124 *
125 * @param integer|string $post_id The post id.
126 * @param array $values An array of values to override $_POST.
127 * @return boolean True if save was successful.
128 */
129 function acf_save_post( $post_id = 0, $values = null ) {
130
131 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified elsewhere.
132 // Override $_POST data with $values.
133 if ( $values !== null ) {
134 $_POST['acf'] = $values;
135 }
136
137 // Bail early if no data to save.
138 if ( empty( $_POST['acf'] ) ) {
139 return false;
140 }
141
142 // Set form data (useful in various filters/actions).
143 acf_set_form_data( 'post_id', $post_id );
144
145 // Filter $_POST data for users without the 'unfiltered_html' capability.
146 if ( ! acf_allow_unfiltered_html() ) {
147 $_POST['acf'] = wp_kses_post_deep( $_POST['acf'] );
148 }
149 // phpcs:enable WordPress.Security.NonceVerification.Missing
150
151 // Do generic action.
152 do_action( 'acf/save_post', $post_id );
153
154 // Return true.
155 return true;
156 }
157
158 /**
159 * _acf_do_save_post
160 *
161 * Private function hooked into 'acf/save_post' to actually save the $_POST data.
162 * This allows developers to hook in before and after ACF has actually saved the data.
163 *
164 * @date 11/1/19
165 * @since 5.7.10
166 *
167 * @param integer|string $post_id The post id.
168 * @return void
169 */
170 function _acf_do_save_post( $post_id = 0 ) {
171
172 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified elsewhere.
173 if ( ! empty( $_POST['acf'] ) ) {
174 acf_update_values( $_POST['acf'], $post_id ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized by WP when saved.
175 }
176 // phpcs:enable WordPress.Security.NonceVerification.Missing
177 }
178
179 // Run during generic action.
180 add_action( 'acf/save_post', '_acf_do_save_post' );
181