diff --git a/README.md b/README.md index 6edd369..e8e2afd 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Draft List -Draft List allows you to both manage your draft and scheduled posts more easily but also to promote them by showing them on your site via shortcode or widget - use it to show your visitors what's "coming soon" or as a great SEO tool. +Draft List allows you to promote your unpublished posts by showing them on your site via a shortcode or widget - use it to show your visitors what's "coming soon" or as a great SEO tool. -How easy is it display a list of draft posts? Here's an example of how you could use it in a post or page... +How easy is it display a list of unpublished posts? Here's an example of how you could use it in a post or page... `[drafts limit=5 type=post order=ma scheduled=no template='{{ul}}{{draft}} {{icon}}']` @@ -10,9 +10,9 @@ This would display a list of up to 5 draft posts in ascending modified date sequ Features include... -* Quick links added to admin menu for going straight to your draft posts and pages -* Menu links show the number of drafts you currently have * Widget/shortcode output is highly configurable - create your own look by using a template, identify scheduled posts with an icon, sequence the results in various ways and even narrow down the results to a specific timeframe -* Click on any of the drafts posts listed to edit them +* If you're logged in, click on any of the posts listed to edit them * Output is cached for streamlined performance -* A meta box in the editor screen allows you to omit individual posts from any list outputs +* A meta box in the editor screen allows you to omit individual posts from any list output + +

 

\ No newline at end of file diff --git a/assets/Archive/banner-1544x500.png b/assets/Archive/banner-1544x500.png deleted file mode 100755 index f2a6aff..0000000 Binary files a/assets/Archive/banner-1544x500.png and /dev/null differ diff --git a/assets/Archive/banner-772x250.png b/assets/Archive/banner-772x250.png deleted file mode 100755 index 917693e..0000000 Binary files a/assets/Archive/banner-772x250.png and /dev/null differ diff --git a/assets/Archive/icon-128x128.png b/assets/Archive/icon-128x128.png deleted file mode 100644 index b555674..0000000 Binary files a/assets/Archive/icon-128x128.png and /dev/null differ diff --git a/assets/Archive/icon-256x256.png b/assets/Archive/icon-256x256.png deleted file mode 100644 index 25c6fc7..0000000 Binary files a/assets/Archive/icon-256x256.png and /dev/null differ diff --git a/assets/icon-128x128.png b/assets/icon-128x128.png index 4134ffe..777cf57 100644 Binary files a/assets/icon-128x128.png and b/assets/icon-128x128.png differ diff --git a/assets/icon-256x256.png b/assets/icon-256x256.png index b1e48a0..c4ddddc 100644 Binary files a/assets/icon-256x256.png and b/assets/icon-256x256.png differ diff --git a/assets/screenshot-2.png b/assets/screenshot-2.png deleted file mode 100644 index c3ad0ac..0000000 Binary files a/assets/screenshot-2.png and /dev/null differ diff --git a/inc/class-draftlistwidget.php b/inc/class-draftlistwidget.php new file mode 100755 index 0000000..d1fd583 --- /dev/null +++ b/inc/class-draftlistwidget.php @@ -0,0 +1,265 @@ + __( 'WordPress plugin to manage and promote your unpublished content.', 'simple-draft-list' ), + 'class' => 'dl-widget', + 'customize_selective_refresh' => true, + ) + ); + } + + /** + * Display widget + * + * Display the widget + * + * @uses adl_generate_code Generate the required code + * + * @param string $args Arguments. + * @param string $instance Instance. + */ + public function widget( $args, $instance ) { + + extract( $args, EXTR_SKIP ); + + // Merge in default values. + $instance = wp_parse_args( (array) $instance, adl_load_widget_defaults() ); + + // Output the header. + echo wp_kses( $before_widget, 'post' ); + + // Extract title for heading. + $title = $instance['title']; + + // Output title, if one exists. + if ( ! empty( $title ) ) { + echo wp_kses( $before_title . $title . $after_title, 'post' ); + } + + // Generate the video and output it. + echo wp_kses( + adl_generate_code( + $instance['limit'], + $instance['type'], + $instance['order'], + $instance['scheduled'], + $instance['folder'], + $instance['date'], + $instance['created'], + $instance['modified'], + $instance['template'], + $instance['words'], + $instance['pending'], + ), + 'post', + ); + + // Output the trailer. + echo wp_kses( $after_widget, 'post' ); + } + + /** + * Widget update/save function + * + * Update and save widget + * + * @param string $new_instance New instance. + * @param string $old_instance Old instance. + * @return string Instance. + */ + public function update( $new_instance, $old_instance ) { + + $instance = $old_instance; + $instance['title'] = $new_instance['title']; + $instance['limit'] = $new_instance['limit']; + $instance['type'] = $new_instance['type']; + $instance['order'] = $new_instance['order']; + $instance['scheduled'] = $new_instance['scheduled']; + $instance['folder'] = $new_instance['folder']; + $instance['date'] = $new_instance['date']; + $instance['created'] = $new_instance['created']; + $instance['modified'] = $new_instance['modified']; + $instance['template'] = $new_instance['template']; + $instance['words'] = $new_instance['words']; + $instance['pending'] = $new_instance['pending']; + + return $instance; + } + + /** + * Widget Admin control form + * + * Define admin file + * + * @param string $instance Instance. + */ + public function form( $instance ) { + + // Merge in default values. + $instance = wp_parse_args( (array) $instance, adl_load_widget_defaults() ); + + // Title field. + $field_id = $this->get_field_id( 'title' ); + $field_name = $this->get_field_name( 'title' ); + echo "\r\n" . '

'; + + // Template field. + $field_id = $this->get_field_id( 'template' ); + $field_name = $this->get_field_name( 'template' ); + echo "\r\n" . '

'; + + // Limit field. + $field_id = $this->get_field_id( 'limit' ); + $field_name = $this->get_field_name( 'limit' ); + echo "\r\n" . '

'; + + // Minimum number of words. + $field_id = $this->get_field_id( 'words' ); + $field_name = $this->get_field_name( 'words' ); + echo "\r\n" . '

'; + + // Draft types field. + $field_id = $this->get_field_id( 'type' ); + $field_name = $this->get_field_name( 'type' ); + echo "\r\n" . '

'; + + // Order field. + $field_id = $this->get_field_id( 'order' ); + $field_name = $this->get_field_name( 'order' ); + echo "\r\n" . '

'; + + // Scheduled field. + $field_id = $this->get_field_id( 'scheduled' ); + $field_name = $this->get_field_name( 'scheduled' ); + echo "\r\n" . '

'; + + // Show pending posts. + $field_id = $this->get_field_id( 'pending' ); + $field_name = $this->get_field_name( 'pending' ); + echo "\r\n" . '

'; + + // Folder field. + $field_id = $this->get_field_id( 'folder' ); + $field_name = $this->get_field_name( 'folder' ); + echo "\r\n" . '

'; + + // Date format field. + $field_id = $this->get_field_id( 'date' ); + $field_name = $this->get_field_name( 'date' ); + echo "\r\n" . '

'; + + // Created field. + $field_id = $this->get_field_id( 'created' ); + $field_name = $this->get_field_name( 'created' ); + echo "\r\n" . '

'; + + // Modified field. + $field_id = $this->get_field_id( 'modified' ); + $field_name = $this->get_field_name( 'modified' ); + echo "\r\n" . '

'; + + echo '

* ' . esc_html__( 'leave blank to show posts across all time periods', 'simple-draft-list' ) . '

'; + } +} + +/** + * Register Widget + * + * Register widget when loading the WP core + */ +function adl_register_widgets() { + register_widget( 'DraftListWidget' ); +} + +add_action( 'widgets_init', 'adl_register_widgets' ); + +/** + * Widget defaults + * + * Return default values for the widget + */ +function adl_load_widget_defaults() { + return array( + 'title' => __( 'Coming Soon', 'simple-draft-list' ), + 'limit' => '0', + 'type' => '', + 'order' => '', + 'scheduled' => 'yes', + 'pending' => 'no', + 'folder' => '', + 'date' => 'F j, Y, g:i a', + 'created' => '', + 'modified' => '', + 'template' => '{{ol}}{{draft}} {{icon}}', + ); +} diff --git a/inc/create-lists.php b/inc/create-lists.php new file mode 100755 index 0000000..009fb2c --- /dev/null +++ b/inc/create-lists.php @@ -0,0 +1,449 @@ + '', + 'type' => '', + 'order' => '', + 'scheduled' => '', + 'icon' => '', + 'folder' => '', + 'author' => '', + 'template' => '', + 'date' => '', + 'created' => '', + 'modified' => '', + 'words' => '', + 'pending' => '', + ), + $paras + ) + ); + + if ( '' == $template ) { + $template = adl_convert_to_template( $icon, $author ); + } + + return adl_generate_code( $limit, $type, $order, $scheduled, $folder, $date, $created, $modified, $template, $words, $pending ); + +} +add_shortcode( 'drafts', 'adl_draft_list_shortcode' ); + +/** + * Generate draft list + * + * Generate draft list output based on passed parameters + * + * @param string $list_limit List limit. + * @param string $list_type List type. + * @param string $list_order List order. + * @param string $scheduled Show scheduled posts. + * @param string $icon_folder Icon folder. + * @param string $date_format Date format to use. + * @param string $created Created range. + * @param string $modified Modified range. + * @param string $template Template. + * @param string $words Number of words. + * @param string $pending Whether to show pending posts. + * @return string Draft list output. + */ +function adl_generate_code( $list_limit = '', $list_type = '', $list_order = '', $scheduled = '', $icon_folder = '', $date_format = '', $created = '', $modified = '', $template = '', $words = '', $pending = '' ) { + + // Validate the list type. + if ( ( 'post' != $list_type ) && ( 'page' != $list_type ) && ( '' != $list_type ) ) { + $list_type = 'error'; + } + + $plugin_name = 'Draft List'; + + // Convert appropriate parameters. + $list_type = strtolower( $list_type ); + $list_order = strtolower( $list_order ); + $scheduled = strtolower( $scheduled ); + $pending = strtolower( $pending ); + $template = html_entity_decode( $template ); + + // Set default values. + if ( '' == $list_limit ) { + $list_limit = 0; + } + if ( '' == $words ) { + $words = 0; + } + if ( '' == $list_order ) { + $list_order = 'da'; + } + if ( '' == $scheduled ) { + $scheduled = 'yes'; + } + if ( '' == $pending ) { + $pending = 'no'; + } + if ( '' == $date_format ) { + $date_format = 'F j, Y, g:i a'; + } + if ( '' == $template ) { + $template = '{{ul}}{{draft}}'; + } + + // Define order of the results. + $first_char = substr( $list_order, 0, 1 ); + $second_char = substr( $list_order, 1, 1 ); + $sort_field = ''; + $sort_sequence = ''; + + if ( ( 'd' == $first_char ) || ( 'm' == $first_char ) ) { + $sort_field = 'post_modified'; + } + if ( 'c' == $first_char ) { + $sort_field = 'post_date'; + } + if ( 't' == $first_char ) { + $sort_field = 'post_title'; + } + if ( 'a' == $second_char ) { + $sort_sequence = ' ASC'; + } + if ( 'd' == $second_char ) { + $sort_sequence = ' DESC'; + } + + // Perform validation of passed parameters. + $error = false; + if ( ! is_numeric( $list_limit ) ) { + $code .= adl_report_error( __( 'The limit is invalid - it must be a number', 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + if ( ! is_numeric( $words ) ) { + $code .= adl_report_error( __( 'The minimum number of words is invalid - it must be a number', 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + if ( ( '' == $sort_field ) || ( '' == $sort_sequence ) ) { + $code .= adl_report_error( __( 'The order is invalid - please view the instructions for valid combinations', 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + if ( ( 'post' != $list_type ) && ( 'page' != $list_type ) && ( '' != $list_type ) ) { + $code .= adl_report_error( __( "The list type is invalid - it must be blank, 'post' or 'page'.", 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + if ( ( 'no' != $scheduled ) && ( 'yes' != $scheduled ) ) { + $code .= adl_report_error( __( "The scheduled parameter must be either 'Yes' or 'No'", 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + if ( strpos( $template, '%draft%' ) == false && strpos( $template, '{{draft}}' ) == false ) { + $code .= adl_report_error( __( 'The template must include the {{draft}} tag', 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + + // Calculate created and modified dates to compare with. + $far_past = '2 January 1970'; + + if ( '' != $created ) { + $created = '-' . $created; + } else { + $created = $far_past; + } + $created = strtotime( $created ); + if ( ( -1 == $created ) || ( ! $created ) ) { + $code .= adl_report_error( __( 'The created parameter is invalid', 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + $created = date( 'Y-m-d H:i:s', $created ); + + if ( '' != $modified ) { + $modified = '-' . $modified; + } else { + $modified = $far_past; + } + $modified = strtotime( $modified ); + if ( ( -1 == $modified ) || ( ! $modified ) ) { + $code .= adl_report_error( __( 'The modified parameter is invalid', 'simple-draft-list' ), $plugin_name, false ); + $error = true; + } + $modified = date( 'Y-m-d H:i:s', $modified ); + + if ( ! $error ) { + + // Define the type of list required. + $type = array( 'post', 'page' ); + if ( ( 'post' == $list_type ) || ( 'page' == $list_type ) ) { + $type = $list_type; + } + + $status = array( 'draft' ); + + if ( true === $scheduled || 'true' == $scheduled || 'yes' == $scheduled ) { + array_push( $status, 'future' ); + } + if ( true === $pending || 'true' == $pending || 'yes' == $pending ) { + array_push( $status, 'pending' ); + } + + // Define icon folder. + if ( '' == $icon_folder ) { + $icon_folder = plugins_url( 'images/', dirname( __FILE__ ) ); + } else { + $icon_folder = get_bloginfo( 'template_url' ) . '/' . $icon_folder . '/'; + } + + // Has a word or character count been requested? + if ( ( $words > 0 ) || ( strpos( $template, '%words%' ) != false ) || ( strpos( $template, '{{words}}' ) != false ) || ( strpos( $template, '%chars%' ) != false ) || ( strpos( $template, '%chars+space%' ) != false ) || ( strpos( $template, '{{chars+space}}' ) != false ) ) { + $sql_content = ', post_content'; + $count = true; + } else { + $sql_content = ''; + $count = false; + } + + // Extract drafts from database based on parameters. + $args = array( + 'post_status' => $status, + 'post_type' => $type, + 'numberposts' => 99, + 'orderby' => $sort_field, + 'sort_order' => $sort_sequence, + ); + + $drafts = get_posts( $args ); + + // If template contains list tags at beginning, wrap these around output. + $list = false; + if ( ( ( '%ol%' == substr( $template, 0, 4 ) ) || ( '%ul%' == substr( $template, 0, 4 ) ) ) && ( 1 != $list_limit ) ) { + $list_type = substr( $template, 1, 2 ); + $code .= '<' . $list_type . ">\n"; + $list = true; + + // Remove any OL and UL tags. + $template = str_replace( '%' . $list_type . '%', '', $template ); + } + + if ( ( ( '{{ol}}' == substr( $template, 0, 6 ) ) || ( '{{ul}}' == substr( $template, 0, 6 ) ) ) && ( 1 != $list_limit ) ) { + $list_type = substr( $template, 2, 2 ); + $code .= '<' . $list_type . ">\n"; + $list = true; + + // Remove any OL and UL tags. + $template = str_replace( '{{' . $list_type . '}}', '', $template ); + } + + $valid_draft = 1; + foreach ( $drafts as $draft_data ) { + + // Skip the post if the title beings with an exclamation mark. + $post_title = $draft_data->post_title; + + if ( '!' != substr( $post_title, 0, 1 ) ) { + + // Extract fields from MySQL results. + $post_id = $draft_data->ID; + $post_type = $draft_data->post_type; + $draft_title = $draft_data->post_title; + $post_created = $draft_data->post_date; + $post_modified = $draft_data->post_modified; + if ( $count ) { + $post_content = $draft_data->post_content; + $post_length = str_word_count( $post_content ); + } + + // Check if the post has enough words in it. + if ( $count && $post_length <= $words ) { + $enough_words = false; + } else { + $enough_words = true; + } + + // Does the current user have editor privileges for the current post type. + if ( ( ( current_user_can( 'edit_posts' ) ) && ( 'post' == $post_type ) ) || ( ( current_user_can( 'edit_pages' ) ) && ( 'page' == $post_type ) ) ) { + $can_edit = true; + } else { + $can_edit = false; + } + + // If the current user can edit then allow a blank title. + if ( ( '' == $draft_title ) && ( $can_edit ) ) { + $draft_title = __( '[No Title]', 'simple-draft-list' ); + } + + // Work out whether created and/or modified date is acceptable. + if ( ( $post_created > $created ) && ( $post_modified > $modified ) ) { + $date_accept = true; + } else { + $date_accept = false; + } + + // Only output if the meta isn't set to exclude it, the limit hasn't been reached, + // there are enough words in the post, the dates are fine and the title isn't blank. + if ( ( $date_accept ) && ( $enough_words ) && ( '' != $draft_title ) && ( 'yes' != strtolower( get_post_meta( $post_id, 'draft_hide', true ) ) ) && ( ( 0 == $list_limit ) || ( $valid_draft <= $list_limit ) ) ) { + + $post_status = $draft_data->post_status; + $author = $draft_data->display_name; + $author_url = $draft_data->user_url; + + if ( $count ) { + $post_content = $draft_data->post_content; + } + + // Build line. + if ( $list ) { + $this_line = "\t
  • "; + } else { + $this_line = ''; + } + $this_line .= $template; + if ( $list ) { + $this_line .= '
  • '; + } + + // Replace the icon tag. + $alt_title = __( 'Scheduled', 'simple-draft-list' ); + if ( 'future' == $post_status ) { + $icon_url = '' . $alt_title . ''; + } else { + $icon_url = ''; + } + $this_line = str_replace( '{{icon}}', $icon_url, $this_line ); + + // Replace the author tag. + $this_line = str_replace( '{{author}}', $author, $this_line ); + + if ( '' != $author_url ) { + $author_link = '' . $author . ''; + } else { + $author_link = $author; + } + $this_line = str_replace( '{{author+link}}', $author_link, $this_line ); + + // Replace the draft tag. + if ( '' != $draft_title ) { + $draft = $draft_title; + } else { + $draft = __( '(no title)', 'simple-draft-list' ); + } + if ( $can_edit ) { + $draft = '' . $draft . ''; + } + $this_line = str_replace( '{{draft}}', $draft, $this_line ); + + // Replace the created date. + $created_date = date( $date_format, strtotime( $post_created ) ); + $this_line = str_replace( '{{created}}', $created_date, $this_line ); + + // Replace the modified date. + $modified_date = date( $date_format, strtotime( $post_modified ) ); + $this_line = str_replace( '{{modified}}', $modified_date, $this_line ); + + // Replace the word and character counts. + if ( $count ) { + if ( strpos( $this_line, '{{words}}' ) != false ) { + $this_line = str_replace( '{{words}}', number_format( $word_count ), $this_line ); + } + if ( strpos( $this_line, '{{chars}}' ) != false ) { + $this_line = str_replace( '{{chars}}', number_format( strlen( $post_content ) - substr_count( $post_content, ' ' ) ), $this_line ); + } + if ( strpos( $this_line, '{{chars+space}}' ) != false ) { + $this_line = str_replace( '{{chars+space}}', number_format( strlen( $post_content ) ), $this_line ); + } + } + + // Replace the category. + $category = get_the_category( $post_id ); + $category = $category[0]->cat_name; + if ( 'Uncategorized' == $category ) { + $category = ''; + } + $this_line = str_replace( '{{category}}', $category, $this_line ); + + // Replace the categories. + $category_list = ''; + foreach ( ( get_the_category( $post_id ) ) as $category ) { + if ( 'Uncategorized' != $category->cat_name ) { + $category_list .= ', ' . $category->cat_name; + } + } + if ( '' != $category_list ) { + $category_list = substr( $category_list, 2 ); + } + + $this_line = str_replace( '{{categories}}', $category_list, $this_line ); + + // Now add the current line to the overall code output. + $code .= $this_line . "\n"; + $valid_draft++; + } + } + } + + if ( $list ) { + $code .= ''; + } + } + + return $code; +} + +/** + * Convert parameters to a template + * + * Convert old parameters to template equivalent + * + * @param string $icon Icon position. + * @param string $author Whether to show author. + * @return string Template. + */ +function adl_convert_to_template( $icon = '', $author = '' ) { + + $template = '{{ul}}'; + if ( strtolower( $icon ) == 'left' ) { + $template .= '{{icon}} '; + } + $template .= '{{draft}}'; + if ( strtolower( $author ) == 'yes' ) { + $template .= ' ({{author}})'; + } + if ( strtolower( $icon ) == 'right' ) { + $template .= ' {{icon}}'; + } + + return $template; +} + +/** + * Report an error + * + * Function to report an error + * + * @param string $error Error message. + * @param string $plugin_name The name of the plugin. + * @param string $echo True or false, depending on whether you wish to return or echo the results. + * @return string True. + */ +function adl_report_error( $error, $plugin_name, $echo = true ) { + + $output = '

    ' . $plugin_name . ': ' . $error . "

    \n"; + if ( $echo ) { + echo esc_html( $output ); + return true; + } else { + return $output; + } +} + diff --git a/inc/metabox.php b/inc/metabox.php new file mode 100755 index 0000000..a7ff695 --- /dev/null +++ b/inc/metabox.php @@ -0,0 +1,100 @@ +' . esc_html__( 'Hide from Draft List?', 'simple-draft-list' ) . '  '; + echo 'ID, 'draft_hide', true ) ) ) { + echo ' checked="checked"'; + } + echo ' />'; + +} + +/** + * Save meta data + * + * Save the entered meta data + * + * @param string $post_id Post ID. + */ +function adl_save_postdata( $post_id ) { + + // If this is an auto save routine and the form has not been submitted then don't do anything. + + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return; + } + + // Verify this came from the correct meta box and with proper authorization. + + if ( isset( $_POST['artiss_draft_list_noncename'] ) ) { // Input var okay. + if ( ! wp_verify_nonce( sanitize_text_field( $_POST['artiss_draft_list_noncename'] ), plugin_basename( __FILE__ ) ) ) { + return; // Input var okay. + } + } + + // Check permissions. + + if ( isset( $_POST['post_type'] ) ) { // Input var okay. + if ( 'page' == sanitize_text_field( $_POST['post_type'] ) ) { // Input var okay. + if ( ! current_user_can( 'edit_page', $post_id ) ) { + return; + } + } else { + if ( ! current_user_can( 'edit_post', $post_id ) ) { + return; + } + } + } + + // Save the data. + + if ( isset( $_POST['adl_hide'] ) ) { // Input var okay. + $data = sanitize_text_field( $_POST['adl_hide'] ); // Input var okay. + } else { + $data = ''; + } + + update_post_meta( $post_id, 'draft_hide', $data ); + +} + +add_action( 'save_post', 'adl_save_postdata' ); diff --git a/inc/setup.php b/inc/setup.php new file mode 100755 index 0000000..813d01c --- /dev/null +++ b/inc/setup.php @@ -0,0 +1,35 @@ +' . __( 'Github', 'simple-draft-list' ) . '' ), + array( '' . __( 'Support', 'simple-draft-list' ) . '' ), + array( '' . __( 'Donate', 'simple-draft-list' ) . '' ), + array( '' . __( 'Write a Review', 'simple-draft-list' ) . ' ⭐️⭐️⭐️⭐️⭐️' ) + ); + } + + return $links; +} + +add_filter( 'plugin_row_meta', 'adl_set_plugin_meta', 10, 2 ); diff --git a/includes/admin-config.php b/includes/admin-config.php deleted file mode 100755 index 407ea5e..0000000 --- a/includes/admin-config.php +++ /dev/null @@ -1,85 +0,0 @@ -' . __( 'Github', 'simple-draft-list' ) . '' ) ); - - $links = array_merge( $links, array( '' . __( 'Support', 'simple-draft-list' ) . '' ) ); - - $links = array_merge( $links, array( '' . __( 'Donate', 'simple-draft-list' ) . '' ) ); - - $links = array_merge( $links, array( '' . __( 'Write a Review', 'simple-draft-list' ) . ' ⭐️⭐️⭐️⭐️⭐️' ) ); - } - - return $links; -} - -add_filter( 'plugin_row_meta', 'adl_set_plugin_meta', 10, 2 ); - -/** -* Admin Screen Initialisation -* -* Set up draft menu options -* -* @since 2.3 -*/ - -function adl_menu_initialise() { - - global $wpdb; - $author = get_current_user_id(); - - // Get total number of draft posts. If more than zero add a sub-menu option - - $all_posts = $wpdb -> get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft'" ); - if ( $all_posts > 0 ) { - - add_submenu_page( 'edit.php', '', __( 'All Drafts ' . $all_posts . '', 'simple-draft-list' ), 'edit_posts', esc_url( 'edit.php?post_status=draft&post_type=post' ) ); - - // Get total number of draft posts for current user. If more than zero add a sub-menu option - - $your_posts = $wpdb -> get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'draft' AND post_author=" . $author ); - if ( $your_posts > 0 && $your_posts !== $all_posts ) { - add_submenu_page( 'edit.php', '', __( 'My Drafts ' . $your_posts . '', 'simple-draft-list' ), 'edit_posts', esc_url( 'edit.php?post_status=draft&post_type=post&author=' . $author . '' ) ); - } - } - - // Get total number of draft pages. If more than zero add a sub-menu option - - $all_pages = $wpdb -> get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'draft'" ); - if ( $all_pages > 0 ) { - - add_submenu_page( 'edit.php?post_type=page', '', __( 'All Drafts ' . $all_pages . '', 'simple-draft-list' ), 'edit_pages', esc_url( 'edit.php?post_status=draft&post_type=page' ) ); - - // Get total number of draft pages for current user. If more than zero add a sub-menu option - - $your_pages = $wpdb -> get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'draft' AND post_author=" . $author ); - if ( $your_pages > 0 && $your_pages !== $all_pages ) { - add_submenu_page( 'edit.php?post_type=page', '', __( 'My Drafts ' . $your_pages . '', 'simple-draft-list' ), 'edit_pages', esc_url( 'edit.php?post_status=draft&post_type=page&author=' . $author . '' ) ); - } - } - -} - -add_action( 'admin_menu', 'adl_menu_initialise' ); diff --git a/includes/generate-code.php b/includes/generate-code.php deleted file mode 100755 index 044d4f5..0000000 --- a/includes/generate-code.php +++ /dev/null @@ -1,342 +0,0 @@ - '', 'type' => '', 'order' => '', 'scheduled' => '', 'icon' => '', 'folder' => '', 'author' => '', 'template' => '', 'date' => '', 'created' => '', 'modified' => '', 'cache' => '', 'words' => '', 'pending' => '' ), $paras ) ); - - if ( '' === $template ) { $template = adl_convert_to_template( $icon, $author); } - - return adl_generate_code( $limit, $type, $order, $scheduled, $folder, $date, $created, $modified, $cache, $template, $words, $pending ); - -} -add_shortcode( 'drafts', 'adl_draft_list_shortcode' ); - -/** -* Generate draft list -* -* Generate draft list output based on passed parameters -* -* @since 2.0 -* -* @param $list_limit string List limit -* @param $list_type string List type -* @param $list_order string List order -* @param $scheduled string Show scheduled posts -* @param $folder string Icon folder -* @param $date_format string Date format to use -* @param $created string Created range -* @param $modified string Modified range -* @param $template string Template -* @return string Draft list output -*/ - -function adl_generate_code( $list_limit = '', $list_type = '', $list_order = '', $scheduled = '', $icon_folder = '', $date_format = '', $created = '', $modified = '', $cache_time = '', $template = '', $words = '', $pending = '' ) { - - // Check and valid cache details - // If invalid, assign a value to it that will ensure no cache is fetched and it drops through to the error checking - - $cache_time = strtolower( $cache_time ); - if ( $cache_time === '' ) { $cache_time = 0.5; } - if ( ( $cache_time !== 'no' ) && ( !is_numeric( $cache_time ) ) ) { $cache_time = 'error'; } - - // Validate the list type as this will determine the cache key - - if ( ( $list_type !== 'post' ) && ( $list_type !== 'page' ) && ( $list_type !== '' ) ) { $list_type = 'error'; } - - // Check for cache - - if ( ( $cache_time === 'no' ) or ( $cache_time === 'error' ) or ( $list_type === 'error' ) ) { - $code = false; - } else { - - // Build an item of the cache key based on current privilages - this ensures that - // editors have their own cache - - if ( ( current_user_can( 'edit_posts' ) ) && ( ( $list_type === 'post' ) or ( $list_type === '' ) ) ) { $editor = "Y"; } else { $editor = "N"; } - if ( ( current_user_can( 'edit_pages' ) ) && ( ( $list_type === 'page' ) or ( $list_type === '' ) ) ) { $editor .= "Y"; } else { $editor .= "N"; } - - // Build cache key & attempt to get cache - - $cache_key = 'adl_' . md5( $list_limit . $list_type . $list_order . $scheduled . $icon_folder . $date_format . $created . $modified . $cache_time . $editor . $template . $words . $pending ); - $code = get_transient( $cache_key ); - } - - if ( !$code ) { - - $plugin_name = 'Draft List'; - $code = "\n\n"; - - // Convert appropriate parameters - - $list_type = strtolower( $list_type ); - $list_order = strtolower( $list_order ); - $scheduled = strtolower( $scheduled ); - $template = html_entity_decode( $template ); - - // Set default values - - if ( $list_limit === '' ) { $list_limit = 0; } - if ( $words === '' ) { $words = 0; } - if ( $list_order === '' ) { $list_order = 'da'; } - if ( $scheduled === '' ) { $scheduled = 'yes'; } - if ( $date_format === '' ) { $date_format = 'F j, Y, g:i a'; } - if ( $template === '' ) { $template = '{{ul}}{{draft}}'; } - - // Define order of the results - - $first_char = substr( $list_order, 0, 1 ); - $second_char = substr( $list_order, 1, 1 ); - $sort_field = ''; - $sort_sequence = ''; - - if ( ( $first_char === 'd' ) or ( $first_char === 'm' ) ) { $sort_field = 'post_modified'; } - if ( $first_char === 'c' ) { $sort_field = 'post_date'; } - if ( $first_char === 't' ) { $sort_field = 'post_title'; } - if ( $second_char === 'a' ) { $sort_sequence = ' ASC'; } - if ( $second_char === 'd' ) { $sort_sequence = ' DESC'; } - - $order = $sort_field . $sort_sequence; - - // Perform validation of passed parameters - - $error = false; - if ( !is_numeric( $list_limit ) ) { $code .= adl_report_error( __( 'The limit is invalid - it must be a number', 'simple-draft-list' ), $plugin_name, false ); $error = true; } - if ( !is_numeric( $words ) ) { $code .= adl_report_error( __( 'The minimum number of words is invalid - it must be a number', 'simple-draft-list' ), $plugin_name, false ); $error = true; } - if ( ( $sort_field === '' ) or ( $sort_sequence === '' ) ) { $code .= adl_report_error( __( 'The order is invalid - please view the instructions for valid combinations', 'simple-draft-list' ), $plugin_name, false ); $error = true; } - if ( ( $list_type !== 'post' ) && ( $list_type !== 'page' ) && ( $list_type !== '' ) ) { $code .= adl_report_error( __( "The list type is invalid - it must be blank, 'post' or 'page'.", 'simple-draft-list' ), $plugin_name, false ); $error = true; } - if ( ( $scheduled !== 'no' ) && ( $scheduled !== 'yes' ) ) { $code .= adl_report_error( __( "The scheduled parameter must be either 'Yes' or 'No'", 'simple-draft-list' ), $plugin_name, false ); $error = true; } - if ( ( $cache_time !== 'no' ) && ( !is_numeric( $cache_time ) ) ) { $code .= adl_report_error( __( "The cache time is invalid - it should either be a number or 'No'", 'simple-draft-list' ), $plugin_name, false ); $error = true; } - if ( strpos( $template, '%draft%' ) === false && strpos( $template, '{{draft}}' ) === false ) { $code .= adl_report_error( __( 'The template must include the {{draft}} tag', 'simple-draft-list' ), $plugin_name, false ); $error = true; } - - // Calculate created and modified dates to compare with - - $far_past = '2 January 1970'; - - if ( $created !== '' ) { $created = '-' . $created; } else { $created = $far_past; } - $created = strtotime( $created ); - if ( ( $created === -1 ) or ( !$created ) ) { $code .= adl_report_error( __( 'The created parameter is invalid', 'simple-draft-list' ), $plugin_name, false ); $error = true; } - $created = date( 'Y-m-d H:i:s', $created ); - - if ( $modified !== '' ) { $modified = '-' . $modified; } else { $modified = $far_past; } - $modified = strtotime( $modified ); - if ( ( $modified === -1 ) or ( !$modified ) ) { $code .= adl_report_error( __( 'The modified parameter is invalid', 'simple-draft-list' ), $plugin_name, false ); $error = true; } - $modified = date( 'Y-m-d H:i:s', $modified ); - - if ( !$error ) { - - // Define the type of list required - - if ( ( $list_type === 'post' ) or ( $list_type === 'page' ) ) { - $type = " AND post_type = '" . $list_type . "'"; - } else { - $type = " AND (post_type = 'post' OR post_type = 'page')"; - } - - $status = ''; - - if ( $scheduled !== 'no' && $scheduled !== false ) { $status .= " OR post_status = 'future'"; } - if ( $pending ) { $status .= " OR post_status = 'pending'"; } - - // Define icon folder - - if ( $icon_folder === '' ) { - $icon_folder = plugins_url( 'images/', dirname(__FILE__) ); - } else { - $icon_folder = get_bloginfo( 'template_url' ) . '/' . $icon_folder . '/'; - } - - // Has a word or character count been requested? - - if ( ( $words > 0 ) or ( strpos( $template, '%words%' ) !== false ) or ( strpos( $template, '{{words}}' ) !== false ) or ( strpos( $template, '%chars%' ) !== false ) or ( strpos( $template, '%chars+space%' ) !== false ) or ( strpos( $template, '{{chars+space}}' ) !== false ) ) { - $sql_content = ', post_content'; - $count = true; - } else { - $sql_content = ''; - $count = false; - } - - // Extract drafts from database based on parameters - - global $wpdb; - - $drafts = $wpdb -> get_results( "SELECT A.id, post_type, post_title, post_status, display_name, user_url, post_date, post_modified" . $sql_content . " FROM $wpdb->posts A, $wpdb->users B WHERE B.ID = A.post_author AND (post_status = 'draft'" . $status . ") AND post_title NOT LIKE '!%'" . $type . " ORDER BY " . $order ); - - // Loop through and output results - - if ( $drafts ) { - - // If template contains list tags at beginning, wrap these around output - - $list = false; - if ( ( ( substr( $template, 0, 4 ) === '%ol%' ) or ( substr( $template, 0, 4 ) === '%ul%' ) ) && ( $list_limit !== 1 ) ) { - $list_type = substr( $template, 1, 2 ); - $code .= '<' . $list_type . ">\n"; - $list = true; - - // Remove any OL and UL tags - - $template = str_replace( '%' . $list_type . '%', '', $template ); - } - - if ( ( ( substr( $template, 0, 6 ) === '{{ol}}' ) or ( substr( $template, 0, 6 ) === '{{ul}}' ) ) && ( $list_limit !== 1 ) ) { - $list_type = substr( $template, 2, 2 ); - $code .= '<' . $list_type . ">\n"; - $list = true; - - // Remove any OL and UL tags - - $template = str_replace( '{{' . $list_type . '}}', '', $template ); - } - - $valid_draft = 1; - foreach ( $drafts as $draft_data ) { - - // Extract fields from MySQL results - - $post_id = $draft_data -> id; - $post_type = $draft_data -> post_type; - $draft_title = $draft_data -> post_title; - $post_created = $draft_data -> post_date; - $post_modified = $draft_data -> post_modified; - if ( $count ) { - $post_content = $draft_data -> post_content; - $post_length = str_word_count( $post_content ); - } - - // Check if the post has enough words in it - - if ( $count && $post_length <= $words ) { $enough_words = false; } else { $enough_words = true; } - - // Does the current user have editor privileges for the current post type - - if ( ( ( current_user_can( 'edit_posts' ) ) && ( $post_type === 'post' ) ) or ( ( current_user_can( 'edit_pages' ) ) && ( $post_type === 'page' ) ) ) { $can_edit = true; } else { $can_edit = false; } - - // If the current user can edit then allow a blank title - - if ( ( $draft_title === '' ) && ( $can_edit ) ) { $draft_title = __( '[No Title]', 'simple-draft-list' ); } - - // Work out whether created and/or modified date is acceptable - - if ( ( $post_created > $created ) && ( $post_modified > $modified ) ) { $date_accept = true; } else { $date_accept = false; } - - // Only output if the meta isn't set to exclude it, the limit hasn't been reached, - // there are enough words in the post, the dates are fine and the title isn't blank - - if ( ( $date_accept ) && ( $enough_words ) && ( $draft_title != '' ) && ( strtolower( get_post_meta( $post_id, 'draft_hide', true ) ) != 'yes' ) && ( ( $list_limit == 0 ) or ( $valid_draft <= $list_limit ) ) ) { - - $post_status = $draft_data -> post_status; - $author = $draft_data -> display_name; - $author_url = $draft_data -> user_url; - - if ( $count ) { $post_content = $draft_data -> post_content; } - - // Build line - - if ( $list ) { $this_line = "\t
  • "; } else { $this_line = ''; } - $this_line .= $template; - if ( $list ) { $this_line .= '
  • '; } - - // Replace the icon tag - - $alt_title = __( 'Scheduled', 'simple-draft-list' ); - if ( $post_status === 'future' ) { $icon_url = '' . $alt_title . ''; } else { $icon_url = ''; } - $this_line = str_replace( '%icon%', $icon_url, $this_line ); - $this_line = str_replace( '{{icon}}', $icon_url, $this_line ); - - // Replace the author tag - - $this_line = str_replace( '%author%', $author, $this_line ); - $this_line = str_replace( '{{author}}', $author, $this_line ); - if ( $author_url !== '' ) { $author_link = '' . $author . ''; } else { $author_link = $author; } - $this_line = str_replace( '%author+link%', $author_link, $this_line ); - $this_line = str_replace( '{{author+link}}', $author_link, $this_line ); - - // Replace the draft tag - - if ( $draft_title !== '' ) { $draft = $draft_title; } else { $draft = __( '(no title)', 'simple-draft-list' ); } - if ( $can_edit ) { $draft = '' . $draft . ''; } - $this_line = str_replace( '%draft%', $draft, $this_line ); - $this_line = str_replace( '{{draft}}', $draft, $this_line ); - - // Replace the created date - - $created_date = date( $date_format, strtotime( $post_created ) ); - $this_line = str_replace( '%created%', $created_date, $this_line ); - $this_line = str_replace( '{{created}}', $created_date, $this_line ); - - // Replace the modified date - - $modified_date = date( $date_format, strtotime( $post_modified ) ); - $this_line = str_replace( '%modified%', $modified_date, $this_line ); - $this_line = str_replace( '{{modified}}', $modified_date, $this_line ); - - // Replace the word and character counts - - if ( $count ) { - if ( strpos( $this_line, '%words%' ) !== false ) { $this_line = str_replace( '%words%', number_format( $word_count ), $this_line ); } - if ( strpos( $this_line, '{{words}}' ) !== false ) { $this_line = str_replace( '{{words}}', number_format( $word_count ), $this_line ); } - if ( strpos( $this_line, '%chars%' ) !== false ) { $this_line = str_replace( '%chars%', number_format( strlen( $post_content ) - substr_count( $post_content, ' ' ) ), $this_line ); } - if ( strpos( $this_line, '{{chars}}' ) !== false ) { $this_line = str_replace( '{{chars}}', number_format( strlen( $post_content ) - substr_count( $post_content, ' ' ) ), $this_line ); } - if ( strpos( $this_line, '%chars+space%' ) !== false ) { $this_line = str_replace( '%chars+space%', number_format( strlen( $post_content ) ), $this_line ); } - if ( strpos( $this_line, '{{chars+space}}' ) !== false ) { $this_line = str_replace( '{{chars+space}}', number_format( strlen( $post_content ) ), $this_line ); } - } - - // Replace the category - - $category = get_the_category( $post_id ); - $category = $category[ 0 ] -> cat_name; - if ( $category === 'Uncategorized' ) { $category = ''; } - $this_line = str_replace( '%category%', $category, $this_line ); - $this_line = str_replace( '{{category}}', $category, $this_line ); - - // Replace the categories - - $category_list = ''; - foreach( ( get_the_category( $post_id ) ) as $category ) { - if ( $category -> cat_name !== 'Uncategorized' ) { $category_list .= ', ' . $category -> cat_name; } - } - if ( $category_list !== '' ) { $category_list = substr( $category_list, 2 ); } - - $this_line = str_replace( '%categories%', $category_list, $this_line ); - $this_line = str_replace( '{{categories}}', $category_list, $this_line ); - - // Now add the current line to the overall code output - - $code .= $this_line . "\n"; - $valid_draft++; - } - } - - if ( $list ) { $code .= ''; } - } - - } - - $code .= "\n\n"; - - // Saving resulting output to cache - - if ( ( $cache_key !== 'no' ) && ( !$error ) ) { set_transient( $cache_key, $code, HOUR_IN_SECONDS * $cache_time ); } - } - - return $code; -} diff --git a/includes/generate-widget.php b/includes/generate-widget.php deleted file mode 100755 index e514798..0000000 --- a/includes/generate-widget.php +++ /dev/null @@ -1,245 +0,0 @@ - __( 'Display a list of draft posts and/or pages.', 'simple-draft-list' ), - 'class' => 'dl-widget', - 'customize_selective_refresh' => true, - ) - ); - } - - /** - * Display widget - * - * Display the widget - * - * @since 2.0 - * - * @uses adl_generate_code Generate the required code - * - * @param string $args Arguments - * @param string $instance Instance - */ - - function widget( $args, $instance ) { - - extract( $args, EXTR_SKIP ); - - // Output the header - echo $before_widget; - - // Extract title for heading - $title = $instance[ 'title' ]; - - // Output title, if one exists - if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } - - // Generate the video and output it - echo adl_generate_code ( $instance[ 'limit' ], - $instance[ 'type' ], - $instance[ 'order' ], - $instance[ 'scheduled' ], - $instance[ 'folder' ], - $instance[ 'date' ], - $instance[ 'created' ], - $instance[ 'modified' ], - $instance[ 'cache' ], - $instance[ 'template' ], - $instance[ 'words' ], - $instance[ 'pending' ] - ); - - // Output the trailer - echo $after_widget; - } - - /** - * Widget update/save function - * - * Update and save widget - * - * @since 2.0 - * - * @param string $new_instance New instance - * @param string $old_instance Old instance - * @return string Instance - */ - - function update( $new_instance, $old_instance ) { - - $instance = $old_instance; - $instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] ); - $instance[ 'limit' ] = $new_instance[ 'limit' ]; - $instance[ 'type' ] = $new_instance[ 'type' ]; - $instance[ 'order' ] = $new_instance[ 'order' ]; - $instance[ 'scheduled' ] = $new_instance[ 'scheduled' ]; - $instance[ 'folder' ] = $new_instance[ 'folder' ]; - $instance[ 'cache' ] = $new_instance[ 'cache' ]; - $instance[ 'date' ] = $new_instance[ 'date' ]; - $instance[ 'created' ] = $new_instance[ 'created' ]; - $instance[ 'modified' ] = $new_instance[ 'modified' ]; - $instance[ 'template' ] = $new_instance[ 'template' ]; - $instance[ 'words' ] = $new_instance[ 'words' ]; - $instance[ 'pending' ] = $new_instance[ 'pending' ]; - - return $instance; - } - - /** - * Widget Admin control form - * - * Define admin file - * - * @since 2.0 - * - * @param string $instance Instance - */ - - function form( $instance ) { - - // Set default options - - $default = array( 'title' => __( 'Coming Soon', 'simple-draft-list' ), 'limit' => '0', 'type' => '', 'order' => '', 'scheduled' => '', 'folder' => '', 'cache' => '0.5', 'date' => 'F j, Y, g:i a', 'created' => '', 'modified' => '', 'template' => '{{ol}}{{draft}} {{icon}}' ); - $instance = wp_parse_args( ( array ) $instance, $default ); - - // Title field - - $field_id = $this -> get_field_id( 'title' ); - $field_name = $this -> get_field_name( 'title' ); - echo "\r\n" . '

    '; - - // Template field - - $field_id = $this -> get_field_id( 'template' ); - $field_name = $this -> get_field_name( 'template' ); - echo "\r\n" . '

    '; - - // Limit field - - $field_id = $this -> get_field_id( 'limit' ); - $field_name = $this -> get_field_name( 'limit' ); - echo "\r\n" . '

    '; - - // Minimum number of words - - $field_id = $this -> get_field_id( 'words' ); - $field_name = $this -> get_field_name( 'words' ); - echo "\r\n" . '

    '; - - // Draft types field - - $field_id = $this -> get_field_id( 'type' ); - $field_name = $this -> get_field_name( 'type' ); - echo "\r\n" . '

    '; - - // Order field - - $field_id = $this -> get_field_id( 'order' ); - $field_name = $this -> get_field_name( 'order' ); - echo "\r\n" . '

    '; - - // Scheduled field - - $field_id = $this -> get_field_id( 'scheduled' ); - $field_name = $this -> get_field_name( 'scheduled' ); - echo "\r\n" . '

    '; - - // Show pending posts - - $field_id = $this -> get_field_id( 'pending' ); - $field_name = $this -> get_field_name( 'pending' ); - echo "\r\n" . '

    '; - - // Folder field - - $field_id = $this -> get_field_id( 'folder' ); - $field_name = $this -> get_field_name( 'folder' ); - echo "\r\n" . '

    '; - - // Date format field - - $field_id = $this -> get_field_id( 'date' ); - $field_name = $this -> get_field_name( 'date' ); - echo "\r\n" . '

    '; - - // Created field - - $field_id = $this -> get_field_id( 'created' ); - $field_name = $this -> get_field_name( 'created' ); - echo "\r\n" . '

    '; - - // Modified field - - $field_id = $this -> get_field_id( 'modified' ); - $field_name = $this -> get_field_name( 'modified' ); - echo "\r\n" . '

    '; - - echo '

    * ' . __( 'leave blank to show posts across all time periods', 'simple-draft-list' ) . '

    '; - - // Cache field - - $field_id = $this -> get_field_id( 'cache' ); - $field_name = $this -> get_field_name( 'cache' ); - echo "\r\n" . '

    hours

    '; - } -} - -/** -* Register Widget -* -* Register widget when loading the WP core -* -* @since 2.0 -*/ - -function adl_register_widgets() { - register_widget( 'DraftListWidget' ); -} - -add_action( 'widgets_init', 'adl_register_widgets' ); diff --git a/includes/meta-box.php b/includes/meta-box.php deleted file mode 100755 index a3590bd..0000000 --- a/includes/meta-box.php +++ /dev/null @@ -1,104 +0,0 @@ -' . __( 'Hide from Draft List?', 'simple-draft-list' ) . '  '; - echo 'ID, 'draft_hide', true ) ) === 'yes' ) { echo ' checked="checked"'; } - echo ' />'; - -} - -/** -* Save meta data -* -* Save the entered meta data -* -* @since 2.0 -* -* @param $post_id string Post ID -*/ - -function adl_save_postdata( $post_id ) { - - // If this is an auto save routine and the form has not been submitted then - // don't do anything - - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } - - // Verify this came from the correct meta box and with proper authorization - - if ( isset( $_POST[ 'artiss_draft_list_noncename' ] ) ) { // Input var okay. - if ( !wp_verify_nonce( sanitize_text_field( $_POST[ 'artiss_draft_list_noncename' ] ), plugin_basename( __FILE__ ) ) ) { return; } // Input var okay. - } - - // Check permissions - - if ( isset( $_POST[ 'post_hide' ] ) ) { // Input var okay. - if ( sanitize_text_field( $_POST[ 'post_type' ] ) === 'page' ) { // Input var okay. - if ( !current_user_can( 'edit_page', $post_id ) ) { return; } - } else { - if ( !current_user_can( 'edit_post', $post_id ) ) { return; } - } - } - - // Save the data - - if ( isset( $_POST[ 'adl_hide' ] ) ) { // Input var okay. - $data = sanitize_text_field( $_POST[ 'adl_hide' ] ); // Input var okay. - } else { - $data = ''; - } - update_post_meta( $post_id, 'draft_hide', $data ); - - // Whenever a post is saved, delete any cached draft list - - global $wpdb; - $wpdb -> query( "DELETE FROM $wpdb->options WHERE option_name LIKE '%transient_adl_%'" ); - -} - -add_action( 'save_post', 'adl_save_postdata' ); diff --git a/includes/shared-functions.php b/includes/shared-functions.php deleted file mode 100755 index 59ce403..0000000 --- a/includes/shared-functions.php +++ /dev/null @@ -1,79 +0,0 @@ -' . $plugin_name . ': ' . __( $error ) . "

    \n"; - if ( $echo ) { - echo $output; - return true; - } else { - return $output; - } -} diff --git a/readme.txt b/readme.txt index b44d53a..7346914 100755 --- a/readme.txt +++ b/readme.txt @@ -1,42 +1,38 @@ === Draft List === Contributors: dartiss Donate link: https://artiss.blog/donate -Tags: draft, list, SEO, sidebar, widget, coming soon +Tags: draft, list, scheduled, SEO, widget Requires at least: 4.6 -Tested up to: 5.3 +Tested up to: 5.5 Requires PHP: 5.3 -Stable tag: 2.4 +Stable tag: 2.5 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html -Manage and promote your drafts and scheduled posts and pages. +📝 WordPress plugin to manage and promote your unpublished content. -== Description == +== Description == + +**If you're upgrading from a previous release of Draft List (i.e. pre version 2.5) please check out the FAQ - a number of changes have been made in this release that you need to be aware of. Also, there's big news for version 3.** Draft List allows you to both manage your draft and scheduled posts more easily but also to promote them by showing them on your site via shortcode or widget - use it to show your visitors what's "coming soon" or as a great SEO tool. How easy is it display a list of draft posts? Here's an example of how you could use it in a post or page... -`[drafts limit=5 type=post order=ma scheduled=no template='{{ul}}{{draft}} {{icon}}']` +`[drafts limit=5 type=post order=ma scheduled=no template='{{ul}}{{[draft}} {{icon}}']` This would display a list of up to 5 draft posts in ascending modified date sequence, with an icon displayed to the right of each if the draft is scheduled. Key features include... - -* Quick links added to admin menu for going straight to your draft posts and pages -* Menu links show the number of drafts you currently have -* Widget/shortcode output is highly configurable - create your own look by using a template, identify scheduled posts with an icon, sequence the results in various ways and even narrow down the results to a specific timeframe + +* Both widgets and shortcodes are available for you to show off your up-coming content +* Output is highly configurable - create your own look by using a template, identify scheduled posts with an icon, sequence the results in various ways and even narrow down the results to a specific timeframe * Click on any of the drafts posts listed to edit them -* Output is cached for streamlined performance * A meta box in the editor screen allows you to omit individual posts from any list outputs -Options coming soon… - -* A dashboard widget to show a summary of draft and scheduled posts and pages -* Quick links to be added to the admin menu for scheduled posts and pages -* Shortcuts to be added to the Admin Bar +Iconography is courtesy of the very talented [Janki Rathod](https://www.linkedin.com/in/jankirathore/) ♥️ -Please visit the [Github page](https://github.com/dartiss/draft-list "Github") for the latest code development, planned enhancements and known issues. +👉 Please visit the [Github page](https://github.com/dartiss/draft-list "Github") for the latest code development, planned enhancements and known issues 👈 == Shortcode Parameters == @@ -47,13 +43,13 @@ The following shortcode parameters are valid... * **folder=** : The scheduled icon will be, by default, the one in the plugin folder named `scheduled.png`. However, use this parameter to specify a folder within your theme that you'd prefer the icon to be fetched from. * **limit=** : The maximum number of draft items to display. The default is 0, which is unlimited. * **order=** : This is the sequence that you'd like to order the results in. It consists of 2 codes - the first is either `t`, `m` or `c` to represent the title, modified date or created date and the second is `a` or `d` for ascending or descending. Therefore `order=td` will display the results in descending title sequence. The default is descending modified date. -* **pending=** : Whether to include pending posts as well. Should be set to `true` or `false`. The default is `false`. -* **scheduled=** : If specified as false then scheduled posts will not display in the list, only drafts. +* **pending=** : True or false, where to include pending posts in the result. By default, pending posts will not be included. +* **scheduled=** : True or false, where to include scheduled posts in the result. By default, scheduled posts will be included. * **template=** : This is the template which formats the output. See the section below on * *Templates** for further information. * **type=** : This allows you to limit the results to either `post` or `page`. The default is both. * **words=** : The minimum number of words that must be present in the draft for it to be included. Defaults to 0. -To restrict the posts/pages to a particular timeframe you can use the following 2 parameters. You simply state, in words, how long ago the posts must be dated for e.g. "2 days", "3 months", etc. +To restrict the posts to a particular timeframe you can use the following 2 parameters. You simply state, in words, how long ago the posts must be dated for e.g. "2 days", "3 months", etc. * **created=** : his reflects how long ago the post/page must have been created for it to be listed. For example `6 months` would only list drafts that were created in the last 6 months. * **modified=** : This reflects how long ago the post/page must have been modified last for it to be listed. For example `6 months` would only list drafts that have been modified in the last 6 months. @@ -65,12 +61,12 @@ The template parameter allows you to format the output by allowing you to specif * **{{ul}}** - Specifies this is an un-ordered list (i.e. bullet point output). This MUST be specified at the beginning of the template if it is to be used. * **{{ol}}** - Specifies this is an ordered list (i.e. number output). This MUST be specified at the beginning of the template if it is to be used. * **{{icon}}** - This is the icon that indicates a scheduled post. -* **{{draft}}** - This is the draft post details. This is the only **REQUIRED** tag. +* **{{draft}}** - This is the post detail and is the only **REQUIRED** tag. * **{{author}}** - This is the name of the post author. * **{{author+link}}** - This is the name of the post author with, where available, a link to their URL. * **{{words}}** - The number of words in the draft post. -* **{{chars}}** - The number of characters (exc. spaces) in the draft post. -* **{{chars+space}}** - The number of characters (inc. spaces) in the draft post. +* **{{chars}}** - The number of characters (exc. spaces) in the post. +* **{{chars+space}}** - The number of characters (inc. spaces) in the post. * **{{created}}** - The date/time the post was created. * **{{modified}}** - The date/time the post was last modified. * **{{category}}** - Shows the first category assigned to the post. @@ -82,7 +78,7 @@ If {{ul}} or {{ol}} are specified then all the appropriate list tags will be add If you wish to omit a page or post from the list then you can do this in 3 ways... -1. By giving the post/page a title beginning with an exclamation mark. You can then remove this before publishing the page/post. +1. By giving the post a title beginning with an exclamation mark. You can then remove this before publishing the post. 2. The post and page editor has a meta box, where you can select to hide the page/post. 3. You can add a custom field to a page/post with a name of 'draft_hide' and a value of 'Yes' @@ -108,15 +104,44 @@ Draft List can be found and installed via the Plugin menu within WordPress admin 2. Activate the plugin through the 'Plugins' menu in WordPress administration. Voila! It's ready to go. + +== Frequently Asked Questions == + += I've upgraded from a version before 2.5 and I hear things have changed. What's happening? = + +From version 2.5, 2 features have been removed... + +1. Caching has gone. This release has had some massive performance improvements which means it was no longer needed. It, more often than not, caused issues and many people have native caching on their site anyway. +2. The draft menus options have been removed. I've moved that functionality off to another plugin named [Draft Links](https://wordpress.org/plugins/draft-links/). If you want the menu links back, please install that. Why have they been removed? For a start, some people were installing this plugin JUST for that functionality, so it made sense for me to separate it. Additionally, the next FAQ answer is part of this too... + += What do I need to know about version 3? = + +Version 3 of this plugin is coming soon and it will be a breaking release. In other words, your existing shortcode will stop working, if you're upgrading from an earlier version - you'll need to make changes to it for it to work again. + +When this plugin first started it was all about drafts. However, that's changed as it's become obvious that what this plugin should be about is any unpublished content - not just drafts. It could be pending or scheduled posts, for example. Basically, it should be so much more. So, version 3 will be. + +It will be renamed and the draft element de-emphasised. This will include renaming the shortcode and various parameters too (hence the breaking element of it). If you have automatic updates switched on for this plugin, I'd recommend turning them off. + +The good news, however, is that the plugin will include a raft of new and powerful features, including the ability to limit unpublished post output to specific categories, amongst other things. == Screenshots == -1. An example list of draft posts -2. Draft post information in the Admin menu +1. An example output of draft posts == Changelog == -[Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning") +I use symantic versioning, with the first release being 1.0. + += 2.5 = +* Enhancement: Total re-write of the post retrieval code +* Enhancement: Brought code up to PHPCS coding standards - hardly a line has been untouched +* Maintenance: Removed the menu changes (links to draft posts) +* Maintenance: Removed Caching +* Maintenance: Rename, concatenation and general shuffle around of the various plugin files +* Maintenance: Updates to the various plugin meta +* Bug: Resolved inconsistencies between `pending` and `scheduled` parameters, where one accepting boolean and yes/no and, well, the other didn't +* Bug: Fixed issue where default values were not being loaded when a widget was being displayed without settings being changed +* Bug: Fixed a bunch of existing bugs, including various widget issues = 2.4 = * Enhancement: New option to include pending posts in lists @@ -233,5 +258,5 @@ Voila! It's ready to go. == Upgrade Notice == -= 2.4 = -* A few assorted improvements, alongside some bug fixes \ No newline at end of file += 2.5 = +* Bugs quashed, some functionality changes and the code is so, so sparkly clean diff --git a/simple-draft-list.php b/simple-draft-list.php index 1850c42..ca974e0 100755 --- a/simple-draft-list.php +++ b/simple-draft-list.php @@ -1,39 +1,37 @@