Skip to content

Commit

Permalink
Merge pull request #195 from OSTraining/development
Browse files Browse the repository at this point in the history
Preparing to release 1.12.0
  • Loading branch information
Anderson Grüdtner Martins authored Apr 18, 2018
2 parents 8f25959 + 8cd285f commit 993e945
Show file tree
Hide file tree
Showing 26 changed files with 207 additions and 117 deletions.
2 changes: 1 addition & 1 deletion includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
);

// Define contants
define('PUBLISHPRESS_VERSION', '1.11.4');
define('PUBLISHPRESS_VERSION', '1.12.0');
define('PUBLISHPRESS_BASE_PATH', __DIR__);
define('PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_BASE_PATH . '/' . basename(__FILE__));
define('PUBLISHPRESS_URL', plugins_url('/', __FILE__));
Expand Down
113 changes: 34 additions & 79 deletions libraries/Notifications/Shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,20 @@ protected function get_actor()
protected function get_user_data($user, $attrs)
{
// No attributes? Set the default one.
if (empty($attrs))
{
if (empty($attrs)) {
$attrs[] = 'display_name';
}

// Set the separator
if (!isset($attrs['separator']))
{
if (!isset($attrs['separator'])) {
$attrs['separator'] = ', ';
}

// Get the user's info
$info = [];
$valid_attributes = [
'id',
'login',
'url',
'display_name',
'email',
'separator',
];

foreach ($attrs as $index => $item)
{
switch ($item)
{
$info = [];

foreach ($attrs as $index => $item) {
switch ($item) {
case 'id':
$info[] = $user->ID;
break;
Expand Down Expand Up @@ -217,6 +205,7 @@ protected function get_post()
* - old_status
* - new_status
* - separator
* - edit_link
*
* @param WP_Post $post
* @param array $attrs
Expand All @@ -227,34 +216,20 @@ protected function get_post_data($post, $attrs)
$publishpress = $this->get_service('publishpress');

// No attributes? Set the default one.
if (empty($attrs))
{
$attrs = array('title');
if (empty($attrs)) {
$attrs = ['title'];
}

// Set the separator
if (!isset($attrs['separator']))
{
if (!isset($attrs['separator'])) {
$attrs['separator'] = ', ';
}

// Get the post's info
$info = [];
$valid_attributes = [
'id',
'title',
'permalink',
'date',
'time',
'old_status',
'new_status',
'separator',
];

foreach ($attrs as $index => $item)
{
switch ($item)
{
$info = [];

foreach ($attrs as $index => $item) {
switch ($item) {
case 'id':
$info[] = $post->ID;
break;
Expand All @@ -264,7 +239,7 @@ protected function get_post_data($post, $attrs)
break;

case 'permalink':
$info[] = get_post_permalink($post->ID);
$info[] = get_permalink($post->ID);
break;

case 'date':
Expand All @@ -282,14 +257,18 @@ protected function get_post_data($post, $attrs)
$this->action_args[$item]
);

if (empty($status) || 'WP_Error' === get_class($status))
{
if (empty($status) || 'WP_Error' === get_class($status)) {
break;
}

$info[] = $status->name;
break;

case 'edit_link':
$admin_path = 'post.php?post=' . $post->ID . '&action=edit';
$info[] = htmlspecialchars_decode(admin_url($admin_path));
break;

default:
break;
}
Expand Down Expand Up @@ -318,29 +297,20 @@ public function handle_psppno_workflow($attrs)
$post = $this->workflow_post;

// No attributes? Set the default one.
if (empty($attrs))
{
if (empty($attrs)) {
$attrs[] = 'title';
}

// Set the separator
if (!isset($attrs['separator']))
{
if (!isset($attrs['separator'])) {
$attrs['separator'] = ', ';
}

// Get the post's info
$info = [];
$valid_attributes = [
'id',
'title',
'separator',
];

foreach ($attrs as $index => $item)
{
switch ($item)
{
$info = [];

foreach ($attrs as $index => $item) {
switch ($item) {
case 'id':
$info[] = $post->ID;
break;
Expand Down Expand Up @@ -379,42 +349,27 @@ public function handle_psppno_workflow($attrs)
*/
public function handle_psppno_edcomment($attrs)
{
if (!isset($this->action_args['comment']))
{
if (!isset($this->action_args['comment'])) {
return;
}

$comment = $this->action_args['comment'];

// No attributes? Set the default one.
if (empty($attrs))
{
if (empty($attrs)) {
$attrs[] = 'content';
}

// Set the separator
if (!isset($attrs['separator']))
{
if (!isset($attrs['separator'])) {
$attrs['separator'] = ', ';
}

// Get the post's info
$info = [];
$valid_attributes = [
'id',
'content',
'author',
'author_email',
'author_url',
'author_ip',
'date',
'separator',
];

foreach ($attrs as $index => $item)
{
switch ($item)
{
$info = [];

foreach ($attrs as $index => $item) {
switch ($item) {
case 'id':
$info[] = $comment->comment_ID;
break;
Expand Down
2 changes: 2 additions & 0 deletions libraries/Notifications/Traits/Dependency_Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ trait Dependency_Injector
*
* @param string $service_name
*
* @return mix
*
* @throws \Exception
*/
public function get_service($service_name)
Expand Down
2 changes: 1 addition & 1 deletion libraries/Notifications/Workflow/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function run_workflows($args)
* @param array $args
* @return array
*/
protected function get_filtered_workflows($args)
public function get_filtered_workflows($args)
{
$workflows = [];

Expand Down
4 changes: 4 additions & 0 deletions libraries/Notifications/Workflow/Step/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function __construct()
* Action to display the metabox
*
* @param string $html
*
* @return string
*
* @throws \Exception
*/
public function render_metabox_section($html)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function save_metabox_data($id, $post)
*/
public function get_run_workflow_query_args($query_args, $action_args)
{
// If post is not set, we ignore.
if (!isset($action_args['post']) || !is_object($action_args['post'])) {
return parent::get_run_workflow_query_args($query_args, $action_args);
}

$categories = wp_get_post_terms($action_args['post']->ID, 'category');
$category_ids = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public function save_metabox_data($id, $post)
*/
public function get_run_workflow_query_args($query_args, $action_args)
{
// If post is not set, we ignore.
if (!isset($action_args['post']) || !is_object($action_args['post'])) {
return parent::get_run_workflow_query_args($query_args, $action_args);
}

// Add the filters
$query_args['meta_query'][] = [
'relation' => 'OR',
// The filter is disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ protected function get_filters($filters = [])
*/
public function filter_run_workflow_query_args($query_args, $action_args)
{

// Check the filters
$filters = $this->get_filters();

Expand Down
59 changes: 59 additions & 0 deletions libraries/Notifications/Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Workflow

use Dependency_Injector;

const NOTIFICATION_SCHEDULE_META_KEY = '_psppre_notification_scheduled';

/**
* The post of this workflow.
*
Expand Down Expand Up @@ -223,4 +225,61 @@ protected function filter_shortcodes($text)
{
return do_shortcode($text);
}

/**
* Get posts related to this workflow, applying the filters, in a reverse way, not founding a workflow related
* to the post. Used by add-ons like Reminders.
*
* @return array
*/
public function get_related_posts()
{
$posts = [];

// Build the query
$query_args = [
'nopaging' => true,
'post_status' => 'future',
'no_found_rows' => true,
'cache_results' => true,
'meta_query' => [
[
'key' => static::NOTIFICATION_SCHEDULE_META_KEY,
'compare' => 'NOT EXISTS',
],
]
];

// Check if the workflow filters by post type
$workflowPostTypes = get_post_meta(
$this->workflow_post->ID,
Step\Event_Content\Filter\Post_Type::META_KEY_POST_TYPE
);

if (!empty($workflowPostTypes)) {
$query_args['post_type'] = $workflowPostTypes;
}

// Check if the workflow filters by category
$workflowCategories = get_post_meta(
$this->workflow_post->ID,
Step\Event_Content\Filter\Category::META_KEY_CATEGORY
);

if (!empty($workflowCategories)) {
$query_args['category__in'] = $workflowCategories;
}

$query = new \WP_Query($query_args);

if (!empty($query->posts))
{
foreach ($query->posts as $post)
{
$posts[] = $post;
}
}

return $posts;
}
}
4 changes: 2 additions & 2 deletions modules/async-notifications/async-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function __construct()
// Register the module with PublishPress
$args = [
'title' => __('Async Notifications', 'publishpress'),
'short_description' => __('Async notifications for PublishPress', 'publishpress'),
'extended_description' => __('Async Notifications for PublishPress', 'publishpress'),
'short_description' => false,
'extended_description' => false,
'module_url' => $this->module_url,
'icon_class' => 'dashicons dashicons-feedback',
'slug' => 'async-notifications',
Expand Down
16 changes: 13 additions & 3 deletions modules/async-notifications/library/Queue/WPCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ public function enqueueNotification($workflowPost, $actionArgs, $receivers, $con
$channel,
];

$timestamp = apply_filters('publishpress_notif_async_timestamp', time(), $workflowPost->ID);

if (false === $timestamp) {
// Abort.
error_log('PublishPress aborted a notification. Invalid timestamp for workflow ' . $workflowPost->ID);
return;
}

// Create one notification for each receiver in the queue
foreach ($receivers as $receiver)
{
Expand All @@ -80,7 +88,7 @@ public function enqueueNotification($workflowPost, $actionArgs, $receivers, $con
// Receiver
$data[] = $receiver;

$this->scheduleEvent($data);
$this->scheduleEvent($data, $timestamp);
}
}
}
Expand All @@ -89,12 +97,14 @@ public function enqueueNotification($workflowPost, $actionArgs, $receivers, $con
* Schedule the notification event.
*
* @param $data
* @param $timestamp
*
* @throws \Exception
*/
protected function scheduleEvent($data)
protected function scheduleEvent($data, $timestamp)
{
wp_schedule_single_event(
time() + 4,
$timestamp,
'publishpress_cron_notify',
$data
);
Expand Down
Loading

0 comments on commit 993e945

Please sign in to comment.