I am often using (and see others using) a set of code, that I see constantly and almost everywhere. Usually on save_post, many people bail out of the function if it's doing auto-save or ajax or cron. So you see a lot of copy-paste in these functions.
[php]
/** Bail out if running an autosave, ajax or a cron */
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
return;
if ( defined( 'DOING_CRON' ) && DOING_CRON )
return;
[/php]
However, I turned this into a function:
Please let me know what you think!!
leeyongqiang says
global $post;
/** Bail out if user does not have permissions */
if(!empty($post_id) && !current_user_can( $cap, $post_id )) return $post_id;
/** Bail out if running an autosave */
if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return true;
/** Bail out if running an ajax */
if ( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) return true;
/** Bail out if running a cron */
if ( defined( ‘DOING_CRON’ ) && DOING_CRON ) return true;
return false;