| 1 |
<?php |
| 2 |
|
| 3 |
namespace King_Addons; |
| 4 |
|
| 5 |
use Elementor\Widget_Base; |
| 6 |
use Elementor\Controls_Manager; |
| 7 |
|
| 8 |
if (!defined('ABSPATH')) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
class Maintenance_Page extends Widget_Base |
| 13 |
{ |
| 14 |
public function get_name() |
| 15 |
{ |
| 16 |
return 'king-addons-maintenance-page'; |
| 17 |
} |
| 18 |
|
| 19 |
public function get_title() |
| 20 |
{ |
| 21 |
return esc_html__('KNG Maintenance Page', 'king-addons'); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_icon() |
| 25 |
{ |
| 26 |
return 'king-addons-icon king-addons-maintenance-mode'; |
| 27 |
} |
| 28 |
|
| 29 |
public function get_categories() |
| 30 |
{ |
| 31 |
return ['king-addons']; |
| 32 |
} |
| 33 |
|
| 34 |
public function get_keywords() |
| 35 |
{ |
| 36 |
return ['maintenance', 'coming soon', 'access', 'gate', 'maintenance page']; |
| 37 |
} |
| 38 |
|
| 39 |
protected function register_controls(): void |
| 40 |
{ |
| 41 |
$this->start_controls_section( |
| 42 |
'section_content', |
| 43 |
[ |
| 44 |
'label' => esc_html__('Maintenance Page', 'king-addons'), |
| 45 |
] |
| 46 |
); |
| 47 |
|
| 48 |
$this->add_control( |
| 49 |
'source_type', |
| 50 |
[ |
| 51 |
'label' => esc_html__('Source', 'king-addons'), |
| 52 |
'type' => Controls_Manager::SELECT, |
| 53 |
'options' => [ |
| 54 |
'built_in' => esc_html__('Built-in Templates', 'king-addons'), |
| 55 |
'page' => esc_html__('WordPress Page', 'king-addons'), |
| 56 |
'elementor' => esc_html__('Elementor Template', 'king-addons'), |
| 57 |
], |
| 58 |
'default' => 'built_in', |
| 59 |
] |
| 60 |
); |
| 61 |
|
| 62 |
$this->add_control( |
| 63 |
'template_id', |
| 64 |
[ |
| 65 |
'label' => esc_html__('Built-in Template', 'king-addons'), |
| 66 |
'type' => Controls_Manager::SELECT, |
| 67 |
'options' => $this->get_template_options(), |
| 68 |
'default' => 'minimal', |
| 69 |
'condition' => [ |
| 70 |
'source_type' => 'built_in', |
| 71 |
], |
| 72 |
] |
| 73 |
); |
| 74 |
|
| 75 |
$this->add_control( |
| 76 |
'page_id', |
| 77 |
[ |
| 78 |
'label' => esc_html__('Select Page', 'king-addons'), |
| 79 |
'type' => Controls_Manager::SELECT, |
| 80 |
'options' => $this->get_pages_options(), |
| 81 |
'default' => '', |
| 82 |
'condition' => [ |
| 83 |
'source_type' => 'page', |
| 84 |
], |
| 85 |
] |
| 86 |
); |
| 87 |
|
| 88 |
$this->add_control( |
| 89 |
'elementor_id', |
| 90 |
[ |
| 91 |
'label' => esc_html__('Elementor Template', 'king-addons'), |
| 92 |
'type' => Controls_Manager::SELECT, |
| 93 |
'options' => $this->get_elementor_templates(), |
| 94 |
'default' => '', |
| 95 |
'condition' => [ |
| 96 |
'source_type' => 'elementor', |
| 97 |
], |
| 98 |
] |
| 99 |
); |
| 100 |
|
| 101 |
$this->add_control( |
| 102 |
'theme_override', |
| 103 |
[ |
| 104 |
'label' => esc_html__('Theme Override', 'king-addons'), |
| 105 |
'type' => Controls_Manager::SELECT, |
| 106 |
'options' => [ |
| 107 |
'' => esc_html__('Default', 'king-addons'), |
| 108 |
'dark' => esc_html__('Dark', 'king-addons'), |
| 109 |
'light' => esc_html__('Light', 'king-addons'), |
| 110 |
], |
| 111 |
'default' => '', |
| 112 |
] |
| 113 |
); |
| 114 |
|
| 115 |
$this->add_control( |
| 116 |
'full_height', |
| 117 |
[ |
| 118 |
'label' => esc_html__('Full Height', 'king-addons'), |
| 119 |
'type' => Controls_Manager::SWITCHER, |
| 120 |
'default' => '', |
| 121 |
] |
| 122 |
); |
| 123 |
|
| 124 |
$this->end_controls_section(); |
| 125 |
|
| 126 |
Core::renderProFeaturesSection($this, '', Controls_Manager::RAW_HTML, 'maintenance-page', [ |
| 127 |
'Private site password protection', |
| 128 |
'Rule-based access control', |
| 129 |
'Multiple schedules and recurring windows', |
| 130 |
'Analytics and integrations' |
| 131 |
]); |
| 132 |
} |
| 133 |
|
| 134 |
private function get_template_options(): array |
| 135 |
{ |
| 136 |
return [ |
| 137 |
'minimal' => esc_html__('Minimal', 'king-addons'), |
| 138 |
'dark' => esc_html__('Dark', 'king-addons'), |
| 139 |
'gradient' => esc_html__('Gradient', 'king-addons'), |
| 140 |
'countdown' => esc_html__('Coming Soon Countdown', 'king-addons'), |
| 141 |
'progress' => esc_html__('Maintenance Progress', 'king-addons'), |
| 142 |
'subscribe' => esc_html__('Simple Subscribe', 'king-addons'), |
| 143 |
'product-launch' => esc_html__('Product Launch', 'king-addons'), |
| 144 |
'construction' => esc_html__('Under Construction', 'king-addons'), |
| 145 |
'split' => esc_html__('Split Layout', 'king-addons'), |
| 146 |
'logo' => esc_html__('Centered Logo', 'king-addons'), |
| 147 |
]; |
| 148 |
} |
| 149 |
|
| 150 |
private function get_pages_options(): array |
| 151 |
{ |
| 152 |
$pages = get_pages([ |
| 153 |
'sort_column' => 'post_title', |
| 154 |
'sort_order' => 'ASC', |
| 155 |
'post_status' => 'publish', |
| 156 |
]); |
| 157 |
|
| 158 |
$options = [ |
| 159 |
'' => esc_html__('Select a page', 'king-addons'), |
| 160 |
]; |
| 161 |
|
| 162 |
foreach ($pages as $page) { |
| 163 |
$options[$page->ID] = $page->post_title; |
| 164 |
} |
| 165 |
|
| 166 |
return $options; |
| 167 |
} |
| 168 |
|
| 169 |
private function get_elementor_templates(): array |
| 170 |
{ |
| 171 |
if (!class_exists('\\Elementor\\Plugin')) { |
| 172 |
return [ |
| 173 |
'' => esc_html__('Elementor not active', 'king-addons'), |
| 174 |
]; |
| 175 |
} |
| 176 |
|
| 177 |
$templates = get_posts([ |
| 178 |
'post_type' => 'elementor_library', |
| 179 |
'post_status' => 'publish', |
| 180 |
'posts_per_page' => 50, |
| 181 |
'orderby' => 'title', |
| 182 |
'order' => 'ASC', |
| 183 |
]); |
| 184 |
|
| 185 |
$options = [ |
| 186 |
'' => esc_html__('Select a template', 'king-addons'), |
| 187 |
]; |
| 188 |
|
| 189 |
foreach ($templates as $template) { |
| 190 |
$options[$template->ID] = $template->post_title; |
| 191 |
} |
| 192 |
|
| 193 |
return $options; |
| 194 |
} |
| 195 |
|
| 196 |
protected function render(): void |
| 197 |
{ |
| 198 |
$settings = $this->get_settings_for_display(); |
| 199 |
$source = $settings['source_type'] ?? 'built_in'; |
| 200 |
|
| 201 |
$shortcode = '[kng_maintenance_page'; |
| 202 |
|
| 203 |
if ($source === 'page' && !empty($settings['page_id'])) { |
| 204 |
$shortcode .= ' id="' . esc_attr($settings['page_id']) . '" type="page"'; |
| 205 |
} elseif ($source === 'elementor' && !empty($settings['elementor_id'])) { |
| 206 |
$shortcode .= ' id="' . esc_attr($settings['elementor_id']) . '" type="elementor"'; |
| 207 |
} else { |
| 208 |
$shortcode .= ' id="' . esc_attr($settings['template_id'] ?? 'minimal') . '"'; |
| 209 |
} |
| 210 |
|
| 211 |
if (!empty($settings['theme_override'])) { |
| 212 |
$shortcode .= ' theme="' . esc_attr($settings['theme_override']) . '"'; |
| 213 |
} |
| 214 |
|
| 215 |
if (!empty($settings['full_height'])) { |
| 216 |
$shortcode .= ' full_height="true"'; |
| 217 |
} |
| 218 |
|
| 219 |
$shortcode .= ']'; |
| 220 |
|
| 221 |
echo do_shortcode($shortcode); |
| 222 |
} |
| 223 |
} |
| 224 |
|