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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-attachment.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-attachment.php
212 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 ( ! class_exists( 'acf_form_attachment' ) ) :
13
14 class acf_form_attachment {
15
16 /**
17 * This function will setup the class functionality
18 *
19 * @type function
20 * @date 5/03/2014
21 * @since 5.0.0
22 *
23 * @param n/a
24 * @return n/a
25 */
26 function __construct() {
27
28 // actions
29 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
30
31 // render
32 add_filter( 'attachment_fields_to_edit', array( $this, 'edit_attachment' ), 10, 2 );
33
34 // save
35 add_filter( 'attachment_fields_to_save', array( $this, 'save_attachment' ), 10, 2 );
36 }
37
38
39 /**
40 * This action is run after post query but before any admin script / head actions.
41 * It is a good place to register all actions.
42 *
43 * @type action (admin_enqueue_scripts)
44 * @date 26/01/13
45 * @since 3.6.0
46 *
47 * @param N/A
48 * @return N/A
49 */
50 function admin_enqueue_scripts() {
51
52 // bail early if not valid screen
53 if ( ! acf_is_screen( array( 'attachment', 'upload' ) ) ) {
54 return;
55 }
56
57 // load acf scripts
58 acf_enqueue_scripts(
59 array(
60 'uploader' => true,
61 )
62 );
63
64 // actions
65 if ( acf_is_screen( 'upload' ) ) {
66 add_action( 'admin_footer', array( $this, 'admin_footer' ), 0 );
67 }
68 }
69
70
71 /**
72 * This function will add acf_form_data to the WP 4.0 attachment grid
73 *
74 * @type action (admin_footer)
75 * @date 11/09/2014
76 * @since 5.0.0
77 *
78 * @param n/a
79 * @return n/a
80 */
81 function admin_footer() {
82
83 // render post data
84 acf_form_data(
85 array(
86 'screen' => 'attachment',
87 'post_id' => 0,
88 )
89 );
90
91 ?>
92 <script type="text/javascript">
93
94 // WP saves attachment on any input change, so unload is not needed
95 acf.unload.active = 0;
96
97 </script>
98 <?php
99 }
100
101
102 /**
103 * description
104 *
105 * @type function
106 * @date 8/10/13
107 * @since 5.0.0
108 *
109 * @param $post_id (int)
110 * @return $post_id (int)
111 */
112 function edit_attachment( $form_fields, $post ) {
113
114 // vars
115 $is_page = acf_is_screen( 'attachment' );
116 $post_id = $post->ID;
117 $el = 'tr';
118
119 // get field groups
120 $field_groups = acf_get_field_groups(
121 array(
122 'attachment_id' => $post_id,
123 'attachment' => $post_id, // Leave for backwards compatibility
124 )
125 );
126
127 // render
128 if ( ! empty( $field_groups ) ) {
129
130 // get acf_form_data
131 ob_start();
132
133 acf_form_data(
134 array(
135 'screen' => 'attachment',
136 'post_id' => $post_id,
137 )
138 );
139
140 // open
141 echo '</td></tr>';
142
143 // loop
144 foreach ( $field_groups as $field_group ) {
145
146 // load fields
147 $fields = acf_get_fields( $field_group );
148
149 // override instruction placement for modal
150 if ( ! $is_page ) {
151 $field_group['instruction_placement'] = 'field';
152 }
153
154 // render
155 acf_render_fields( $fields, $post_id, $el, $field_group['instruction_placement'] );
156 }
157
158 // close
159 echo '<tr class="compat-field-acf-blank"><td>';
160
161 $html = ob_get_contents();
162
163 ob_end_clean();
164
165 $form_fields['acf-form-data'] = array(
166 'label' => '',
167 'input' => 'html',
168 'html' => $html,
169 );
170 }
171
172 // return
173 return $form_fields;
174 }
175
176
177 /**
178 * description
179 *
180 * @type function
181 * @date 8/10/13
182 * @since 5.0.0
183 *
184 * @param $post_id (int)
185 * @return $post_id (int)
186 */
187 function save_attachment( $post, $attachment ) {
188
189 // bail early if not valid nonce
190 if ( ! acf_verify_nonce( 'attachment' ) ) {
191 return $post;
192 }
193
194 // bypass validation for ajax
195 if ( acf_is_ajax( 'save-attachment-compat' ) ) {
196 acf_save_post( $post['ID'] );
197
198 // validate and save
199 } elseif ( acf_validate_save_post( true ) ) {
200 acf_save_post( $post['ID'] );
201 }
202
203 // return
204 return $post;
205 }
206 }
207
208 new acf_form_attachment();
209 endif;
210
211 ?>
212