Skip to content

Commit 883b70e

Browse files
committed
make task interactive
1 parent f4a7cdc commit 883b70e

2 files changed

Lines changed: 77 additions & 1 deletion

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.siteSettings( {
10+
settingAPIKey: 'page_comments',
11+
setting: 'page_comments',
12+
taskId: 'disable-comment-pagination',
13+
popoverId: 'prpl-popover-disable-comment-pagination',
14+
settingCallbackValue: () => '',
15+
} );

classes/suggested-tasks/providers/class-disable-comment-pagination.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Add tasks to disable comments.
1212
*/
13-
class Disable_Comment_Pagination extends Tasks {
13+
class Disable_Comment_Pagination extends Tasks_Interactive {
1414

1515
/**
1616
* Whether the task is an onboarding task.
@@ -26,6 +26,43 @@ class Disable_Comment_Pagination extends Tasks {
2626
*/
2727
protected const PROVIDER_ID = 'disable-comment-pagination';
2828

29+
/**
30+
* The popover ID.
31+
*
32+
* @var string
33+
*/
34+
const POPOVER_ID = 'disable-comment-pagination';
35+
36+
/**
37+
* Initialize the task.
38+
*
39+
* @return void
40+
*/
41+
public function init() {
42+
\add_action( 'rest_api_init', [ $this, 'register_setting_with_rest' ] );
43+
}
44+
45+
/**
46+
* Register the setting with the REST API.
47+
*
48+
* @return void
49+
*/
50+
public function register_setting_with_rest() {
51+
register_setting(
52+
'discussion',
53+
'page_comments',
54+
[
55+
'type' => 'string',
56+
'label' => __( 'Break comments into pages', 'progress-planner' ),
57+
'show_in_rest' => [
58+
'schema' => [
59+
'enum' => [ '1', '' ],
60+
],
61+
],
62+
]
63+
);
64+
}
65+
2966
/**
3067
* Get the task URL.
3168
*
@@ -85,4 +122,28 @@ public function should_add_task() {
85122
public function is_task_completed( $task_id = '' ) {
86123
return ! \get_option( 'page_comments' );
87124
}
125+
126+
/**
127+
* Get the popover instructions.
128+
*
129+
* @return void
130+
*/
131+
public function print_popover_instructions() {
132+
?>
133+
<p><?php \esc_html_e( 'Comment pagination is enabled by default. This means that comments are split into multiple pages. This can be disabled to make the comments easier to read.', 'progress-planner' ); ?></p>
134+
<?php
135+
}
136+
137+
/**
138+
* Print the popover input field for the form.
139+
*
140+
* @return void
141+
*/
142+
public function print_popover_form_contents() {
143+
?>
144+
<button type="submit" class="prpl-button prpl-button-primary" style="color: #fff;">
145+
<?php \esc_html_e( 'Disable comment pagination', 'progress-planner' ); ?>
146+
</button>
147+
<?php
148+
}
88149
}

0 commit comments

Comments
 (0)