-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplugin.php
More file actions
215 lines (170 loc) · 5.03 KB
/
Copy pathplugin.php
File metadata and controls
215 lines (170 loc) · 5.03 KB
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
<?php
namespace UnregisterElementor;
use Elementor\Utils;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Main class plugin
*/
class Plugin {
/**
* @var Plugin
*/
private static $_instance;
/**
* @var Manager
*/
public $modules_manager;
/**
* @deprecated
*
* @return string
*/
public function get_version() {
return UNREGISTER_ELEMENTOR_WIDGETS_VERSION;
}
/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0.0
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'unregister-elementor' ), '1.0.0' );
}
/**
* Disable unserializing of the class
*
* @since 1.0.0
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'unregister-elementor' ), '1.0.0' );
}
/**
* @return \Elementor\Plugin
*/
public static function elementor() {
return \Elementor\Plugin::$instance;
}
/**
* @return Plugin
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
private function includes() {
require UNREGISTER_ELEMENTOR_WIDGETS_PATH . 'includes/modules-manager.php';
}
public function autoload( $class ) {
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
return;
}
$has_class_alias = isset( $this->classes_aliases[ $class ] );
// Backward Compatibility: Save old class name for set an alias after the new class is loaded
if ( $has_class_alias ) {
$class_alias_name = $this->classes_aliases[ $class ];
$class_to_load = $class_alias_name;
} else {
$class_to_load = $class;
}
if ( ! class_exists( $class_to_load ) ) {
$filename = strtolower(
preg_replace(
[ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
[ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
$class_to_load
)
);
$filename = UNREGISTER_ELEMENTOR_WIDGETS_PATH . $filename . '.php';
if ( is_readable( $filename ) ) {
include( $filename );
}
}
if ( $has_class_alias ) {
class_alias( $class_alias_name, $class );
}
}
public function enqueue_styles() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$direction_suffix = is_rtl() ? '-rtl' : '';
wp_enqueue_style(
'unregister-elementor',
UNREGISTER_ELEMENTOR_WIDGETS_ASSETS_URL . 'css/frontend' . $direction_suffix . $suffix . '.css',
[],
UNREGISTER_ELEMENTOR_WIDGETS_VERSION
);
}
public function enqueue_frontend_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script(
'elementor-quick-start-frontend',
UNREGISTER_ELEMENTOR_WIDGETS_URL . 'assets/js/frontend' . $suffix . '.js',
[
'jquery',
],
UNREGISTER_ELEMENTOR_WIDGETS_VERSION,
true
);
$locale_settings = [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'elementor-quick-start-frontend' ),
];
wp_localize_script(
'elementor-quick-start-frontend',
'UnregisterElementorFrontendConfig',
apply_filters( 'unregister_elementor_widgets/frontend/localize_settings', $locale_settings )
);
}
public function enqueue_editor_scripts() {
$suffix = Utils::is_script_debug() ? '' : '.min';
}
public function register_frontend_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
}
public function enqueue_editor_styles() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
}
public function elementor_init() {
$this->modules_manager = new Manager();
$elementor = \Elementor\Plugin::$instance;
// Add element category in panel
$elementor->elements_manager->add_category(
'quick-start-elements',
[
'title' => __( 'Quick Start Elements', 'unregister-elementor' ),
'icon' => 'font',
],
1
);
$elementor->editor->add_editor_template( __DIR__ . '/includes/templates/editor.php' );
do_action( 'unregister_elementor_widgets/init' );
}
private function setup_hooks() {
add_action( 'elementor/init', [ $this, 'elementor_init' ] );
add_action( 'elementor/frontend/before_register_scripts', [ $this, 'register_frontend_scripts' ] );
add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_editor_styles' ] );
add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'enqueue_frontend_scripts' ] );
add_action( 'elementor/frontend/after_enqueue_styles', [ $this, 'enqueue_styles' ] );
}
/**
* Plugin constructor.
*/
private function __construct() {
spl_autoload_register( [ $this, 'autoload' ] );
$this->includes();
$this->setup_hooks();
}
}
if ( ! defined( 'UNREGISTER_ELEMENTOR_WIDGETS_TESTS' ) ) {
// In tests we run the instance manually.
Plugin::instance();
}