Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update/#1601-Add-2-new-notifications #1722

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 100 additions & 17 deletions modules/improved-notifications/improved-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,6 @@ public function init()
add_filter('psppno_default_channel', [$this, 'filter_default_channel'], 10, 2);
}

/**
* Load default editorial fields the first time the module is loaded
*
* @since 0.7
*/
public function install()
{
if (false === $this->has_default_workflows()) {
$this->create_default_workflow_post_save();
$this->create_default_workflow_editorial_comment();
}
}

/**
* Methods called after all modules where loaded and initialized,
* to make sure all hooks are set before we start some specific features.
Expand Down Expand Up @@ -248,7 +235,83 @@ public function print_configure_view()
/**
* Create default notification workflows based on current notification settings
*/
protected function create_default_workflow_post_save()
protected function create_default_workflow_post_update()
{
$view = $this->get_service('view');

// Post Save
$workflow = [
'post_status' => 'publish',
'post_title' => __('Existing Post is updated', 'publishpress'),
'post_type' => 'psppnotif_workflow',
'meta_input' => [
static::META_KEY_IS_DEFAULT_WORKFLOW => '1',
Post_Update::META_KEY_SELECTED => '1',
Content_Main::META_KEY_SUBJECT => '"[psppno_post title]" was updated',
Content_Main::META_KEY_BODY => $view->render('workflow_default_content_post_update'),
Receiver_Site_Admin::META_KEY => 1,
Post_Type_Filter::META_KEY_POST_TYPE => 'post',
Post_Type::META_KEY_SELECTED => 1,
],
];

$post_id = wp_insert_post($workflow);

if (is_int($post_id) && ! empty($post_id)) {
// Get post statuses
$statuses = $this->get_post_statuses();
// Add each status to the "From" and "To" filter
foreach ($statuses as $status) {
add_post_meta($post_id, Filter_Post_Status::META_KEY_POST_STATUS_FROM, $status->slug, false);
add_post_meta($post_id, Filter_Post_Status::META_KEY_POST_STATUS_TO, $status->slug, false);
}
}
}

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

$statuses = [
(object)[
'slug' => 'auto-draft',
]
];

// Post Save
$workflow = [
'post_status' => 'publish',
'post_title' => __('New Post is created in Draft status', 'publishpress'),
'post_type' => 'psppnotif_workflow',
'meta_input' => [
static::META_KEY_IS_DEFAULT_WORKFLOW => '1',
Post_StatusTransition::META_KEY_SELECTED => '1',
Filter_Post_Status::META_KEY_POST_STATUS_TO => 'draft',
Content_Main::META_KEY_SUBJECT => '"[psppno_post title]" created in draft',
Content_Main::META_KEY_BODY => $view->render('workflow_default_content_new_draft_created'),
Receiver_Site_Admin::META_KEY => 1,
Post_Type_Filter::META_KEY_POST_TYPE => 'post',
Post_Type::META_KEY_SELECTED => 1,
],
];

$post_id = wp_insert_post($workflow);

if (is_int($post_id) && ! empty($post_id)) {
// 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 workflows based on current notification settings
*/
protected function create_default_workflow_post_published()
{
$view = $this->get_service('view');

Expand All @@ -267,22 +330,23 @@ protected function create_default_workflow_post_save()
'slug' => 'auto-draft',
];

// Post Save
// Post Published
$workflow = [
'post_status' => 'publish',
'post_title' => __('Notify when content is published', 'publishpress'),
'post_title' => __('New Post is Published', 'publishpress'),
'post_type' => 'psppnotif_workflow',
'meta_input' => [
static::META_KEY_IS_DEFAULT_WORKFLOW => '1',
Post_StatusTransition::META_KEY_SELECTED => '1',
Filter_Post_Status::META_KEY_POST_STATUS_TO => 'publish',
Content_Main::META_KEY_SUBJECT => '"[psppno_post title]" was published',
Content_Main::META_KEY_BODY => $view->render('workflow_default_content_post_save'),
Content_Main::META_KEY_BODY => $view->render('workflow_default_content_post_published'),
Receiver_Site_Admin::META_KEY => 1,
Post_Type_Filter::META_KEY_POST_TYPE => 'post',
Post_Type::META_KEY_SELECTED => 1,
],
];


$post_id = wp_insert_post($workflow);

Expand Down Expand Up @@ -443,6 +507,20 @@ protected function has_default_workflows()
return $query->the_post();
}

/**
* Load default editorial fields the first time the module is loaded
*
* @since 0.7
*/
public function install()
{
if (false === $this->has_default_workflows()) {
$this->create_default_workflow_post_update();
$this->create_default_workflow_new_draft_created();
$this->create_default_workflow_post_published();
}
}

/**
* Upgrade our data in case we need to
*
Expand Down Expand Up @@ -488,6 +566,11 @@ public function upgrade($previous_version)
if (version_compare($previous_version, '1.10', '<=')) {
$this->migrate_legacy_metadata_for_role();
}

if (version_compare($previous_version, '4.3.1', '<=')) {
$this->create_default_workflow_post_update();
$this->create_default_workflow_new_draft_created();
}
}

protected function migrate_legacy_metadata_for_role()
Expand Down
2 changes: 1 addition & 1 deletion publishpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ function () {
}
}
}

update_option('pp_planner_activated', true);
}
);
7 changes: 7 additions & 0 deletions views/workflow_default_content_new_draft_created.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Thank you for helping create great content with us.

This notification is to let you know the content "[psppno_post title]" was created in draft.

The user who created the content is [psppno_actor display_name].

The URL of the content is [psppno_post permalink]
7 changes: 7 additions & 0 deletions views/workflow_default_content_post_published.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Thank you for helping create great content with us.

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

The user who published the content is [psppno_actor display_name].

The URL of the content is [psppno_post permalink]
7 changes: 7 additions & 0 deletions views/workflow_default_content_post_update.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Thank you for helping create great content with us.

This notification is to let you know the content "[psppno_post title]" was updated.

The user who update the content is [psppno_actor display_name].

The URL of the content is [psppno_post permalink]
Loading