Created
August 1, 2012 17:47
-
-
Save wpsmith/3229180 to your computer and use it in GitHub Desktop.
Bail out if running an autosave, ajax or a cron for use in save_post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Bail out if running an autosave, ajax or a cron | |
* or user does not have proper capabilities | |
* | |
* @return bool|int True if should bail, post ID if lacking cap | |
*/ | |
function wps_bail( $post_id = '', $cap = 'edit_post' ) { | |
/** 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; | |
/** Bail out if user does not have permissions */ | |
if ( '' != $post_id && ! current_user_can( $cap, $post_id ) ) | |
return $post_id; | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'save_post', 'wps_save_worksheet_settings', 10, 2 ); | |
/** | |
* Save settings post meta fields added to Sermon metaboxes. | |
* | |
* @since 1.0.0 | |
* | |
* @param int $post_id The post ID | |
* @param object $post Current post object data | |
*/ | |
function wps_save_worksheet_settings( $post_id, $post ) { | |
/** Bail out if running an autosave, ajax or a cron */ | |
if ( wps_bail( $post_id ) ) return; | |
// do stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment