Created
June 23, 2015 04:13
-
-
Save kellenmace/04a871f782447d924ee7 to your computer and use it in GitHub Desktop.
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
/* | |
* 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