How can I make post fields required in WordPress?

I am setting up a WordPress site as a CMS and trying to figure out a way to make certain post fields “required” before an author can publish a post.

In particular, I want authors to be required to select a “category” and to set a “featured image”. It’s been suggested that something like this could be done using some Javascript, but to be honest, I’m not entirely sure where to start (and my Javascript skills aren’t the best).

If anyone has an idea as to how this can be done, I can really use the help. Thanks!

2 s
2

Fairly simple using jQuery and global $typenow ex:

add_action('admin_print_scripts-post.php', 'my_publish_admin_hook');
add_action('admin_print_scripts-post-new.php', 'my_publish_admin_hook');
function my_publish_admin_hook(){
    global $typenow;
    if (in_array($typenow, array('post','page','mm_photo '))){
        ?>
        <script language="javascript" type="text/javascript">
            jQuery(document).ready(function() {
                jQuery('#post').submit(function() {
                    if (jQuery("#set-post-thumbnail").find('img').size() > 0) {
                        jQuery('#ajax-loading').hide();
                        jQuery('#publish').removeClass('button-primary-disabled');
                        return true;
                    }else{
                        alert("please set a featured image!!!");
                        jQuery('#ajax-loading').hide();
                        jQuery('#publish').removeClass('button-primary-disabled');
                        return false;
                    }
                    return false;
                });
            });
        </script>

        <?php
    }
}

Leave a Comment