|
| 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