Skip to content

Commit

Permalink
Merge pull request #8 from OSTraining/development
Browse files Browse the repository at this point in the history
Hotfixes for the notifications
  • Loading branch information
Anderson Grüdtner Martins authored Aug 31, 2017
2 parents a025ec5 + 73679a7 commit eb04bfa
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 39 deletions.
4 changes: 4 additions & 0 deletions src/common/css/publishpress-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ Status color box */
.pp-status-color + strong {
margin-left: 5px;
}

.psppca_field_warning {
font-style: italic;
}
2 changes: 1 addition & 1 deletion src/includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
);

// Define contants
define( 'PUBLISHPRESS_VERSION', '1.7.1' );
define( 'PUBLISHPRESS_VERSION', '1.7.2' );
define( 'PUBLISHPRESS_ROOT', dirname( __FILE__ ) );
define( 'PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_ROOT . '/' . basename( __FILE__ ) );
define( 'PUBLISHPRESS_URL', plugins_url( '/', __FILE__ ) );
Expand Down
48 changes: 47 additions & 1 deletion src/libraries/Notifications/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function init() {
add_action( 'load-edit.php', [ $this, 'add_load_edit_hooks' ] );

add_filter( 'post_updated_messages', [ $this, 'filter_post_updated_messages' ] );
add_filter( 'bulk_post_updated_messages', [ $this, 'filter_bulk_post_updated_messages' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -185,15 +186,60 @@ protected function print_column_receivers( $post_id ) {
}
}

/**
* Customize the post messages for the notification workflows when the
* content is saved.
*
* @param string $messages
*
* @return array
*/
public function filter_post_updated_messages( $messages ) {
global $current_screen;

if ( PUBLISHPRESS_NOTIF_POST_TYPE_WORKFLOW !== $current_screen->post_type ) {
return $messages;
}

$messages['post'][1] = __( 'Notification workflow updated.', 'pulishpress' );
$post = get_post();

/* translators: Publish box date format, see https://secure.php.net/date */
$scheduled_date = date_i18n( __( 'M j, Y @ H:i' ), strtotime( $post->post_date ) );

$messages['post'][1] = __( 'Notification workflow updated.', 'pulishpress' );
$messages['post'][4] = __( 'Notification workflow updated.', 'pulishpress' );
$messages['post'][6] = __( 'Notification workflow published.', 'pulishpress' );
$messages['post'][7] = __( 'Notification workflow saved.', 'pulishpress' );
$messages['post'][8] = __( 'Notification workflow submitted.', 'pulishpress' );
$messages['post'][9] = sprintf( __( 'Notification workflow scheduled for: %s.' ), '<strong>' . $scheduled_date . '</strong>' );
$messages['post'][10] = __( 'Notification workflow draft updated.', 'pulishpress' );

return $messages;
}

/**
* Customize the post messages for the notification workflows when the
* content is bulk edited.
*
* @param string $bulk_messages
* @param int $bulk_contents
*
* @return array
*/
public function filter_bulk_post_updated_messages( $bulk_messages, $bulk_counts ) {
global $current_screen;

if ( PUBLISHPRESS_NOTIF_POST_TYPE_WORKFLOW !== $current_screen->post_type ) {
return $bulk_messages;
}

$bulk_messages['post']['updated'] = _n( '%s notification workflow updated.', '%s notification workflows updated.', $bulk_counts['updated'] );
$bulk_messages['post']['locked'] = ( 1 == $bulk_counts['locked'] ) ? __( '1 notification workflow not updated, somebody is editing it.' ) :
_n( '%s notification workflow not updated, somebody is editing it.', '%s notification workflows not updated, somebody is editing them.', $bulk_counts['locked'] );
$bulk_messages['post']['deleted'] = _n( '%s notification workflow permanently deleted.', '%s notification workflows permanently deleted.', $bulk_counts['deleted'] );
$bulk_messages['post']['trashed'] = _n( '%s notification workflow moved to the Trash.', '%s notification workflows moved to the Trash.', $bulk_counts['trashed'] );
$bulk_messages['post']['untrashed'] = _n( '%s notification workflow restored from the Trash.', '%s notification workflows restored from the Trash.', $bulk_counts['untrashed'] );

return $bulk_messages;
}
}
24 changes: 24 additions & 0 deletions src/modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class PP_Calendar extends PP_Module {
*/
const DEFAULT_NUM_WEEKS = 5;

/**
* Name of the transient option to flag the warning for selecting
* at least one post type
*/
const TRANSIENT_SHOW_ONE_POST_TYPE_WARNING = 'show_one_post_type_warning';

/**
* [$module description]
*
Expand Down Expand Up @@ -1642,6 +1648,13 @@ public function register_settings() {
public function settings_post_types_option() {
global $publishpress;
$publishpress->settings->helper_option_custom_post_type( $this->module );

// Check if we need to display the message about selecting at lest one post type
if ( get_transient( static::TRANSIENT_SHOW_ONE_POST_TYPE_WARNING ) ) {
echo '<p class="psppca_field_warning">' . __( 'At least one post type must be selected', 'publishpress' ) . '</p>';

delete_transient( static::TRANSIENT_SHOW_ONE_POST_TYPE_WARNING );
}
}

/**
Expand Down Expand Up @@ -1699,11 +1712,22 @@ public function settings_validate( $new_options ) {
break;
}
}

if ( $empty) {
// Check post by default
$options['post_types'] = array( 'post' => 'on' );

// Add flag to display a warning to the user
set_transient( static::TRANSIENT_SHOW_ONE_POST_TYPE_WARNING, 1, 300 );
} else {
$options['post_types'] = $this->clean_post_type_options( $new_options['post_types'], $this->module->post_type_support );
}
} else {
// Check post by default
$options['post_types'] = array( 'post' => 'on' );

// Add flag to display a warning to the user
set_transient( static::TRANSIENT_SHOW_ONE_POST_TYPE_WARNING, 1, 300 );
}

if ( 'on' != $new_options['ics_subscription'] ) {
Expand Down
92 changes: 58 additions & 34 deletions src/modules/improved-notifications/improved-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,68 +181,87 @@ public function init() {
public function install() {
// Check if we any other workflow before create, avoiding duplicated registers
if ( false === $this->has_default_workflows() ) {
$this->create_default_workflows();
$this->create_default_workflow_post_save();
$this->create_default_workflow_editorial_comment();
}
}

/**
* Create default notification workflows based on current notification settings
*/
protected function create_default_workflows() {
protected function create_default_workflow_post_save() {
$twig = $this->get_service( 'twig' );

// Get post statuses
$statuses = $this->get_post_statuses();
// Remove the published state
foreach ( $statuses as $index => $status ) {
if ( $status->slug === 'publish' ) {
unset( $statuses[ $index ] );
}
}

// Post Save
$args = [
'post_title' => __( 'Notify when posts are saved', 'publishpress' ),
'event_meta_key' => Event_Post_save::META_KEY_SELECTED,
'content_subject' => 'Changes were saved to &quot;[psppno_post title]&quot;',
'content_body' => $twig->render( 'workflow_default_content_post_save.twig', [] ),
$workflow = [
'post_status' => 'publish',
'post_title' => __( 'Notify when content is published', 'publishpress' ),
'post_type' => 'psppnotif_workflow',
'meta_input' => [
static::META_KEY_IS_DEFAULT_WORKFLOW => '1',
Event_Post_save::META_KEY_SELECTED => '1',
Filter_Post_Status::META_KEY_POST_STATUS_TO => 'publish',
Filter_Category::META_KEY_CATEGORY => 'all',
Content_Main::META_KEY_SUBJECT => '&quot;[psppno_post title]&quot; was published',
Content_Main::META_KEY_BODY => $twig->render( 'workflow_default_content_post_save.twig', [] ),
Receiver_Site_Admin::META_KEY => 1,
],
];
$this->create_default_workflow( $args );

// Editorial Comment
$args = [
'post_title' => __( 'Notify on editorial comments', 'publishpress' ),
'event_meta_key' => Event_Editorial_Comment::META_KEY_SELECTED,
'content_subject' => 'New editorial comment to &quot;[psppno_post title]&quot;',
'content_body' => $twig->render( 'workflow_default_content_editorial_comment.twig', [] ),
];
$this->create_default_workflow( $args );
$post_id = wp_insert_post( $workflow );

if ( is_int( $post_id ) && ! empty( $post_id ) ) {
add_post_meta( $post_id, Filter_Post_Type::META_KEY_POST_TYPE, 'post', false );
add_post_meta( $post_id, Filter_Post_Type::META_KEY_POST_TYPE, 'page', false );

// Add each status to the "From" filter, except the "publish" state
foreach ( $statuses as $status ) {
add_post_meta( $post_id, Filter_Post_Status ::META_KEY_POST_STATUS_FROM, $status->slug, false );
}
}
}

/**
* Create default notification workflow for the post_save event
*
* $args = [
* 'post_title' => ...
* 'content_subject' => ...
* 'content_body' => ...
* 'event_meta_key' => ...
* ]
*
* @param array $args
* Create default notification workflow for the editorial comments
*/
protected function create_default_workflow( $args ) {
protected function create_default_workflow_editorial_comment() {
$twig = $this->get_service( 'twig' );

// Post Save
$workflow = [
'post_status' => 'publish',
'post_title' => $args['post_title'],
'post_title' => __( 'Notify on editorial comments', 'publishpress' ),
'post_type' => 'psppnotif_workflow',
'meta_input' => [
static::META_KEY_IS_DEFAULT_WORKFLOW => '1',
$args['event_meta_key'] => '1',
Filter_Post_Type::META_KEY_POST_TYPE => 'all',
Filter_Post_Status::META_KEY_POST_STATUS_FROM => 'all',
Event_Editorial_Comment::META_KEY_SELECTED => '1',
Filter_Post_Status::META_KEY_POST_STATUS_TO => 'all',
Filter_Post_Status::META_KEY_POST_STATUS_FROM => 'all',
Filter_Category::META_KEY_CATEGORY => 'all',
Content_Main::META_KEY_SUBJECT => $args['content_subject'],
Content_Main::META_KEY_BODY => $args['content_body'],
Content_Main::META_KEY_SUBJECT => 'New editorial comment to &quot;[psppno_post title]&quot;',
Content_Main::META_KEY_BODY => $twig->render( 'workflow_default_content_editorial_comment.twig', [] ),
Receiver_Site_Admin::META_KEY => 1,
],
];

wp_insert_post( $workflow );
$post_id = wp_insert_post( $workflow );

if ( is_int( $post_id ) && ! empty( $post_id ) ) {
add_post_meta( $post_id, Filter_Post_Type::META_KEY_POST_TYPE, 'post', false );
add_post_meta( $post_id, Filter_Post_Type::META_KEY_POST_TYPE, 'page', false );
}
}


/**
* Returns true if we found any default workflow
*
Expand Down Expand Up @@ -300,6 +319,11 @@ public function action_transition_post_status( $new_status, $old_status, $post )
return;
}

// Ignores auto-save
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}

// Go ahead and do the action to run workflows
$args = [
'action' => 'transition_post_status',
Expand Down
2 changes: 1 addition & 1 deletion src/publishpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: The essential plugin for any WordPress site with multiple writers
* Author: PressShack
* Author URI: https://pressshack.com
* Version: 1.7.1
* Version: 1.7.2
*
* Copyright (c) 2017 PressShack
*
Expand Down
13 changes: 12 additions & 1 deletion src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author URI: https://pressshack.com
Tags: Content Calendar, Editorial Calendar, workflow, checklist, pre-publish
Requires at least: 4.6
Tested up to: 4.8
Stable tag: 1.7.1
Stable tag: 1.7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -157,6 +157,14 @@ You can install PublishPress through your WordPress admin area:
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

= [1.7.2] - 2017-08-31 =

* Fixed:
* Fixed default notification workflows to avoid notifications on every post save, but only when the content transition to Published;
* Fixed the message after delete workflows;
* Fixed the notifications workflows to ignore autosaves;
* Fixed post type options in the calendar settings, selecting the Post post type by default, if nothing is selected - Displaying a warning;

= [1.7.1] - 2017-08-30 =

* Fixed:
Expand All @@ -165,6 +173,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
* Fixed bug on saving modules settings where changes were not being saved;
* Fixed default color and icon for existent statuses;

* Changed:
* Improved default colors for custom statuses;

= [1.7.0] - 2017-08-29 =

* Added:
Expand Down
2 changes: 1 addition & 1 deletion src/twig/workflow_default_content_post_save.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Thank you for helping create great content with us.

This notification is to let you know changes were saved for "[psppno_post title]".
This notification is to let you know the content "[psppno_post title]" was published.

The user who saved the changes is [psppno_actor display_name].

Expand Down

0 comments on commit eb04bfa

Please sign in to comment.