PluginProbe
Download Manager Addons for Elementor / trunk
Download Manager Addons for Elementor vtrunk
trunk 1.0.5 1.2.3 1.2.5 1.3.0
wpdm-elementor / src / widgets / PackageWidget.php

PackageWidget.php in Download Manager Addons for Elementor trunk, at src/widgets/PackageWidget.php

88 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDM\Elementor\Widgets;
4
5 /**
6 * Single Package Widget.
7 * Embeds a single WPDM package.
8 */
9 class PackageWidget extends BaseWidget
10 {
11 /**
12 * Expected settings keys for this widget.
13 */
14 private const SETTINGS_KEYS = ['pid', 'ltemplate'];
15
16 /**
17 * Settings sanitization rules.
18 */
19 private const SANITIZERS = [
20 'pid' => 'int',
21 'ltemplate' => 'text',
22 ];
23
24 public function get_name()
25 {
26 return 'wpdmpackage';
27 }
28
29 public function get_title()
30 {
31 return __('Package', WPDM_ELEMENTOR);
32 }
33
34 public function get_icon()
35 {
36 return 'eicon-download-button';
37 }
38
39 protected function register_controls()
40 {
41 $this->start_controls_section(
42 'content_section',
43 [
44 'label' => __('Parameters', WPDM_ELEMENTOR),
45 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
46 ]
47 );
48
49 $this->add_control(
50 'pid',
51 [
52 'label' => __('Package', WPDM_ELEMENTOR),
53 'type' => \Elementor\Controls_Manager::SELECT2,
54 'placeholder' => __('Package', WPDM_ELEMENTOR),
55 'select2options' => $this->getPackageSearchConfig()
56 ]
57 );
58
59 $this->add_control(
60 'ltemplate',
61 [
62 'label' => __('Link Template', WPDM_ELEMENTOR),
63 'type' => \Elementor\Controls_Manager::SELECT2,
64 'options' => $this->getLinkTemplateOptions(),
65 'default' => 'link-template-panel'
66 ]
67 );
68
69 $this->end_controls_section();
70 }
71
72 protected function render()
73 {
74 $settings = $this->getCleanSettings(self::SETTINGS_KEYS);
75 $settings = $this->sanitizeSettings($settings, self::SANITIZERS);
76
77 if (empty($settings['pid'])) {
78 return;
79 }
80
81 echo WPDM()->package->shortCodes->singlePackage([
82 'id' => $settings['pid'],
83 'template' => $settings['ltemplate']
84 ]);
85 }
86 }
87
88