forked from norewp/elementor-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
193 lines (156 loc) · 4.56 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
<?php
namespace ElementorStarter;
use Elementor\Utils;
use Elementor\Controls_Manager;
if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
/**
* Main class plugin
*/
class Plugin {
/**
* @var Plugin
*/
private static $_instance;
/**
* @var Manager
*/
private $_modules_manager;
/**
* @var array
*/
private $_localize_settings = [];
/**
* @return string
*/
public function get_version() {
return ELEMENTOR_STARTER_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?', 'elementor-starter' ), '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?', 'elementor-starter' ), '1.0.0' );
}
/**
* @return Plugin
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
private function _includes() {
require ELEMENTOR_STARTER_PATH . 'includes/modules-manager.php';
}
public function autoload( $class ) {
if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
return;
}
$filename = strtolower(
preg_replace(
[ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
[ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
$class
)
);
$filename = ELEMENTOR_STARTER_PATH . $filename . '.php';
if ( is_readable( $filename ) ) {
include( $filename );
}
}
public function get_localize_settings() {
return $this->_localize_settings;
}
public function add_localize_settings( $setting_key, $setting_value = null ) {
if ( is_array( $setting_key ) ) {
$this->_localize_settings = array_replace_recursive( $this->_localize_settings, $setting_key );
return;
}
if ( ! is_array( $setting_value ) || ! isset( $this->_localize_settings[ $setting_key ] ) || ! is_array( $this->_localize_settings[ $setting_key ] ) ) {
$this->_localize_settings[ $setting_key ] = $setting_value;
return;
}
$this->_localize_settings[ $setting_key ] = array_replace_recursive( $this->_localize_settings[ $setting_key ], $setting_value );
}
public function enqueue_styles() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$direction_suffix = is_rtl() ? '-rtl' : '';
wp_enqueue_style(
'elementor-starter',
ELEMENTOR_STARTER_URL . 'assets/css/frontend' . $direction_suffix . $suffix . '.css',
[],
Plugin::instance()->get_version()
);
}
public function enqueue_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script(
'elementor-starter-js',
ELEMENTOR_STARTER_URL . 'assets/js/frontend' . $suffix . '.js',
[
'jquery',
],
Plugin::instance()->get_version(),
true
);
wp_localize_script(
'elementor-starter-js',
'ElementorStarterFrontendConfig', // This is used in the js file to group all of your scripts together
[
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'elementor-starter-js' ),
]
);
}
public function enqueue_panel_scripts() {}
public function enqueue_panel_styles() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
}
public function elementor_init() {
$this->_modules_manager = new Manager();
// Add element category in panel
\Elementor\Plugin::instance()->elements_manager->add_category(
'elementor-start-widgets', // This is the name of your addon's category and will be used to group your widgets/elements in the Edit sidebar pane!
[
'title' => __( 'Starter Widgets', 'elementor-starter' ), // The title of your modules category - keep it simple and short!
'icon' => 'font',
],
1
);
}
protected function add_actions() {
add_action( 'elementor/init', [ $this, 'elementor_init' ] );
add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'enqueue_scripts' ], 998 );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 998 );
}
/**
* Plugin constructor.
*/
private function __construct() {
spl_autoload_register( [ $this, 'autoload' ] );
$this->_includes();
$this->add_actions();
}
}
if ( ! defined( 'ELEMENTOR_STARTER_TESTS' ) ) {
// In tests we run the instance manually.
Plugin::instance();
}