Skip to content

Commit

Permalink
Merge pull request #34 from dartiss/develop
Browse files Browse the repository at this point in the history
Version 1.1
  • Loading branch information
dartiss authored Nov 23, 2020
2 parents f261d88 + 9150d12 commit ead917c
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 128 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Draft Concluder

Based on [an idea by John Blackbourn](https://twitter.com/johnbillion/status/1314494422529331203), this plugin is designed to be a reminder to those who leave draft posts unloved. And, yes, all of John's ideas are here, with more to boot.
<img src="https://ps.w.org/draft-concluder/assets/icon-128x128.png" align="left">Based on [an idea by John Blackbourn](https://twitter.com/johnbillion/status/1314494422529331203), this plugin is designed to be a reminder to those who leave draft posts unloved. And, yes, all of John's ideas are here, with more to boot.

* Send emails out on a daily or weekly schedule and at a time that you'd prefer
* Look for draft pages as well as posts, if you like. Or just pages, if that's what you want. We won't judge
Expand All @@ -14,6 +14,6 @@ Oh, and, naturally, the code passes [WordPress](https://github.com/WordPress/Wor

Always forgetting to complete posts or you have other people on your site who do? This is the draft botherer that you need!

I'd like to thank [Caleb Burks](https://calebburks.com/) for the feedback he provided. Also, the iconography is courtesy of the very talented [Janki Rathod](https://www.linkedin.com/in/jankirathore/) ♥️
I'd like to thank [Caleb Burks](https://calebburks.com/) for the feedback he provided. Also, the iconography is courtesy of the very talented [Janki Rathod](https://www.fiverr.com/jankirathore) ♥️

<p align="right"><a href="https://wordpress.org/plugins/draft-concluder/"><img src="https://img.shields.io/wordpress/plugin/dt/draft-concluder?label=wp.org%20downloads&style=for-the-badge">&nbsp;<img src="https://img.shields.io/wordpress/plugin/stars/draft-concluder?color=orange&style=for-the-badge"></a></p>
33 changes: 24 additions & 9 deletions draft-concluder.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
<?php
/**
Plugin Name: Draft Concluder
Plugin URI: https://wordpress.org/plugins/draft-concluder/
Description: 📝 Email users that have outstanding drafts.
Version: 1.0.1
Author: David Artiss
Author URI: https://artiss.blog
Text Domain: draft-concluder
@package draft-concluder
* Draft Concluder
*
* @package draft-concluder
* @author David Artiss
* @license GPL-2.0-or-later
*
* Plugin Name: Draft Concluder
* Plugin URI: https://wordpress.org/plugins/draft-concluder/
* Description: 📝 Email users that have outstanding drafts.
* Version: 1.1
* Requires at least: 4.6
* Requires PHP: 5.3
* Author: David Artiss
* Author URI: https://artiss.blog
* Text Domain: draft-concluder
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume
* that you can use any other version of the GPL.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

// Require the various code components - all held within the inc folder.
Expand Down
13 changes: 7 additions & 6 deletions inc/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
function draft_concluder_now_shortcode( $paras, $content ) {

draft_concluder_process_posts( true );
return draft_concluder_process_posts( true );

}

Expand All @@ -35,10 +35,10 @@ function draft_concluder_now_shortcode( $paras, $content ) {
function draft_concluder_last_run_shortcode( $paras, $content ) {

$output = get_option( 'draft_concluder_output' );
$debug = '';

echo '<p>';
if ( ! $output ) {
echo esc_html( __( 'Draft Concluder has not yet run.', 'draft_concluder' ) );
$debug .= esc_html( __( 'Draft Concluder has not yet run.', 'draft_concluder' ) );
} else {
$timestamp = date( 'l jS \of F Y h:i:s A', $output['timestamp'] );
if ( 0 == $output['errors'] ) {
Expand All @@ -48,16 +48,17 @@ function draft_concluder_last_run_shortcode( $paras, $content ) {
/* translators: %1$s: timestamp %2$s: number of errors */
$text = sprintf( __( 'Draft Concluder last ran at %1$s, with %2$s errors.', 'draft_concluder' ), esc_html( $timestamp ), esc_html( $output['errors'] ) );
}
echo esc_html( $text ) . '<br/>';
echo wp_kses(
$debug .= esc_html( $text ) . '<br/>';
$debug .= wp_kses(
$output['emails'],
array(
'br' => array(),
'p' => array(),
)
);
}
echo '</p>';

return $debug;
}

add_shortcode( 'dc_last_run', 'draft_concluder_last_run_shortcode' );
17 changes: 12 additions & 5 deletions inc/process-drafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,24 @@ function draft_concluder_process_posts( $debug = false ) {
}
}

// If the modified date is different to the creation date, then we'll output it.
// In which case, we'll build an appropriate end-of-sentence.
$modified = '';
if ( $post->post_date != $post->post_modified ) {
/* translators: %1$s: the date the post was last modified */
$modified = sprintf( __( ' and last edited on %1$s', 'draft_concluder' ), esc_html( substr( $post->post_modified, 0, strlen( $post->post_modified ) - 3 ) ) );
}

if ( $include_draft ) {

// Build a list of drafts that require the user's attention.

$draft_count ++;

/* translators: Do not translate COUNT,TITLE, LINK, CREATED or MODIFIED : those are placeholders. */
$message .= __(
'###COUNT###. ###TITLE### - ###LINK###
This was created on ###CREATED### and last edited on ###MODIFIED###.
This was created on ###CREATED######MODIFIED###.
',
'draft_concluder'
);
Expand All @@ -117,15 +125,14 @@ function draft_concluder_process_posts( $debug = false ) {
esc_html( $post->post_title ),
esc_html( get_admin_url() . 'post.php?post=' . $post->ID . '&action=edit' ),
esc_html( substr( $post->post_date, 0, strlen( $post->post_date ) - 3 ) ),
esc_html( substr( $post->post_modified, 0, strlen( $post->post_modified ) - 3 ) ),
$modified,
),
$message
);
}
}

// Add a header to the email content. A different message is used dependant on whether there is 1 or more drafts.

if ( 0 < $draft_count ) {

if ( 1 == $draft_count ) {
Expand Down Expand Up @@ -180,7 +187,7 @@ function draft_concluder_process_posts( $debug = false ) {
// If debugging, output to screen - otherwise, email the results.

if ( $debug ) {
echo wp_kses(
return wp_kses(
$display_out,
array(
'br' => array(),
Expand Down
161 changes: 69 additions & 92 deletions inc/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ function draft_concluder_section_callback() {

echo esc_html( __( 'These settings allow you to control when the emails are generated and what they should report on.', 'draft-concluder' ) );

// Show the current status of the event run.
echo '<br/><br/>';
echo wp_kses( '<strong>' . __( 'Status: ', 'draft_concluder' ) . '</strong>', array( 'strong' => array() ) );
if ( ! $output ) {
echo esc_html( __( 'Draft Concluder has not yet run.', 'draft_concluder' ) );
} else {
$timestamp = date( 'l jS \of F Y @ h:i:s A', $output['timestamp'] );
$timestamp = date( 'l jS \o\f F Y \a\t g:i A', $output['timestamp'] );
if ( 0 == $output['errors'] ) {
/* translators: %1$s: timestamp */
$text = sprintf( __( 'Draft Concluder last ran at %1$s, successfully.', 'draft_concluder' ), $timestamp );
Expand All @@ -66,6 +67,13 @@ function draft_concluder_section_callback() {
}
}

// If an event has been scheduled, output the next run time.
if ( false !== wp_next_scheduled( 'draft_concluder_mailer' ) ) {
$next_run = date( 'l jS \o\f F Y \a\t g:i A', wp_next_scheduled( 'draft_concluder_mailer' ) );
/* translators: %1$s: timestamp */
$text .= '&nbsp;' . sprintf( __( 'It is next due to run on %1$s.', 'draft_concluder' ), $next_run );
}

echo esc_html( $text ) . '<br/>';
}

Expand All @@ -77,40 +85,20 @@ function draft_concluder_section_callback() {
function draft_concluder_when_callback() {

$option = get_option( 'draft_concluder_when' );

echo '<select name="draft_concluder_when"><option ';
if ( 'Daily' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Daily">Daily</option><option ';
if ( 'Monday' == $option || ! $option ) {
echo 'selected="selected" ';
}
echo 'value="Monday">Monday</option><option ';
if ( 'Tuesday' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Tuesday">Tuesday</option><option ';
if ( 'Wednesday' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Wednesday">Wednesday</option><option ';
if ( 'Thursday' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Thursday">Thursday</option><option ';
if ( 'Friday' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Friday">Friday</option><option ';
if ( 'Saturday' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Saturday">Saturday</option><option ';
if ( 'Sunday' == $option ) {
echo 'selected="selected" ';
}
echo 'value="Sunday">Sunday</option></select>';
if ( ! $option ) {
$option = 'Monday';
}

echo '<select name="draft_concluder_when">';
echo '<option ' . selected( 'Daily', $option, false ) . ' value="Daily">' . esc_html__( 'Daily', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Monday', $option, false ) . ' value="Monday">' . esc_html__( 'Monday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Tuesday', $option, false ) . ' value="Tuesday">' . esc_html__( 'Tuesday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Wednesday', $option, false ) . ' value="Wednesday">' . esc_html__( 'Wednesday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Thursday', $option, false ) . ' value="Thursday">' . esc_html__( 'Thursday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Friday', $option, false ) . ' value="Friday">' . esc_html__( 'Friday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Saturday', $option, false ) . ' value="Saturday">' . esc_html__( 'Saturday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'Sunday', $option, false ) . ' value="Sunday">' . esc_html__( 'Sunday', 'draft_concluder' ) . '</option>';
echo '</select>';
}

/**
Expand All @@ -121,40 +109,36 @@ function draft_concluder_when_callback() {
function draft_concluder_time_callback() {

$option = get_option( 'draft_concluder_time' );

echo '<select name="draft_concluder_time"><option ';
if ( '1am' == $option || ! $option ) {
echo 'selected="selected" ';
}
echo 'value="1am">1am</option><option ';
if ( '4am' == $option ) {
echo 'selected="selected" ';
}
echo 'value="4am">4am</option><option ';
if ( '7am' == $option ) {
echo 'selected="selected" ';
}
echo 'value="7am">7am</option><option ';
if ( '11am' == $option ) {
echo 'selected="selected" ';
}
echo 'value="11am">11am</option><option ';
if ( '1pm' == $option ) {
echo 'selected="selected" ';
}
echo 'value="1pm">1pm</option><option ';
if ( '4pm' == $option ) {
echo 'selected="selected" ';
}
echo 'value="4pm">4pm</option><option ';
if ( '7pm' == $option ) {
echo 'selected="selected" ';
}
echo 'value="7pm">7pm</option><option ';
if ( '10pm' == $option ) {
echo 'selected="selected" ';
}
echo 'value="10pm">10pm</option></select>';
if ( ! $option ) {
$option = '1am';
}

echo '<select name="draft_concluder_time">';
echo '<option ' . selected( '12am', $option, false ) . ' value="12am">' . esc_html__( 'Midnight', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '1am', $option, false ) . ' value="1am">' . esc_html__( '1am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '2am', $option, false ) . ' value="2am">' . esc_html__( '2am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '3am', $option, false ) . ' value="3am">' . esc_html__( '3am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '4am', $option, false ) . ' value="4am">' . esc_html__( '4am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '5am', $option, false ) . ' value="5am">' . esc_html__( '5am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '6am', $option, false ) . ' value="6am">' . esc_html__( '6am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '7am', $option, false ) . ' value="7am">' . esc_html__( '7am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '8am', $option, false ) . ' value="8am">' . esc_html__( '8am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '9am', $option, false ) . ' value="9am">' . esc_html__( '9am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '10am', $option, false ) . ' value="10am">' . esc_html__( '10am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '11am', $option, false ) . ' value="11am">' . esc_html__( '11am', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '12pm', $option, false ) . ' value="12pm">' . esc_html__( 'Midday', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '1pm', $option, false ) . ' value="1pm">' . esc_html__( '1pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '2pm', $option, false ) . ' value="2pm">' . esc_html__( '2pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '3pm', $option, false ) . ' value="3pm">' . esc_html__( '3pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '4pm', $option, false ) . ' value="4pm">' . esc_html__( '4pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '5pm', $option, false ) . ' value="5pm">' . esc_html__( '5pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '6pm', $option, false ) . ' value="6pm">' . esc_html__( '6pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '7pm', $option, false ) . ' value="7pm">' . esc_html__( '7pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '8pm', $option, false ) . ' value="8pm">' . esc_html__( '8pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '9pm', $option, false ) . ' value="9pm">' . esc_html__( '9pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '10pm', $option, false ) . ' value="10pm">' . esc_html__( '10pm', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( '11pm', $option, false ) . ' value="11pm">' . esc_html__( '11pm', 'draft_concluder' ) . '</option>';
echo '</select>';
}

/**
Expand All @@ -165,20 +149,15 @@ function draft_concluder_time_callback() {
function draft_concluder_what_callback() {

$option = get_option( 'draft_concluder_what' );

echo '<select name="draft_concluder_what"><option ';
if ( 'post' == $option ) {
echo 'selected="selected" ';
}
echo 'value="post">Posts</option><option ';
if ( 'page' == $option ) {
echo 'selected="selected" ';
}
echo 'value="page">Pages</option><option ';
if ( 'postpage' == $option || ! $option ) {
echo 'selected="selected" ';
if ( ! $option ) {
$option = 'postpage';
}
echo 'value="postpage">Posts & Pages</option></select>';

echo '<select name="draft_concluder_what">';
echo '<option ' . selected( 'post', $option, false ) . ' value="post">' . esc_html__( 'Posts', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'page', $option, false ) . ' value="page">' . esc_html__( 'Pages', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'postpage', $option, false ) . ' value="post">' . esc_html__( 'Posts & Pages', 'draft_concluder' ) . '</option>';
echo '</select>';
}

/**
Expand All @@ -193,7 +172,7 @@ function draft_concluder_age_callback() {
$option = 0;
}

echo '<input name="draft_concluder_age" size="3" maxlength="3" type="text" value="' . esc_html( $option ) . '" />&nbsp;days';
echo '<input name="draft_concluder_age" size="3" maxlength="3" type="text" value="' . esc_html( $option ) . '" />&nbsp;' . esc_html__( 'days', 'draft_concluder' );
}

/**
Expand All @@ -204,14 +183,12 @@ function draft_concluder_age_callback() {
function draft_concluder_since_callback() {

$option = get_option( 'draft_concluder_since' );

echo '<select name="draft_concluder_since"><option ';
if ( 'created' == $option || ! $option ) {
echo 'selected="selected" ';
}
echo 'value="created">Since they were created</option><option ';
if ( 'modified' == $option ) {
echo 'selected="selected" ';
if ( ! $option ) {
$option = 'created';
}
echo 'value="modified">Since they were last updated</option></select>';

echo '<select name="draft_concluder_since">';
echo '<option ' . selected( 'created', $option, false ) . ' value="created">' . esc_html__( 'Since they were created', 'draft_concluder' ) . '</option>';
echo '<option ' . selected( 'modified', $option, false ) . ' value="modified">' . esc_html__( 'Since they were last updated', 'draft_concluder' ) . '</option>';
echo '</select>';
}
Loading

0 comments on commit ead917c

Please sign in to comment.