1. add_action( 'admin_head-post-new.php', 'wpse_59770_publish_admin_hook' );
  2. add_action( 'admin_head-post.php', 'wpse_59770_publish_admin_hook' );
  3. add_action( 'wp_ajax_wpse_59770_pre_submit_validation', 'wpse_59770_ajax_pre_submit_validation' );
  4.  
  5. function wpse_59770_publish_admin_hook()
  6. {
  7.     global $current_screen;
  8.     if( 'page' != $current_screen->post_type )
  9.         return;
  10.  
  11.     ?>
  12.     <script>
  13.         jQuery(document).ready(function() {
  14.             jQuery('#publish').click(function()
  15.             {
  16.                 jQuery('#publishing-action #ajax-loading').css('visibility', 'visible');
  17.                 var data = {
  18.                     action: 'wpse_59770_pre_submit_validation',
  19.                     security: '<?php echo wp_create_nonce( 'pre_publish_validation' ); ?>',
  20.                 };
  21.                 jQuery.post(ajaxurl, data, function(response)
  22.                 {
  23.                     // OK, save page
  24.                     if (response=='true') {
  25.                         jQuery('#publish').removeClass('button-primary-disabled');
  26.                         jQuery( "#publish" ).click()
  27.                     }
  28.                     // Not OK, display alert message
  29.                     else
  30.                     {
  31.                         alert(response);
  32.                         jQuery('#ajax-loading').css('visibility', 'hidden');
  33.                         jQuery('#publish').removeClass('button-primary-disabled');
  34.                         return false;
  35.                     }
  36.                 });
  37.                 return false;
  38.             });
  39.         });
  40.     </script>
  41.     <?php
  42. }
  43.  
  44.  
  45. function wpse_59770_ajax_pre_submit_validation()
  46. {
  47.     //simple Security check
  48.     check_ajax_referer( 'pre_publish_validation', 'security' );
  49.  
  50.     echo 'true';
  51.     die();
  52. }