|
| 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 | +} |
0 commit comments