Can anybody please explain in simple words (layman's terms), what this function actually does.

if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {

I am learning to code custom post types and I found this function for saving the content of meta boxes.

Thanks in advance :)


That conditional logic first checkes if the constant DOING_AUTOSAVE is defined by using the PHP function defined('SOME_CONSTANT_NAME').

Then the logic checks to see if the state/value of the constant DOING_AUTOSAVE is true, that's the second part of the conditional right after the && (and).

So if DOING_AUTOSAVE has been defined in the request lifecycle and the state/value of DOING_AUTOSAVE is true then we return which is a means of aborting the logic that is to follow beneath the conditional.

DOING_AUTOSAVE only gets defined and set as true in the wp-admin/includes/post.php file within the wp_autosave() function.

Of course it may be defined elsewhere customly...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.