Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'admin_head-post-new.php', 'wpse_59770_publish_admin_hook' );
- add_action( 'admin_head-post.php', 'wpse_59770_publish_admin_hook' );
- add_action( 'wp_ajax_wpse_59770_pre_submit_validation', 'wpse_59770_ajax_pre_submit_validation' );
- function wpse_59770_publish_admin_hook()
- {
- global $current_screen;
- if( 'page' != $current_screen->post_type )
- return;
- ?>
- <script>
- jQuery(document).ready(function() {
- jQuery('#publish').click(function()
- {
- jQuery('#publishing-action #ajax-loading').css('visibility', 'visible');
- var data = {
- action: 'wpse_59770_pre_submit_validation',
- security: '<?php echo wp_create_nonce( 'pre_publish_validation' ); ?>',
- };
- jQuery.post(ajaxurl, data, function(response)
- {
- // OK, save page
- if (response=='true') {
- jQuery('#publish').removeClass('button-primary-disabled');
- jQuery( "#publish" ).click()
- }
- // Not OK, display alert message
- else
- {
- alert(response);
- jQuery('#ajax-loading').css('visibility', 'hidden');
- jQuery('#publish').removeClass('button-primary-disabled');
- return false;
- }
- });
- return false;
- });
- });
- </script>
- <?php
- }
- function wpse_59770_ajax_pre_submit_validation()
- {
- //simple Security check
- check_ajax_referer( 'pre_publish_validation', 'security' );
- echo 'true';
- die();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement