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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 / forms / form-gutenberg.php
advanced-custom-fields / includes / forms Last commit date
form-attachment.php 5 months ago form-comment.php 4 weeks ago form-customizer.php 5 months ago form-front.php 2 months ago form-gutenberg.php 5 months ago form-nav-menu.php 5 months ago form-post.php 3 months ago form-taxonomy.php 2 months ago form-user.php 4 weeks ago form-widget.php 5 months ago index.php 2 years ago
form-gutenberg.php
198 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 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 if ( ! class_exists( 'ACF_Form_Gutenberg' ) ) :
17
18 class ACF_Form_Gutenberg {
19
20 /**
21 * __construct
22 *
23 * Setup for class functionality.
24 *
25 * @date 13/12/18
26 * @since 5.8.0
27 *
28 * @param void
29 * @return void
30 */
31 function __construct() {
32
33 // Add actions.
34 add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
35
36 // Ignore validation during meta-box-loader AJAX request.
37 add_action( 'acf/validate_save_post', array( $this, 'acf_validate_save_post' ), 999 );
38 }
39
40 /**
41 * enqueue_block_editor_assets
42 *
43 * Allows a safe way to customize Guten-only functionality.
44 *
45 * @date 14/12/18
46 * @since 5.8.0
47 *
48 * @param void
49 * @return void
50 */
51 function enqueue_block_editor_assets() {
52
53 // Remove edit_form_after_title.
54 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 20, 0 );
55
56 // Call edit_form_after_title manually.
57 add_action( 'block_editor_meta_box_hidden_fields', array( $this, 'block_editor_meta_box_hidden_fields' ) );
58
59 // Customize editor metaboxes.
60 add_filter( 'filter_block_editor_meta_boxes', array( $this, 'filter_block_editor_meta_boxes' ) );
61
62 // Trigger ACF enqueue scripts as the site editor doesn't trigger this from form-post.php
63 acf_enqueue_scripts(
64 array(
65 'uploader' => true,
66 )
67 );
68 }
69
70 /**
71 * add_meta_boxes
72 *
73 * Modify screen for Gutenberg.
74 *
75 * @date 13/12/18
76 * @since 5.8.0
77 *
78 * @param void
79 * @return void
80 */
81 function add_meta_boxes() {
82
83 // Remove 'edit_form_after_title' action.
84 remove_action( 'edit_form_after_title', array( acf_get_instance( 'ACF_Form_Post' ), 'edit_form_after_title' ) );
85 }
86
87 /**
88 * block_editor_meta_box_hidden_fields
89 *
90 * Modify screen for Gutenberg.
91 *
92 * @date 13/12/18
93 * @since 5.8.0
94 *
95 * @param void
96 * @return void
97 */
98 function block_editor_meta_box_hidden_fields() {
99
100 // Manually call 'edit_form_after_title' function.
101 acf_get_instance( 'ACF_Form_Post' )->edit_form_after_title();
102 }
103
104 /**
105 * filter_block_editor_meta_boxes
106 *
107 * description
108 *
109 * @date 5/4/19
110 * @since 5.7.14
111 *
112 * @param type $var Description. Default.
113 * @return type Description.
114 */
115 function filter_block_editor_meta_boxes( $wp_meta_boxes ) {
116
117 // Globals
118 global $current_screen;
119
120 // Move 'acf_after_title' metaboxes into 'normal' location.
121 if ( isset( $wp_meta_boxes[ $current_screen->id ]['acf_after_title'] ) ) {
122
123 // Extract locations.
124 $locations = $wp_meta_boxes[ $current_screen->id ];
125
126 // Ensure normal location exists.
127 if ( ! isset( $locations['normal'] ) ) {
128 $locations['normal'] = array();
129 }
130 if ( ! isset( $locations['normal']['high'] ) ) {
131 $locations['normal']['high'] = array();
132 }
133
134 // Append metaboxes.
135 foreach ( $locations['acf_after_title'] as $priority => $meta_boxes ) {
136 $locations['normal']['high'] = array_merge( $meta_boxes, $locations['normal']['high'] );
137 }
138
139 // Update original data.
140 $wp_meta_boxes[ $current_screen->id ] = $locations;
141 unset( $wp_meta_boxes[ $current_screen->id ]['acf_after_title'] );
142
143 // Avoid conflicts with saved metabox order.
144 add_filter( 'get_user_option_meta-box-order_' . $current_screen->id, array( $this, 'modify_user_option_meta_box_order' ) );
145 }
146
147 // Return
148 return $wp_meta_boxes;
149 }
150
151 /**
152 * modify_user_option_meta_box_order
153 *
154 * Filters the `meta-box-order_{$post_type}` value by prepending "acf_after_title" data to "normal".
155 * Fixes a bug where metaboxes with position "acf_after_title" do not appear in the block editor.
156 *
157 * @date 11/7/19
158 * @since 5.8.2
159 *
160 * @param array $stored_meta_box_order User's existing meta box order.
161 * @return array Modified array with meta boxes moved around.
162 */
163 function modify_user_option_meta_box_order( $locations ) {
164 if ( ! empty( $locations['acf_after_title'] ) ) {
165 if ( ! empty( $locations['normal'] ) ) {
166 $locations['normal'] = $locations['acf_after_title'] . ',' . $locations['normal'];
167 } else {
168 $locations['normal'] = $locations['acf_after_title'];
169 }
170 unset( $locations['acf_after_title'] );
171 }
172 return $locations;
173 }
174
175 /**
176 * acf_validate_save_post
177 *
178 * Ignore errors during the Gutenberg "save metaboxes" AJAX request.
179 * Allows data to save and prevent UX issues.
180 *
181 * @date 16/12/18
182 * @since 5.8.0
183 *
184 * @param void
185 * @return void
186 */
187 function acf_validate_save_post() {
188
189 // Check if current request came from Gutenberg.
190 if ( isset( $_GET['meta-box-loader'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Verified elsewhere.
191 acf_reset_validation_errors();
192 }
193 }
194 }
195
196 acf_new_instance( 'ACF_Form_Gutenberg' );
197 endif;
198