• Jim S.

    (@stitzelj)


    I need a plugin that limits an author to a post of maximum length (i.e. no more than 1000 words) for a project I’m putting together. Specifically, I’m looking for a plugin that allows an author to enter any number of words in the editor but that won’t let them publish the post until it has been edited down to the maximum number allowed (or lower). Unfortunately, I don’t have quite enough know-how to code something like this. Anyone able to write a plugin like this — or at least give me some direction as to how to get started or where to hook it in?

Viewing 7 replies - 1 through 7 (of 7 total)
  • luckdragon

    (@luckdragon)

    the problem with most plugins like that is it doesn’t strip out the html code when calculating, so
    <strong>hi there</strong>
    would actually count as 25 characters, and

    <img src="http://yourdomain.com/wp-content/plugins/whatever/images/filename.jpg" width="100" height="100">

    would count as 107 characters

    Thread Starter Jim S.

    (@stitzelj)

    Well, I don’t need a character count, but a word count. The content being submitted would be short fiction, so HTML markup would be minimal.

    luckdragon

    (@luckdragon)

    I’m not sure, I’ve seen jqueries that monitor the “comment” field, but not sure about the post one.

    Moderator bcworkz

    (@bcworkz)

    You want to hook the filter ‘wp_insert_post_data’. Your function will be passed an array with all the post data. If you assigned the array to $draft, you might be most interested in the value of $draft->post_content_filtered. Your function will need to somehow get a word count out of this value.

    Unresolved is how to handle a high word count. I think if you just did a wp_die(), the user can just use their back button and all of the form data is still retained. Certainly, more elegant solutions are possible.

    nbernhard

    (@nbernhard)

    Could you use jQuery or something similar to disable the ‘publish’ button until the word count is acceptable?

    You would still need a fallback for those who do not use Javascript, but this may be a good solution to start with.

    nbernhard

    (@nbernhard)

    For starters, this function would return the string without the HTML tags:

    jQuery.fn.stripTags = function () {
        return this.replaceWith(this.html().replace(/<\/?[^>]+>/gi, ''));
    };
    Thread Starter Jim S.

    (@stitzelj)

    Doesn’t the editor already count the number of words in a post? How do I tap into that?

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Limit Word Count’ is closed to new replies.