Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created June 24, 2015 01:52
Show Gist options
  • Save kellenmace/eb62a574defe62b7ce7d to your computer and use it in GitHub Desktop.
Save kellenmace/eb62a574defe62b7ce7d to your computer and use it in GitHub Desktop.
/*
* Require post title when adding/editing a Project Summary
*/
function rpt_require_post_title_for_custom_post_type() {
global $post;
// only run the code below if this is a "project_summary" post type
if ( 'project_summary' == $post->post_type ) {
?>
<script type='text/javascript'>
(function ($) {
$('body').on( 'submit.edit-post', '#post', function () {
// If the title isn't set
if( $("#title").val().replace(/ /g,'').length === 0 ) {
// Show a popup box that says "A title is required."
alert('A title is required.');
// Hide the spinner
$('#major-publishing-actions .spinner').hide();
// The buttons get "disabled" added to them on submit. Remove that class.
$('#major-publishing-actions').find( ':button, :submit, a.submitdelete, #post-preview' ).removeClass( 'disabled' );
// Focus on the title field.
$("#title").focus();
return false;
}
});
}(jQuery));
</script>
<?php
}
}
add_action( 'admin_print_footer_scripts', 'rpt_require_post_title_for_custom_post_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment