Skip to content

Commit c0baaf1

Browse files
authored
Merge pull request #538 from ProgressPlanner/ari/task-disable-comment-pagination
New task provider: Disable comment pagination
2 parents da235b2 + 166acbb commit c0baaf1

7 files changed

Lines changed: 186 additions & 10 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* global prplInteractiveTaskFormListener */
2+
3+
/*
4+
* Disable Comment Pagination recommendation.
5+
*
6+
* Dependencies: progress-planner/recommendations/interactive-task
7+
*/
8+
9+
prplInteractiveTaskFormListener.settings( {
10+
setting: 'page_comments',
11+
settingPath: '{}',
12+
taskId: 'disable-comment-pagination',
13+
popoverId: 'prpl-popover-disable-comment-pagination',
14+
settingCallbackValue: () => '',
15+
} );

assets/js/recommendations/interactive-task.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ const prplInteractiveTaskFormListener = {
109109
settings: ( {
110110
taskId,
111111
setting,
112-
value,
113-
settingPath,
112+
settingPath = false,
114113
popoverId,
115114
settingCallbackValue = ( settingValue ) => settingValue,
116115
} = {} ) => {
@@ -136,7 +135,7 @@ const prplInteractiveTaskFormListener = {
136135
_ajax_nonce: progressPlanner.nonce,
137136
post_id: taskId,
138137
setting,
139-
value,
138+
value: settingsToPass[ setting ],
140139
setting_path: settingPath,
141140
},
142141
} ).then( () => {

classes/suggested-tasks/class-tasks-manager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Progress_Planner\Suggested_Tasks\Providers\Settings_Saved;
1515
use Progress_Planner\Suggested_Tasks\Providers\Debug_Display;
1616
use Progress_Planner\Suggested_Tasks\Providers\Disable_Comments;
17+
use Progress_Planner\Suggested_Tasks\Providers\Disable_Comment_Pagination;
1718
use Progress_Planner\Suggested_Tasks\Providers\Sample_Page;
1819
use Progress_Planner\Suggested_Tasks\Providers\Hello_World;
1920
use Progress_Planner\Suggested_Tasks\Providers\Remove_Inactive_Plugins;
@@ -60,6 +61,7 @@ public function __construct() {
6061
new Settings_Saved(),
6162
new Debug_Display(),
6263
new Disable_Comments(),
64+
new Disable_Comment_Pagination(),
6365
new Sample_Page(),
6466
new Hello_World(),
6567
new Remove_Inactive_Plugins(),
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* Add tasks for disabling comments.
4+
*
5+
* @package Progress_Planner
6+
*/
7+
8+
namespace Progress_Planner\Suggested_Tasks\Providers;
9+
10+
/**
11+
* Add tasks to disable comments.
12+
*/
13+
class Disable_Comment_Pagination extends Tasks_Interactive {
14+
15+
/**
16+
* Whether the task is an onboarding task.
17+
*
18+
* @var bool
19+
*/
20+
protected const IS_ONBOARDING_TASK = true;
21+
22+
/**
23+
* The provider ID.
24+
*
25+
* @var string
26+
*/
27+
protected const PROVIDER_ID = 'disable-comment-pagination';
28+
29+
/**
30+
* The popover ID.
31+
*
32+
* @var string
33+
*/
34+
const POPOVER_ID = 'disable-comment-pagination';
35+
36+
/**
37+
* Get the task URL.
38+
*
39+
* @return string
40+
*/
41+
protected function get_url() {
42+
return \admin_url( 'options-discussion.php' );
43+
}
44+
45+
/**
46+
* Get the link setting.
47+
*
48+
* @return array
49+
*/
50+
public function get_link_setting() {
51+
return [
52+
'hook' => 'options-discussion.php',
53+
'iconEl' => 'label[for="page_comments"]',
54+
];
55+
}
56+
57+
/**
58+
* Get the task title.
59+
*
60+
* @return string
61+
*/
62+
protected function get_title() {
63+
return \esc_html__( 'Disable comment pagination', 'progress-planner' );
64+
}
65+
66+
/**
67+
* Get the task description.
68+
*
69+
* @return string
70+
*/
71+
protected function get_description() {
72+
return \sprintf(
73+
/* translators: %d is the number of comments per page, %s is the "recommend to disable comment pagination" link */
74+
\esc_html__( 'When comment pagination is enabled, your site creates a new page for every %1$d comments. This is not helping your website in search engines, and can break up the ongoing conversation. That\'s why we %2$s.', 'progress-planner' ),
75+
(int) \get_option( 'comments_per_page' ),
76+
'<a href="https://prpl.fyi/disable-comment-pagination" target="_blank">' . \esc_html__( 'recommend to disable comment pagination', 'progress-planner' ) . '</a>'
77+
);
78+
}
79+
80+
/**
81+
* Check if the task condition is satisfied.
82+
* (bool) true means that the task condition is satisfied, meaning that we don't need to add the task or task was completed.
83+
*
84+
* @return bool
85+
*/
86+
public function should_add_task() {
87+
return $this->are_dependencies_satisfied() && \get_option( 'page_comments' );
88+
}
89+
90+
/**
91+
* Check if the task is completed.
92+
*
93+
* @param string $task_id The task ID.
94+
*
95+
* @return bool
96+
*/
97+
public function is_task_completed( $task_id = '' ) {
98+
return ! \get_option( 'page_comments' );
99+
}
100+
101+
/**
102+
* Get the popover instructions.
103+
*
104+
* @return void
105+
*/
106+
public function print_popover_instructions() {
107+
?>
108+
<p>
109+
<?php
110+
\printf(
111+
/* translators: %d is the number of comments per page, %s is the "recommend to disable comment pagination" link */
112+
\esc_html__( 'When comment pagination is enabled, your site creates a new page for every %1$d comments. This is not helping your website in search engines, and can break up the ongoing conversation. That\'s why we %2$s.', 'progress-planner' ),
113+
(int) \get_option( 'comments_per_page' ),
114+
'<a href="https://prpl.fyi/disable-comment-pagination" target="_blank">' . \esc_html__( 'recommend to disable comment pagination', 'progress-planner' ) . '</a>'
115+
);
116+
?>
117+
</p>
118+
<?php
119+
}
120+
121+
/**
122+
* Print the popover input field for the form.
123+
*
124+
* @return void
125+
*/
126+
public function print_popover_form_contents() {
127+
?>
128+
<button type="submit" class="prpl-button prpl-button-primary" style="color: #fff;">
129+
<?php \esc_html_e( 'Disable comment pagination', 'progress-planner' ); ?>
130+
</button>
131+
<?php
132+
}
133+
}

classes/suggested-tasks/providers/class-email-sending.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function set_email_error( $e ) {
278278
*
279279
* @return void
280280
*/
281-
protected function the_popover_content() {
281+
public function the_popover_content() {
282282
\progress_planner()->the_view(
283283
'popovers/email-sending.php',
284284
[

classes/suggested-tasks/providers/class-tasks-interactive.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function get_task_details( $task_data = [] ) {
4949
*
5050
* This is only for interactive tasks that change non-core settings.
5151
* The $_POST data is expected to be:
52-
* - post_id: (int) The post ID.
5352
* - setting: (string) The setting to update.
5453
* - value: (mixed) The value to update the setting to.
5554
* - setting_path: (array) The path to the setting to update.
@@ -66,10 +65,6 @@ public function handle_interactive_task_submit() {
6665
\wp_send_json_error( [ 'message' => \esc_html__( 'Invalid nonce.', 'progress-planner' ) ] );
6766
}
6867

69-
if ( ! isset( $_POST['post_id'] ) || ! isset( $_POST['action_type'] ) ) {
70-
\wp_send_json_error( [ 'message' => \esc_html__( 'Missing data.', 'progress-planner' ) ] );
71-
}
72-
7368
if ( ! isset( $_POST['setting'] ) ) {
7469
\wp_send_json_error( [ 'message' => \esc_html__( 'Missing setting.', 'progress-planner' ) ] );
7570
}
@@ -121,7 +116,7 @@ public function add_popover() {
121116
*
122117
* @return void
123118
*/
124-
protected function the_popover_content() {
119+
public function the_popover_content() {
125120
\progress_planner()->the_view(
126121
[
127122
'/views/popovers/' . static::POPOVER_ID . '.php',

classes/suggested-tasks/providers/class-tasks.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ abstract class Tasks implements Tasks_Interface {
4949
*/
5050
protected const DATA_COLLECTOR_CLASS = \Progress_Planner\Suggested_Tasks\Data_Collector\Base_Data_Collector::class;
5151

52+
/**
53+
* Dependencies on other tasks.
54+
*
55+
* The key is the task-ID of the other task,
56+
* If the value is true, the task is pending, if false, the task is completed/dismissed/snoozed.
57+
*
58+
* @var array<string, bool>
59+
*/
60+
protected const DEPENDENCIES = [];
61+
5262
/**
5363
* Whether the task is repetitive.
5464
*
@@ -548,4 +558,26 @@ protected function transform_collector_data( array $data ): array {
548558

549559
return $data;
550560
}
561+
562+
/**
563+
* Check if the task dependencies are satisfied.
564+
*
565+
* @return bool
566+
*/
567+
public function are_dependencies_satisfied() {
568+
foreach ( static::DEPENDENCIES as $task_id => $result ) {
569+
$post = \progress_planner()->get_suggested_tasks_db()->get_post( $task_id );
570+
if ( ! $post ) {
571+
return false;
572+
}
573+
$post_status = $post->post_status;
574+
if ( ( 'publish' === $post_status && ! $result )
575+
|| ( 'publish' !== $post_status && $result )
576+
) {
577+
return false;
578+
}
579+
}
580+
581+
return true;
582+
}
551583
}

0 commit comments

Comments
 (0)