Are you using a checklist when writing your articles?

by krike in CMS / Reviews / Tutorials / wordpress on 17 Jan 2013


I have a huge problem, when writing an article I always forget to do something. I always tell myself I will remember, but no …. I just keep forgetting everything.

I needed a plugin to add a todo list that i could check each time I finished an item on that list. Before creating my own plugin I always google or check the wordpress plugin list to see if something like this existed.

There were plenty of plugins but most results led me to the blogging checklist plugin. It is a small and simple plugin and that is exactly what I needed. I hate plugins with to many options to configure and even tough the pugin wasn’t updated for 2 years it still works perfectly.

Step 1. You install and activate

Screen Shot 2013-01-17 at 19.52.59

Step 2. Create your checklist items

Screen Shot 2013-01-17 at 19.53.48

Step 3. and start writing your posts and check off the items as you go.

Screen Shot 2013-01-17 at 19.54.28

BUT!

the plugin misses a very important feature to my opinion. It DOES NOT save the checked items after page refresh ( page refresh can also be triggered when saving or publishing)

I’m not sure why the plugin author didn’t bather with this. What if you have to leave suddenly and did not finish your article? You would love to know where you left off and what is left to do. Yes you can go over the items to see which one are done. But that’s not exactly the point, is it?

So If like me you wish to save your checked items per post, follow these simple steps.

1) open /blogging-checklist/blogging-checklist.php

2) find the following function:

/* Prints the inner fields for the custom post/page section */
function bloggingchecklist_inner_custom_box() {

  // Use nonce for verification

  echo '<input type="hidden" name="bloggingchecklist_noncename" id="bloggingchecklist_noncename" value="' .
    wp_create_nonce( plugin_basename(__FILE__) ) . '" />';

  // The actual fields for data entry
  ?>
  <em>Note: the following checkboxes will be cleared each time you load this page and are not interactive.</em>
  <?

  // Read in existing option value from database, and display
  echo "<p>";
  echo blogging_checklist_convert(get_option("bloggingchecklist_content"));
  echo "</p>";

}

3) replace with the following:

/*
 * MODIFICATION: Save selected options to keep the selected options after page refresh
 */
/* Prints the inner fields for the custom post/page section */
function bloggingchecklist_inner_custom_box() {
    global $post;
    $blogChecklistFieldId = 'blogging_checklist_options';
    $savedOptions = get_post_meta($post->ID, $blogChecklistFieldId, true);
    // Use nonce for verification
    echo '<input type="hidden" name="bloggingchecklist_noncename" id="bloggingchecklist_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
    // The actual fields for data entry
    $options = get_option("bloggingchecklist_content");
    $options = explode('[ ]', $options);
    foreach($options as $option){
        if(!empty($option)) {
            $shortname = strtolower(str_replace(' ', '_', trim($option)));
            $checked = (is_array($savedOptions) && in_array($shortname, $savedOptions)) ? 'checked="checked"':'';
            echo "<p><input type='checkbox' id='" . $shortname . "' name='" . $blogChecklistFieldId . "[]' value='" . $shortname . "' " . $checked . " /> ";
            if(is_array($savedOptions) && in_array($shortname, $savedOptions)){
                echo '<del>' . $option . '</del>';
            } else {
                echo $option;
            }
            echo "</p>";
        }
    }

}

function bloggingchecklist_inner_custom_box_save($postId) {
    $blogChecklistFieldId = 'blogging_checklist_options';
    // verify nonce
    //print_r($_POST);
    if (array_key_exists('bloggingchecklist_noncename', $_POST) && !wp_verify_nonce($_POST['bloggingchecklist_noncename'], plugin_basename(__FILE__))) {
        return $postId;
    }
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $postId;
    }
    // check permissions
    if (array_key_exists('post_type', $_POST) && 'page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $postId)) {
            return $postId;
        }
    } elseif (!current_user_can('edit_post', $postId)) {
        return $postId;
    }
    $old = get_post_meta($postId, $blogChecklistFieldId, true);
    if (array_key_exists($blogChecklistFieldId, $_POST)) {
        $options = $_POST[$blogChecklistFieldId];
    } else {
        $options = array();
    }
    update_post_meta($postId, $blogChecklistFieldId, $options);
}
add_action('save_post', 'bloggingchecklist_inner_custom_box_save');

/*
 * END MODIFICATION
 */

And that’s it, happy blogging!

Written by krike

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sit amet nisl nisl. Ut interdum libero vitae quam ultricies et lacinia elit aliquet. Praesent tincidunt, sem tempus feugiat feugiat, turpis tellus scelerisque erat, sit amet feugiat neque arcu ac lectus. Sed at mi et elit interdum scelerisque vitae eu felis.

krike has written 77 posts.