Skip to content

Commit 3d70e2d

Browse files
committed
make tast interactive
1 parent ae5366f commit 3d70e2d

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

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/providers/class-select-timezone.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Add task to select the site locale.
1212
*/
13-
class Select_Timezone extends Tasks {
13+
class Select_Timezone extends Tasks_Interactive {
1414

1515
/**
1616
* The provider ID.
@@ -19,6 +19,13 @@ class Select_Timezone extends Tasks {
1919
*/
2020
protected const PROVIDER_ID = 'select-timezone';
2121

22+
/**
23+
* The popover ID.
24+
*
25+
* @var string
26+
*/
27+
const POPOVER_ID = 'select-timezone';
28+
2229
/**
2330
* Whether the task is dismissable.
2431
*
@@ -80,4 +87,50 @@ public function should_add_task() {
8087

8188
return ! $timezone_activity;
8289
}
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+
}
83136
}

0 commit comments

Comments
 (0)