Created
January 23, 2013 13:10
-
-
Save th3hamburgler/4605395 to your computer and use it in GitHub Desktop.
Wordpress: Save data from post meta box. Ignore pesky revisions.
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
/** | |
* Save custom post data meta box | |
* | |
* @access function | |
* @param int | |
* @return void | |
*/ | |
function save_post($post_id) { | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; | |
if (!wp_verify_nonce( $_POST['my_noncename'], MY_PLUGIN_DIRECTORY)) return; | |
// Check permissions | |
if ( 'page' == $_POST['post_type'] ) { | |
if ( !current_user_can( 'edit_page', $post_id ) ) return; | |
} else { | |
if ( !current_user_can( 'edit_post', $post_id ) ) return; | |
} | |
if (get_post_type($post_id) == 'revision') return; | |
// save data | |
update_post_meta($post_id, 'my_value', $_POST['my_value']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment