Skip to content

Commit da235b2

Browse files
authored
Merge pull request #556 from ProgressPlanner/filip/select-timezone
New task provider: Select site timezone
2 parents bbc0015 + 49daef1 commit da235b2

5 files changed

Lines changed: 158 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
= 1.7.0 =
22

3+
Added these recommendations from Ravi:
4+
* Select site timezone.
5+
36
Bugs we fixed:
47

58
* Fix issue where "Perform all updates" task was incorrectly marked as completed.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* global prplInteractiveTaskFormListener */
2+
3+
/*
4+
* Set the site timezone.
5+
*
6+
* Dependencies: progress-planner/recommendations/interactive-task
7+
*/
8+
9+
prplInteractiveTaskFormListener.siteSettings( {
10+
settingAPIKey: 'timezone',
11+
setting: 'timezone',
12+
taskId: 'select-timezone',
13+
popoverId: 'prpl-popover-select-timezone',
14+
} );

classes/suggested-tasks/class-task.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ public function update( array $data ): void {
9090
* @return void
9191
*/
9292
public function delete(): void {
93-
$this->data = [];
9493
// Delete only if the task is already saved in the database.
9594
if ( $this->ID ) {
9695
\progress_planner()->get_suggested_tasks_db()->delete_recommendation( $this->ID );
9796
}
97+
98+
// Clear the data.
99+
$this->data = [];
98100
}
99101

100102
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Progress_Planner\Suggested_Tasks\Providers\Update_Term_Description;
3434
use Progress_Planner\Suggested_Tasks\Providers\Unpublished_Content;
3535
use Progress_Planner\Suggested_Tasks\Providers\Collaborator;
36+
use Progress_Planner\Suggested_Tasks\Providers\Select_Timezone;
3637

3738
/**
3839
* Tasks_Manager class.
@@ -76,6 +77,7 @@ public function __construct() {
7677
new Update_Term_Description(),
7778
new Unpublished_Content(),
7879
new Collaborator(),
80+
new Select_Timezone(),
7981
];
8082

8183
// Add the plugin integration.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
/**
3+
* Add task to select the site timezone.
4+
*
5+
* @package Progress_Planner
6+
*/
7+
8+
namespace Progress_Planner\Suggested_Tasks\Providers;
9+
10+
/**
11+
* Add task to select the site locale.
12+
*/
13+
class Select_Timezone extends Tasks_Interactive {
14+
15+
/**
16+
* The provider ID.
17+
*
18+
* @var string
19+
*/
20+
protected const PROVIDER_ID = 'select-timezone';
21+
22+
/**
23+
* The popover ID.
24+
*
25+
* @var string
26+
*/
27+
const POPOVER_ID = 'select-timezone';
28+
29+
/**
30+
* Whether the task is dismissable.
31+
*
32+
* @var bool
33+
*/
34+
protected $is_dismissable = true;
35+
36+
/**
37+
* Get the task URL.
38+
*
39+
* @return string
40+
*/
41+
protected function get_url() {
42+
return \admin_url( 'options-general.php?pp-focus-el=' . $this->get_task_id() );
43+
}
44+
45+
/**
46+
* Get the link setting.
47+
*
48+
* @return array
49+
*/
50+
public function get_link_setting() {
51+
return [
52+
'hook' => 'options-general.php',
53+
'iconEl' => 'label[for="timezone_string"]',
54+
];
55+
}
56+
57+
/**
58+
* Get the task title.
59+
*
60+
* @return string
61+
*/
62+
protected function get_title() {
63+
return \esc_html__( 'Set site timezone', 'progress-planner' );
64+
}
65+
66+
/**
67+
* Get the task description.
68+
*
69+
* @return string
70+
*/
71+
protected function get_description() {
72+
return \esc_html__( 'Set site timezone to ensure scheduled posts and pages are published at desired time.', 'progress-planner' );
73+
}
74+
75+
/**
76+
* Check if the task should be added.
77+
*
78+
* @return bool
79+
*/
80+
public function should_add_task() {
81+
$timezone_activity = \progress_planner()->get_activities__query()->query_activities(
82+
[
83+
'category' => 'suggested_task',
84+
'data_id' => static::PROVIDER_ID,
85+
]
86+
);
87+
88+
return ! $timezone_activity;
89+
}
90+
91+
/**
92+
* Get the popover instructions.
93+
*
94+
* @return void
95+
*/
96+
public function print_popover_instructions() {
97+
?>
98+
<p><?php \esc_html_e( 'Set site timezone to ensure scheduled posts and pages are published at desired time.', 'progress-planner' ); ?></p>
99+
<?php
100+
}
101+
102+
/**
103+
* Print the popover input field for the form.
104+
*
105+
* @return void
106+
*/
107+
public function print_popover_form_contents() {
108+
$current_offset = \get_option( 'gmt_offset' );
109+
$tzstring = \get_option( 'timezone_string' );
110+
111+
// Remove old Etc mappings. Fallback to gmt_offset.
112+
if ( str_contains( $tzstring, 'Etc/GMT' ) ) {
113+
$tzstring = '';
114+
}
115+
116+
if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists.
117+
if ( 0 === (int) $current_offset ) {
118+
$tzstring = 'UTC+0';
119+
} elseif ( $current_offset < 0 ) {
120+
$tzstring = 'UTC' . $current_offset;
121+
} else {
122+
$tzstring = 'UTC+' . $current_offset;
123+
}
124+
}
125+
?>
126+
<label>
127+
<select id="timezone" name="timezone">
128+
<?php echo \wp_timezone_choice( $tzstring, \get_user_locale() ); ?>
129+
</select>
130+
</label>
131+
<button type="submit" class="prpl-button prpl-button-primary" style="color: #fff;">
132+
<?php \esc_html_e( 'Set site timezone', 'progress-planner' ); ?>
133+
</button>
134+
<?php
135+
}
136+
}

0 commit comments

Comments
 (0)