66
77if ( ! class_exists ( 'ACF_Form_Post ' ) ) :
88
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+ */
917 class ACF_Form_Post {
1018
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 = '' ;
1325
1426 /**
1527 * __construct
@@ -21,20 +33,20 @@ class ACF_Form_Post {
2133 *
2234 * @return void
2335 */
24- function __construct () {
36+ public function __construct () {
2537
2638 // initialize on post edit screens
2739 add_action ( 'load-post.php ' , array ( $ this , 'initialize ' ) );
2840 add_action ( 'load-post-new.php ' , array ( $ this , 'initialize ' ) );
2941
3042 // 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 );
3244 add_action ( 'save_post ' , array ( $ this , 'save_post ' ), 10 , 2 );
3345 }
3446
3547
3648 /**
37- * initialize
49+ * Initialize.
3850 *
3951 * Sets up Form functionality.
4052 *
@@ -43,7 +55,7 @@ function __construct() {
4355 *
4456 * @return void
4557 */
46- function initialize () {
58+ public function initialize () {
4759
4860 // globals
4961 global $ typenow ;
@@ -72,7 +84,6 @@ function initialize() {
7284 }
7385
7486 /**
75- * add_meta_boxes
7687 *
7788 * Adds ACF metaboxes for the given $post_type and $post.
7889 *
@@ -83,7 +94,7 @@ function initialize() {
8394 * @param WP_Post $post The post being edited.
8495 * @return void
8596 */
86- function add_meta_boxes ( $ post_type , $ post ) {
97+ public function add_meta_boxes ( $ post_type , $ post ) {
8798
8899 // Storage for localized postboxes.
89100 $ postboxes = array ();
@@ -107,7 +118,7 @@ function add_meta_boxes( $post_type, $post ) {
107118 $ priority = 'high ' ; // high, core, default, low
108119
109120 // Reduce priority for sidebar metaboxes for best position.
110- if ( $ context == ' side ' ) {
121+ if ( ' side ' === $ context ) {
111122 $ priority = 'core ' ;
112123 }
113124
@@ -176,7 +187,7 @@ function add_meta_boxes( $post_type, $post ) {
176187 public function edit_form_after_title () {
177188
178189 // globals
179- global $ post, $ wp_meta_boxes ;
190+ global $ post ;
180191
181192 // render post data
182193 acf_form_data (
@@ -199,18 +210,16 @@ public function edit_form_after_title() {
199210 }
200211
201212 /**
202- * render_meta_box
203- *
204213 * Renders the ACF metabox HTML.
205214 *
206215 * @date 19/9/18
207216 * @since ACF 5.7.6.7.6
208217 *
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.
211220 * @return void
212221 */
213- function render_meta_box ( $ post , $ metabox ) {
222+ public function render_meta_box ( $ post , $ metabox ) {
214223
215224 // vars
216225 $ id = $ metabox ['id ' ];
@@ -222,25 +231,21 @@ function render_meta_box( $post, $metabox ) {
222231 }
223232
224233 /**
225- * wp_insert_post_empty_content
226234 *
227235 * Allows WP to insert a new post without title or post_content if ACF data exists.
228236 *
229237 * @date 16/07/2014
230238 * @since ACF 5.0.1.0.1
231239 *
232240 * @param boolean $maybe_empty Whether the post should be considered "empty".
233- * @param array $postarr Array of post data.
234241 * @return boolean
235242 */
236- function wp_insert_post_empty_content ( $ maybe_empty, $ postarr ) {
243+ public function wp_insert_post_empty_content ( $ maybe_empty ) {
237244
238- // return false and allow insert if '_acf_changed' exists
245+ // Return false and allow insert if '_acf_changed' exists.
239246 if ( $ maybe_empty && acf_maybe_get_POST ( '_acf_changed ' ) ) {
240247 return false ;
241248 }
242-
243- // return
244249 return $ maybe_empty ;
245250 }
246251
@@ -255,33 +260,31 @@ function wp_insert_post_empty_content( $maybe_empty, $postarr ) {
255260 * @param WP_Post $post The post to check.
256261 * @return boolean
257262 */
258- function allow_save_post ( $ post ) {
263+ public function allow_save_post ( $ post ) {
259264
260- // vars
261265 $ allow = true ;
262266
263- // restrict post types
267+ // Restricted post types.
264268 $ 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 ) ) {
266270 $ allow = false ;
267271 }
268272
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.
270274 $ form_post_id = (int ) acf_maybe_get_POST ( 'post_ID ' );
271275 if ( $ form_post_id && $ form_post_id !== $ post ->ID ) {
272276 $ allow = false ;
273277 }
274278
275- // revision (preview)
276- if ( $ post ->post_type == ' revision ' ) {
279+ // Revision (preview).
280+ if ( ' revision ' === $ post ->post_type ) {
277281
278282 // 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 ) {
280284 $ allow = true ;
281285 }
282286 }
283287
284- // return
285288 return $ allow ;
286289 }
287290
@@ -306,7 +309,7 @@ public function save_post( $post_id, $post ) {
306309 }
307310
308311 // Validate for published post (allow draft to save without validation).
309- if ( $ post -> post_status === ' publish ' ) {
312+ if ( ' publish ' === $ post -> post_status ) {
310313 // Bail early if validation fails.
311314 if ( ! acf_validate_save_post () ) {
312315 return ;
0 commit comments