Skip to content
Snippets Groups Projects
Commit cbd0da5d authored by Erick Hitter's avatar Erick Hitter
Browse files

Start of Ajax handling to purge a post's revisions on demand.

See #1.
parent 3c397043
No related branches found
No related tags found
No related merge requests found
( function( $ ) {
$( document ).ready( function() {
var purge_button = $( '#wp_revisions_control .button.purge' ),
post_id = null,
nonce = null,
button_text = null;
$( purge_button ).on( 'click', click_handler_purge );
/**
*
*/
function click_handler_purge() {
post_id = parseInt( $( this ).data( 'postid' ) );
button_text = $( purge_button ).text();
$( purge_button ).text( wp_revisions_control.processing_text );
var confirmed = confirm( wp_revisions_control.ays );
if ( confirmed && post_id ) {
$.ajax({
url: ajaxurl,
cache: false,
data: {
action: wp_revisions_control.processing_text + '_purge',
post_id: post_id,
nonce: $( this ).data( 'nonce' )
},
type: 'post',
success: ajax_request_success,
error: ajax_request_error
});
} else {
$( purge_button ).text( button_text );
}
}
/**
*
*/
function ajax_request_success() {
console.log( 'Yippee' );
$( purge_button ).text( button_text );
}
/**
*
*/
function ajax_request_error() {
console.log( 'Sad panda' );
}
} );
} )( jQuery );
\ No newline at end of file
......@@ -232,8 +232,17 @@ class WP_Revisions_Control {
public function action_add_meta_boxes( $post_type, $post ) {
remove_meta_box( 'revisionsdiv', null, 'normal' );
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != get_post_status() && count( wp_get_post_revisions( $post ) ) > 1 )
if ( post_type_supports( $post_type, 'revisions' ) && 'auto-draft' != get_post_status() && count( wp_get_post_revisions( $post ) ) > 1 ) {
add_meta_box( 'revisionsdiv-wp-rev-ctl', __('Revisions'), array( $this, 'revisions_meta_box' ), null, 'normal', 'core' );
$handle = 'wp-revisions-control-post';
wp_enqueue_script( $handle, plugins_url( 'js/post.js', __FILE__ ), array( 'jquery' ), '20130706', true );
wp_localize_script( $handle, $this->settings_section, array(
'action_base' => $this->settings_section,
'processing_text' => __( 'Processing…', 'wp_revisions_control' ),
'ays' => __( 'Are you sure?', 'wp_revisions_control' )
) );
}
}
/**
......@@ -245,6 +254,8 @@ class WP_Revisions_Control {
?>
<div id="<?php echo esc_attr( $this->settings_section ); ?>">
<h4>WP Revisions Control</h4>
<span class="button purge" data-postid="<?php the_ID(); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( $this->settings_section . '_purge' ) ); ?>_purge"><?php _e( 'Purge these revisions', 'wp_revisions_control' ); ?></span>
</div><!-- #<?php echo esc_attr( $this->settings_section ); ?> -->
<?php
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment