| 1 |
<?php |
| 2 |
/** |
| 3 |
* Wishlist Page Widget. |
| 4 |
* |
| 5 |
* @package King_Addons |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace King_Addons; |
| 9 |
|
| 10 |
use Elementor\Controls_Manager; |
| 11 |
use Elementor\Widget_Base; |
| 12 |
use King_Addons\Wishlist\Wishlist_Frontend; |
| 13 |
use King_Addons\Wishlist\Wishlist_Renderer; |
| 14 |
use King_Addons\Wishlist\Wishlist_Service; |
| 15 |
|
| 16 |
if (!defined('ABSPATH')) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Renders a wishlist page/table inside Elementor. |
| 22 |
*/ |
| 23 |
class Wishlist_Page extends Widget_Base |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Widget slug. |
| 27 |
* |
| 28 |
* @return string Widget name. |
| 29 |
*/ |
| 30 |
public function get_name(): string |
| 31 |
{ |
| 32 |
return 'king-addons-wishlist-page'; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Widget title. |
| 37 |
* |
| 38 |
* @return string Widget title. |
| 39 |
*/ |
| 40 |
public function get_title(): string |
| 41 |
{ |
| 42 |
return esc_html__('Wishlist Page', 'king-addons'); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Widget icon. |
| 47 |
* |
| 48 |
* @return string Icon class. |
| 49 |
*/ |
| 50 |
public function get_icon(): string |
| 51 |
{ |
| 52 |
return 'king-addons-icon king-addons-wishlist-page'; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Widget categories. |
| 57 |
* |
| 58 |
* @return array<int, string> Categories. |
| 59 |
*/ |
| 60 |
public function get_categories(): array |
| 61 |
{ |
| 62 |
return ['king-addons-woo']; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Style dependencies. |
| 67 |
* |
| 68 |
* @return array<int, string> Style handles. |
| 69 |
*/ |
| 70 |
public function get_style_depends(): array |
| 71 |
{ |
| 72 |
return [ |
| 73 |
'king-addons-wishlist', |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Script dependencies. |
| 79 |
* |
| 80 |
* @return array<int, string> Script handles. |
| 81 |
*/ |
| 82 |
public function get_script_depends(): array |
| 83 |
{ |
| 84 |
return [ |
| 85 |
'king-addons-wishlist', |
| 86 |
]; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Register controls. |
| 91 |
* |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public function get_custom_help_url() |
| 95 |
{ |
| 96 |
return 'mailto:[email protected]?subject=Bug Report - King Addons&body=Please describe the issue'; |
| 97 |
} |
| 98 |
|
| 99 |
protected function register_controls(): void |
| 100 |
{ |
| 101 |
$this->start_controls_section( |
| 102 |
'kng_page_content', |
| 103 |
[ |
| 104 |
'label' => esc_html__('Wishlist', 'king-addons'), |
| 105 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
'kng_wishlist_id', |
| 111 |
[ |
| 112 |
'label' => esc_html__('Wishlist ID', 'king-addons'), |
| 113 |
'type' => Controls_Manager::TEXT, |
| 114 |
'description' => esc_html__('Leave empty to use the active wishlist.', 'king-addons'), |
| 115 |
] |
| 116 |
); |
| 117 |
|
| 118 |
$this->end_controls_section(); |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Render wishlist page markup. |
| 123 |
* |
| 124 |
* @return void |
| 125 |
*/ |
| 126 |
protected function render(): void |
| 127 |
{ |
| 128 |
$settings = $this->get_settings_for_display(); |
| 129 |
$service = new Wishlist_Service(); |
| 130 |
$renderer = new Wishlist_Renderer($service); |
| 131 |
$frontend = new Wishlist_Frontend($service, $renderer); |
| 132 |
|
| 133 |
echo $frontend->shortcode_page([ |
| 134 |
'wishlist_id' => $settings['kng_wishlist_id'] ?? '', |
| 135 |
]); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|