6
6
7
7
if ( ! class_exists ( 'ACF_Form_Post ' ) ) :
8
8
9
+ /**
10
+ * Class ACF_Form_Post
11
+ *
12
+ * Handles the functionality for adding custom fields to post edit screens.
13
+ *
14
+ * @package ACF
15
+ * @since ACF 5.0.0
16
+ */
9
17
class ACF_Form_Post {
10
18
11
- /** @var string The first field groups style CSS. */
12
- var $ style = '' ;
19
+ /**
20
+ * Style.
21
+ *
22
+ * @var string The first field groups style CSS.
23
+ */
24
+ public $ style = '' ;
13
25
14
26
/**
15
27
* __construct
@@ -21,20 +33,20 @@ class ACF_Form_Post {
21
33
*
22
34
* @return void
23
35
*/
24
- function __construct () {
36
+ public function __construct () {
25
37
26
38
// initialize on post edit screens
27
39
add_action ( 'load-post.php ' , array ( $ this , 'initialize ' ) );
28
40
add_action ( 'load-post-new.php ' , array ( $ this , 'initialize ' ) );
29
41
30
42
// save
31
- add_filter ( 'wp_insert_post_empty_content ' , array ( $ this , 'wp_insert_post_empty_content ' ), 10 , 2 );
43
+ add_filter ( 'wp_insert_post_empty_content ' , array ( $ this , 'wp_insert_post_empty_content ' ), 10 , 1 );
32
44
add_action ( 'save_post ' , array ( $ this , 'save_post ' ), 10 , 2 );
33
45
}
34
46
35
47
36
48
/**
37
- * initialize
49
+ * Initialize.
38
50
*
39
51
* Sets up Form functionality.
40
52
*
@@ -43,7 +55,7 @@ function __construct() {
43
55
*
44
56
* @return void
45
57
*/
46
- function initialize () {
58
+ public function initialize () {
47
59
48
60
// globals
49
61
global $ typenow ;
@@ -72,7 +84,6 @@ function initialize() {
72
84
}
73
85
74
86
/**
75
- * add_meta_boxes
76
87
*
77
88
* Adds ACF metaboxes for the given $post_type and $post.
78
89
*
@@ -83,7 +94,7 @@ function initialize() {
83
94
* @param WP_Post $post The post being edited.
84
95
* @return void
85
96
*/
86
- function add_meta_boxes ( $ post_type , $ post ) {
97
+ public function add_meta_boxes ( $ post_type , $ post ) {
87
98
88
99
// Storage for localized postboxes.
89
100
$ postboxes = array ();
@@ -107,7 +118,7 @@ function add_meta_boxes( $post_type, $post ) {
107
118
$ priority = 'high ' ; // high, core, default, low
108
119
109
120
// Reduce priority for sidebar metaboxes for best position.
110
- if ( $ context == ' side ' ) {
121
+ if ( ' side ' === $ context ) {
111
122
$ priority = 'core ' ;
112
123
}
113
124
@@ -176,7 +187,7 @@ function add_meta_boxes( $post_type, $post ) {
176
187
public function edit_form_after_title () {
177
188
178
189
// globals
179
- global $ post, $ wp_meta_boxes ;
190
+ global $ post ;
180
191
181
192
// render post data
182
193
acf_form_data (
@@ -199,18 +210,16 @@ public function edit_form_after_title() {
199
210
}
200
211
201
212
/**
202
- * render_meta_box
203
- *
204
213
* Renders the ACF metabox HTML.
205
214
*
206
215
* @date 19/9/18
207
216
* @since ACF 5.7.6.7.6
208
217
*
209
- * @param WP_Post $post The post being edited.
210
- * @param array metabox The add_meta_box() args.
218
+ * @param WP_Post $post The post being edited.
219
+ * @param array $ metabox The add_meta_box() args.
211
220
* @return void
212
221
*/
213
- function render_meta_box ( $ post , $ metabox ) {
222
+ public function render_meta_box ( $ post , $ metabox ) {
214
223
215
224
// vars
216
225
$ id = $ metabox ['id ' ];
@@ -222,25 +231,21 @@ function render_meta_box( $post, $metabox ) {
222
231
}
223
232
224
233
/**
225
- * wp_insert_post_empty_content
226
234
*
227
235
* Allows WP to insert a new post without title or post_content if ACF data exists.
228
236
*
229
237
* @date 16/07/2014
230
238
* @since ACF 5.0.1.0.1
231
239
*
232
240
* @param boolean $maybe_empty Whether the post should be considered "empty".
233
- * @param array $postarr Array of post data.
234
241
* @return boolean
235
242
*/
236
- function wp_insert_post_empty_content ( $ maybe_empty, $ postarr ) {
243
+ public function wp_insert_post_empty_content ( $ maybe_empty ) {
237
244
238
- // return false and allow insert if '_acf_changed' exists
245
+ // Return false and allow insert if '_acf_changed' exists.
239
246
if ( $ maybe_empty && acf_maybe_get_POST ( '_acf_changed ' ) ) {
240
247
return false ;
241
248
}
242
-
243
- // return
244
249
return $ maybe_empty ;
245
250
}
246
251
@@ -255,33 +260,31 @@ function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
255
260
* @param WP_Post $post The post to check.
256
261
* @return boolean
257
262
*/
258
- function allow_save_post ( $ post ) {
263
+ public function allow_save_post ( $ post ) {
259
264
260
- // vars
261
265
$ allow = true ;
262
266
263
- // restrict post types
267
+ // Restricted post types.
264
268
$ restrict = array ( 'auto-draft ' , 'revision ' , 'acf-field ' , 'acf-field-group ' );
265
- if ( in_array ( $ post ->post_type , $ restrict ) ) {
269
+ if ( in_array ( $ post ->post_type , $ restrict, true ) ) {
266
270
$ allow = false ;
267
271
}
268
272
269
- // disallow if the $_POST ID value does not match the $post->ID
273
+ // Disallow if the $_POST ID value does not match the $post->ID.
270
274
$ form_post_id = (int ) acf_maybe_get_POST ( 'post_ID ' );
271
275
if ( $ form_post_id && $ form_post_id !== $ post ->ID ) {
272
276
$ allow = false ;
273
277
}
274
278
275
- // revision (preview)
276
- if ( $ post ->post_type == ' revision ' ) {
279
+ // Revision (preview).
280
+ if ( ' revision ' === $ post ->post_type ) {
277
281
278
282
// allow if doing preview and this $post is a child of the $_POST ID
279
- if ( acf_maybe_get_POST ( 'wp-preview ' ) == ' dopreview ' && $ form_post_id === $ post ->post_parent ) {
283
+ if ( ' dopreview ' === acf_maybe_get_POST ( 'wp-preview ' ) && $ form_post_id === $ post ->post_parent ) {
280
284
$ allow = true ;
281
285
}
282
286
}
283
287
284
- // return
285
288
return $ allow ;
286
289
}
287
290
@@ -306,7 +309,7 @@ public function save_post( $post_id, $post ) {
306
309
}
307
310
308
311
// Validate for published post (allow draft to save without validation).
309
- if ( $ post -> post_status === ' publish ' ) {
312
+ if ( ' publish ' === $ post -> post_status ) {
310
313
// Bail early if validation fails.
311
314
if ( ! acf_validate_save_post () ) {
312
315
return ;
0 commit comments