• I added a code in my functions.php to require the maximum words in order to publish for my authors. I have an article directory where people guest blog.

    The only issues is that the Error message shown when you try to post something under X amount of words appears in another window saying:

    “Error: Your post is below the minimum word count.”

    How can I get this error to show up right above the post title after they publish it?

    function minWord($content){
    	global $post;
            $num = 100; //set this to the minimum number of words
    	$content = $post->post_content;
    	if (str_word_count($content) <  $num)
    	    wp_die( __('Error: your post is below the minimum word count.') );
    }
    add_action('publish_post', 'minWord');
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There is a message box feature you can use, it’s really intended for status messages like “Post updated”. For outright errors, the post edit page uses wp_die() just as you do. I suppose with inline CSS you could style the message box in some way that it’s clear that it’s a error message and not a status message.

    To use the message box, first hook ‘post_updated_messages’ and add your HTML to the passed array under the ‘post’ key. See the source to see the default message array definition.

    Next you need to request a new page with the array index number as a value for the URL parameter ‘message’, so the request might look something like this:
    example.com/wp-admin/post.php?post=123&action=edit&message=11

    Of course, the post parameter must have the correct ID. I’m not sure a redirect from the ‘publish_post’ hook will work or not. If it doesn’t, you’ll either need to find a hook that does or use javascript to generate the request.

Viewing 1 replies (of 1 total)
  • The topic ‘Change WP_Die error to view in dashboard’ is closed to new replies.