-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
executable file
·238 lines (203 loc) · 5.2 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
namespace ElementreeAddons;
if (!defined('ABSPATH')) {
exit('Press Enter to proceed...');
}
/**
* ElementreeAddons plugin.
*
* @since 1.0.0
*/
class ElementreeAddons {
/**
* Widgets filename.
*
* get the all ElementreeAddons widgets by the filename, which is in: __DIR__/widgets/).
*
* The "filename" Must match there class name similar to - search-box => Widget_SearchBox
*
* @since 1.0.0
* @access private
*
* @var widgets_filename
*/
private $widgets_filename = [
'home-page',
'results-page',
'onboarding-page',
'expert-page',
'user-login',
'dashboard',
'freelance-dashboard',
'header',
'footer',
'elementor-search',
'account-button'
];
/**
* Instance.
*
* Holds the plugin instance.
*
* @since 1.0.0
* @access private
* @static
*
* @var $instance
*/
private static $instance = null;
/**
* Settings.
*
* Holds the plugin settings.
*
* @since 1.0.0
* @access private
*
* @var Settings
*/
private static $settings = null;
/**
* Register Categories.
*
* Add a new widget type to the list of registered widget types.
*
* @since 1.0.0
* @access public
*
*/
public function registerCategories()
{
\Elementor\Plugin::instance()->elements_manager->add_category(
'elementree-addons',
array(
'title' => __('Elementree Addons', 'elementree-addons'),
'icon' => 'fa fa-plug'
)
);
}
/**
* Register widget type.
*
* Add a new widget type to the list of registered widget types.
*
* @since 1.0.0
* @access public
*
*/
public function registerWidgets() {
require __DIR__ . '/widgets/AbstractWidget.php';
foreach ( $this->widgets_filename as $widget_filename ) {
include( __DIR__ . '/widgets/' . $widget_filename . '.php' );
$class_name = str_replace( '-', '_', $widget_filename );
$class_name = __NAMESPACE__ . '\Widget_' . $class_name;
\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new $class_name() );
}
}
/**
* Instance.
*
* Ensures only one instance of the plugin class is loaded or can be loaded.
*
* @since 1.0.0
* @access public
* @static
*
* @return Plugin An instance of the class.
*/
public static function instance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
}
/**
* loading scripts on init
*/
// public function elementor_experts_load_scripts_admin(){
// // remove default style
// add_action('wp_enqueue_scripts', function() {
// wp_dequeue_style( 'twentynineteen-style' );
// wp_dequeue_style( 'experts-style' );
// wp_dequeue_style( 'hello-elementor-child' );
// wp_dequeue_style( 'hello-elementor' );
// }, 100);
// wp_enqueue_media();
// }
// public static function elementor_experts_load_settings(){
// // if (is_null(self::$settings)) {
// // self::$settings = new ExpertsSettings();
// // }
// }
/**
* Plugin constructor.
*
* Initializing Elementor Experts plugin.
*
* @since 1.0.0
* @access private
*/
private function __construct() {
// Check required version
if (!version_compare(ELEMENTOR_VERSION, '1.8.0', '>=')) {
return;
}
// add_action( 'admin_enqueue_scripts', array($this, 'elementor_experts_load_scripts_admin' ));
// add_action( 'wp_enqueue_scripts', array($this, 'elementor_experts_load_scripts_admin' ));
//add_action( 'admin_enqueue_scripts', array($this, 'elementor_experts_load_settings'));
add_action( 'elementor/init', array($this, 'registerCategories') );
add_action( 'elementor/widgets/widgets_registered', array($this, 'registerWidgets') );
//
// register a new route for getting the settings values
//
// add_action('rest_api_init', function () {
// register_rest_route( 'experts/v1/api', 'settings',array(
// 'methods' => 'GET',
// 'callback' => array($this,'get_experts_settings_json'),
// 'permission_callback' => function () {
// // to implement later
// return true;
// }
// ));
// });
}
// sending the settings values when reaching the route:
// /wp-json/experts/v1/api/settings
//
public function get_experts_settings_json(){
if(is_null(self::$settings)){
self::$settings = new ExpertsSettings();
}
self::$settings->get_experts_settings_json();
}
}
add_action('elementor/loaded', function() {
ElementreeAddons::instance();
if(is_admin()){
// ElementreeAddons::elementor_experts_load_settings();
}
});
add_action('admin_menu', function() {
// add_menu_page(
// $page_title,
// $menu_title,
// $capability,
// $menu_slug,
// function() use ( $widget_name, $settings ) {
// echo \Elementree\Plugin::$instance->get_markup($widget_name, $settings);
// },
// $icon_url,
// $position
// );
// add_submenu_page(
// $parent_slug,
// $page_title,
// $menu_title,
// $capability,
// $menu_slug,
// function() use ( $widget_name, $settings ) {
// echo \Elementree\Plugin::$instance->get_markup($widget_name, $settings);
// },
// $position
// );
});