PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-dev3
Elementor Website Builder – more than just a page builder v4.1.0-dev3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / common / modules / finder / module.php

module.php in Elementor Website Builder – more than just a page builder 4.1.0-dev3, at core/common/modules/finder/module.php

133 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Core\Common\Modules\Finder;
4
5 use Elementor\Core\Base\Module as BaseModule;
6 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
7 use Elementor\Plugin;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 /**
14 * Finder Module
15 *
16 * Responsible for initializing Elementor Finder functionality
17 */
18 class Module extends BaseModule {
19
20 /**
21 * Categories manager.
22 *
23 * @access private
24 *
25 * @var Categories_Manager
26 */
27 private $categories_manager;
28
29 /**
30 * Module constructor.
31 *
32 * @since 2.3.0
33 * @access public
34 */
35 public function __construct() {
36 $this->categories_manager = new Categories_Manager();
37
38 $this->add_template();
39
40 add_action( 'elementor/ajax/register_actions', [ $this, 'register_ajax_actions' ] );
41 }
42
43 /**
44 * Get name.
45 *
46 * @since 2.3.0
47 * @access public
48 *
49 * @return string
50 */
51 public function get_name() {
52 return 'finder';
53 }
54
55 /**
56 * Add template.
57 *
58 * @since 2.3.0
59 * @access public
60 */
61 public function add_template() {
62 Plugin::$instance->common->add_template( __DIR__ . '/template.php' );
63 }
64
65 /**
66 * Register ajax actions.
67 *
68 * @since 2.3.0
69 * @access public
70 *
71 * @param Ajax $ajax
72 */
73 public function register_ajax_actions( Ajax $ajax ) {
74 $ajax->register_ajax_action( 'finder_get_category_items', [ $this, 'ajax_get_category_items' ] );
75 }
76
77 /**
78 * Ajax get category items.
79 *
80 * @since 2.3.0
81 * @access public
82 *
83 * @param array $data
84 *
85 * @return array
86 *
87 * @throws \Exception If finder category registration fails or validation errors occur.
88 */
89 public function ajax_get_category_items( array $data ) {
90 if ( ! current_user_can( 'manage_options' ) ) {
91 throw new \Exception( 'Access denied.' );
92 }
93
94 $category = $this->categories_manager->get_categories( $data['category'] );
95
96 return $category->get_category_items( $data );
97 }
98
99 /**
100 * Get init settings.
101 *
102 * @since 2.3.0
103 * @access protected
104 *
105 * @return array
106 */
107 protected function get_init_settings() {
108 $categories = $this->categories_manager->get_categories();
109
110 $categories_data = [];
111
112 foreach ( $categories as $category_name => $category ) {
113 $categories_data[ $category_name ] = array_merge( $category->get_settings(), [ 'name' => $category_name ] );
114 }
115
116 /**
117 * Finder categories.
118 *
119 * Filters the list of finder categories. This hook is used to manage Finder
120 * categories - to add new categories, remove and edit existing categories.
121 *
122 * @since 2.3.0
123 *
124 * @param array $categories_data A list of finder categories.
125 */
126 $categories_data = apply_filters( 'elementor/finder/categories', $categories_data );
127
128 return [
129 'data' => $categories_data,
130 ];
131 }
132 }
133