Created
December 13, 2013 13:56
-
-
Save thomasgriffin/7944588 to your computer and use it in GitHub Desktop.
Here is a surefire way to hook into save_post if you need to save stuff. In my case, it is for custom metaboxes.
This file contains hidden or 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 | |
/** | |
* Callback for saving values from metaboxes. | |
* | |
* @since 1.0.0 | |
* | |
* @param int $post_id The current post ID. | |
* @param object $post The current post object. | |
*/ | |
function tgm_save_meta_boxes( $post_id, $post ) { | |
// Bail out if we fail a security check. | |
if ( ! isset( $_POST['some-identifier'] ) || ! wp_verify_nonce( $_POST['some-identifier'], 'some-identifier' ) ) | |
return; | |
// Bail out if running an autosave, ajax, cron or revision. | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
return; | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) | |
return; | |
if ( defined( 'DOING_CRON' ) && DOING_CRON ) | |
return; | |
if ( wp_is_post_revision( $post_id ) ) | |
return; | |
// Bail out if the user doesn't have the correct permissions to update the slider. | |
if ( ! current_user_can( 'edit_post', $post_id ) ) | |
return; | |
// As you were - it is safe to do stuff now. :-) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment