-
-
Save wkw/d9eb1125e2aac2a022d0eb25b1eba0eb to your computer and use it in GitHub Desktop.
How to hook into and pass your plugin data though WordPress Autosave
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
// Must be in an external file or loaded at the end of wp_footer() | |
jQuery(document).ajaxSend(function(e, x, a) { | |
var awesome = 1; | |
a.data += '&' + jQuery.param( {is_awesome: awesome} ); | |
}); |
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 | |
add_action('save_post', 'autosave_save_custom'); | |
function autosave_save_custom( $post ) { | |
if( wp_is_post_autosave($post) && isset( $_POST['is_awesome'] ) ) { | |
$is_awesome = intval( $_POST['is_awesome'] ); | |
$post_id = $post->ID; | |
update_metadata( $post->post_type, $post_id, 'is_awesome', $is_awesome ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment