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