From 7813e84edbdf5e8345b013ddc5e2d509a704d9ba Mon Sep 17 00:00:00 2001 From: David Artiss Date: Fri, 10 Nov 2017 14:58:57 +0000 Subject: [PATCH] Initial release --- images/scheduled.png | Bin 0 -> 369 bytes includes/admin-config.php | 77 ++++++++ includes/generate-code.php | 335 ++++++++++++++++++++++++++++++++++ includes/generate-widget.php | 222 ++++++++++++++++++++++ includes/meta-box.php | 105 +++++++++++ includes/shared-functions.php | 80 ++++++++ readme.txt | 229 +++++++++++++++++++++++ simple-draft-list.php | 42 +++++ 8 files changed, 1090 insertions(+) create mode 100755 images/scheduled.png create mode 100755 includes/admin-config.php create mode 100755 includes/generate-code.php create mode 100755 includes/generate-widget.php create mode 100755 includes/meta-box.php create mode 100755 includes/shared-functions.php create mode 100755 readme.txt create mode 100755 simple-draft-list.php diff --git a/images/scheduled.png b/images/scheduled.png new file mode 100755 index 0000000000000000000000000000000000000000..d4719b3189033399d545b0843ce4b3c27dc7c975 GIT binary patch literal 369 zcmV-%0gnEOP)s^+~6;%MRIj z&F@DT8!H0E7Btg2QCx4@Mx%Wq4z=3|d=vBnqI(?@%Sd#s)9<0#I+gezHM5Z12Lv2X zkXUm*Ko#f#)F7Er5sh3s#Q{ipW#68J%Abh3LXty#e_ggWgX8jPF4cfvE& z9s&~QEINOoZMCOCnsyVxLFjs|tp5`#X8@t4NWnRCbeu*Sq-wEHe9m&t02Ct>Tne2I zd45Ck%|Yes3pL3yX!Hqz;yQgbl7dU&2M-1N5S(AZiSRt6nF7B*;tc!)*LYqH+*3!< P00000NkvXXu0mjfFhiC? literal 0 HcmV?d00001 diff --git a/includes/admin-config.php b/includes/admin-config.php new file mode 100755 index 0000000..90a42fb --- /dev/null +++ b/includes/admin-config.php @@ -0,0 +1,77 @@ +' . __( 'Support', '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', '', __( 'Your 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', '', __( 'Your 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' ); +?> \ No newline at end of file diff --git a/includes/generate-code.php b/includes/generate-code.php new file mode 100755 index 0000000..8100ab9 --- /dev/null +++ b/includes/generate-code.php @@ -0,0 +1,335 @@ + '', 'type' => '', 'order' => '', 'scheduled' => '', 'icon' => '', 'folder' => '', 'author' => '', 'template' => '', 'date' => '', 'created' => '', 'modified' => '', 'cache' => '' ), $paras ) ); + + if ( $template == '' ) { $template = adl_convert_to_template( $icon, $author); } + + return adl_generate_code( $limit, $type, $order, $scheduled, $folder, $date, $created, $modified, $cache, $template ); + +} +add_shortcode( 'drafts', 'adl_draft_list_shortcode' ); + +/** +* Draft List Function +* +* Function to output draft list +* +* @since 2.0 +* +* @param $template string Template +* @param $paras string Parameters +*/ + +function draft_list( $template, $parameters ) { + + $limit = adl_get_parameters( $parameters, 'limit' ); + $type = adl_get_parameters( $parameters, 'type' ); + $order = adl_get_parameters( $parameters, 'order' ); + $scheduled = adl_get_parameters( $parameters, 'scheduled' ); + $folder = adl_get_parameters( $parameters, 'folder' ); + $date = adl_get_parameters( $parameters, 'date' ); + $created = adl_get_parameters( $parameters, 'created' ); + $modified = adl_get_parameters( $parameters, 'modified' ); + $cache = adl_get_parameters( $parameters, 'cache' ); + + echo adl_generate_code( $limit, $type, $order, $scheduled, $folder, $date, $created, $modified, $cache, $template ); + + return; +} + +/** +* 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 = '' ) { + + // 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 ); + $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 ( $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 ( ( $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 ) { $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')"; + } + if ( $scheduled != 'no' ) { $status = " OR post_status = 'future'";} else { $status = ''; } + + // 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 ( ( strpos( $template, '%words%' ) !== false ) or ( strpos( $template, '%chars%' ) !== 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 ); + } + + $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; + + // 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, + // the dates are fine and the title isn't blank + + if ( ( $date_accept ) && ( $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 ); + + // 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( str_word_count( $post_content, 0 ) ), $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 ( $category == 'Uncategorized' ) { $category = ''; } + $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 ); + + // 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, 3600 * $cache_time ); } + } + + return $code; +} +?> \ No newline at end of file diff --git a/includes/generate-widget.php b/includes/generate-widget.php new file mode 100755 index 0000000..afdb58d --- /dev/null +++ b/includes/generate-widget.php @@ -0,0 +1,222 @@ + __( 'Display a list of draft posts and/or pages.', 'simple-draft-list' ), 'class' => 'my-widget-class' ) + ); + } + + /** + * 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' ] ); + + // 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' ]; + + 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" . '

    '; + + // 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" . '

    '; + + // 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' ); +?> \ No newline at end of file diff --git a/includes/meta-box.php b/includes/meta-box.php new file mode 100755 index 0000000..ffe57f0 --- /dev/null +++ b/includes/meta-box.php @@ -0,0 +1,105 @@ +' . __( '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' ] ) ) { + if ( !wp_verify_nonce( $_POST[ 'artiss_draft_list_noncename' ], plugin_basename( __FILE__ ) ) ) { return; } + } + + // Check permissions + + if ( isset( $_POST[ 'post_hide' ] ) ) { + if ( $_POST[ 'post_type' ] == 'page' ) { + 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' ] ) ) { + $data = sanitize_text_field( $_POST[ 'adl_hide' ] ); + } 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' ); +?> \ No newline at end of file diff --git a/includes/shared-functions.php b/includes/shared-functions.php new file mode 100755 index 0000000..0489d83 --- /dev/null +++ b/includes/shared-functions.php @@ -0,0 +1,80 @@ +' . $plugin_name . ': ' . __( $error ) . "

    \n"; + if ( $echo ) { + echo $output; + return true; + } else { + return $output; + } +} +?> \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100755 index 0000000..e9b7374 --- /dev/null +++ b/readme.txt @@ -0,0 +1,229 @@ +=== Draft List === +Contributors: dartiss +Tags: draft, list, SEO, sidebar, widget, coming soon +Requires at least: 4.6 +Tested up to: 4.8.0 +Stable tag: 2.3.3 +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. + +== Description == + +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%']` + +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 +* 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 + +Technical specification... + +* Licensed under [GPLv2 (or later)](http://wordpress.org/about/gpl/ "GNU General Public License") +* Designed for both single and multi-site installations +* PHP7 compatible +* Fully internationalized, ready for translations. **If you would like to add a translation to this plugin then please head to our [Translating WordPress](https://translate.wordpress.org/projects/wp-plugins/simple-draft-list "Translating WordPress") page** + +For the latest known issue and planned enhancements, please see [my Bug Tracker site](https://artiss.uk/bugtracker/index.php?project=12 "Bug Tracker") site. + +== Shortcode Parameters == + +The following shortcode parameters are valid... + +* **limit=** : The maximum number of draft items to display. The default is 0, which is unlimited. +* **type=** : This allows you to limit the results to either `post` or `page`. The default is both. +* **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. +* **scheduled=** : If specified as `No` then scheduled posts will not display in the list, only drafts. +* **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. +* **cache=** : How long to cache the output for, in hours. Defaults to half an hour. Set to `No` to not cache at all. Whenever you save a post any cache will be cleared to ensure that any lists are updated. +* **template=** : This is the template which formats the output. See the section below on * *Templates** for further information. +* **date=** : The format of any dates output. This uses the PHP date formatting system - [read here](http://uk3.php.net/manual/en/function.date.php "date") for the formatting codes. Defaults to `F j, Y, g:i a`. + +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. + +* **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. +* **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. + +== Templates == + +The template parameter allows you to format the output by allowing you to specify how each line of output will display. A number of tags can be added, and you can mix these with HTML. The available tags are as follows... + +* **%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. +* **%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. +* **%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. +* **%categories%** - Shows all categories assigned to the post, comma separated. + +If %ul% or %ol% are specified then all the appropriate list tags will be added to the output. If neither are used then it's assumed that line output will be controlled by yourself. + +== Omitting Posts/Pages from Results == + +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. +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' + +== Edit Link == + +If the current user can edit the draft item being listed then it will be linked to the appropriate edit page. The user then simply needs to click on the draft item to edit it. + +There are separate permissions for post and page editing, so an editor with just one permission may find that they can only edit some of the draft items. + +Drafts that don't have a title will not be shown on the list UNLESS the current user has edit privileges for the draft - in this case a title of [No Title] will be shown. + +== Using a Widget == + +Sidebar widgets can be easily added. In Administration simply click on the `Widgets` option under the `Appearance` menu. `Draft Posts` will be one of the listed widgets. Drag it to the appropriate sidebar on the right hand side and then choose your options. + +Save the result and that's it! You can use unlimited widgets, so you can add different lists to different sidebars. + +== Installation == + +Draft List can be found and installed via the Plugin menu within WordPress administration (Plugins -> Add New). Alternatively, it can be downloaded from WordPress.org and installed manually... + +1. Upload the entire `simple-draft-list` folder to your `wp-content/plugins/` directory. +2. Activate the plugin through the 'Plugins' menu in WordPress administration. + +Voila! It's ready to go. + +== Screenshots == + +1. An example list of draft posts +2. Draft post information in the Admin menu + +== Changelog == + +[Learn more about my version numbering methodology](https://artiss.blog/2016/09/wordpress-plugin-versioning/ "WordPress Plugin Versioning") + += 2.3.3 = + +* Maintenance: The README has had a re-write and the image assets have been replaced. Shiny! +* Maintenance: Minimum WordPress requirement for this plugin is now 4.6, which means various version checks and language files have now been removed. New! +* Maintenance: My site moved some time ago but links in the plugin and the README were still directed to the old one. Changed! +* Maintenance: The shortcake code is called whether in admin or frontend because, well, it makes no difference. Plum! +* Bug: Corrected spelling mistake. Sad trombone! + += 2.3.2 = +* Maintenance: Updated branding, inc. adding donation links + += 2.3.1 = +* Enhancement: Draft pages shortcuts only appear if the user can edit pages +* Enhancement: Only show the user's drafts if it's different to the total number (otherwise, if a site has only one author, they will get two links when only one is required) + += 2.3 = +* Enhancement: Quick links added to admin menu for any draft posts. Will show links for both all drafts and drafts for the current user +* Maintenance: Updated branding +* Maintenance: Removed unnecessary `-adl` prefix from file names +* Maintenance: Stopped hardcoding the plugin folder name in includes. Naughty boy +* Maintenance: Replaced `wp_plugin_url` with the nicerer `plugins_url` +* Maintenance: Replaced the deprecated `attribute_escape` with `esc_attr` in the widget code +* Maintenance: Merged the widget code so it's all in one handy file +* Maintenance: Sanitized the data being sloshed about by the meta box option +* Maintenance: Updated the clock icon to a material design version + += 2.2.6 = +* Maintenance: Added a domain path +* Maintenance: Removed deprecated functionality +* Bug: Fixed the categories tag +* Bug: Solved a PHP bug + += 2.2.5 = +* Maintenance: Added a text domain + += 2.2.4 = +* Bug: I've just noticed that if you use the editor box to hide the post from draft list you can't switch it back off again. Untick the box, save and it's ticked again. Doh. Why did nobody notice this before? It's now fixed though. + += 2.2.3 = +* Maintenance: Resolved widget issues with version 4.3 of WordPress + += 2.2.2 = +* Maintenance: Updated support forum link + += 2.2.1 = +* Bug: Removed some debug output + += 2.2 = +* Maintenance: Updated clock icon +* Enhancement: Added `category` and `categories` template tags + += 2.1 = +* Maintenance: Moved default scheduled icon to its own folder +* Enhancement: Added internationalization + += 2.0.2 = +* Maintenance: Removed dashboard widget + += 2.0.1 = +* Bug: Fix caching problem that prevents edit links from working correctly + += 2.0 = +* Maintenance: Renamed plugin and brought program coding standards up-to-date +* Enhancement: Added new template system, allowing better control over output +* Enhancement: Option to display modified and/or created date +* Enhancement: Option to display word and/or character count +* Enhancement: Draft posts/pages with no title are no longer displayed +* Enhancement: Can now sort output by date created as well as the date modified +* Enhancement: Meta box added to editor to allow post/page to be excluded from list +* Enhancement: Output is now cached (and cache times are adjustable) +* Enhancement: User can now limit time period over which drafts will be displayed +* Enhancement: Added validation of the passed parameters +* Enhancement: New widget option added +* Enhancement: Added improved clock image +* Bug: Alternative icon folder option now works + += 1.6 = +* Enhancement: Draft titles now have links to their edit page if the current user is allowed to edit them + += 1.5 = +* Maintenance: Code tidy +* Enhancement: Added option to show post/page author +* Enhancement: Added version details to code output +* Enhancement: Added shortcode option + += 1.4 = +* Enhancement: Added icon for scheduled posts (which can be modified and switched off, if required) + += 1.3 = +* Enhancement: Date order now displays according to date of last modification + += 1.2 = +* Enhancement: Now displays scheduled posts as well +* Enhancement: Added new parameter to suppress scheduled posts, if required +* Bug: Fixed bug in limit default + += 1.1 = +* Maintenance: With the release of WP 3.0 different post types are possible and these can get mixed in with the results (e.g. menu items, etc). Changed the code to restrict output to pages and posts only + += 1.0 = +* Initial release + +== Upgrade Notice == + += 2.3.3 = +* A number of maintenance updates \ No newline at end of file diff --git a/simple-draft-list.php b/simple-draft-list.php new file mode 100755 index 0000000..d93ffdd --- /dev/null +++ b/simple-draft-list.php @@ -0,0 +1,42 @@ + \ No newline at end of file