-
Notifications
You must be signed in to change notification settings - Fork 1
/
amadeus-elementor.php
443 lines (390 loc) · 12.6 KB
/
amadeus-elementor.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<?php
/**
* Plugin Name: Amadeus Elementor
* Plugin URI: https://www.amadeus-elementor.com/
* Description: Provides a collection of powerful, fully customizable, and extendable widgets on top of any Elementor version and works independently with any WordPress theme.
* Version: 2.0.0
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: BAKKBONE Australia
* Author URI: https://www.bakkbone.com.au/
* License: GNU General Public License (GPL) 3.0 or later
* License URI: https://www.gnu.org/licenses/gpl.html
* Tested up to: 6.2.2
* WC tested up to: 7.8.0
* Elementor tested up to: 3.14.0
* Elementor Pro tested up to: 3.14.0
* Text Domain: amadeus-elementor
* Domain Path: /lang
*
* This plugin is a fork of UranusWP's now-defunct "Zeus Elementor".
**/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Returns the main instance of Amadeus_Elementor to prevent the need to use globals.
*
* @since 1.0.0
* @return object Amadeus_Elementor
*/
function amadeus_elementor() {
return Amadeus_Elementor::instance();
}
amadeus_elementor();
/**
* Main Amadeus_Elementor Class
*
* @class Amadeus_Elementor
* @version 1.0.0
* @since 1.0.0
* @package Amadeus_Elementor
*/
final class Amadeus_Elementor {
/**
* Amadeus_Elementor The single instance of Amadeus_Elementor.
*
* @var object
* @access private
* @since 1.0.0
*/
private static $instance = null;
/**
* The token.
*
* @var string
* @access public
* @since 1.0.0
*/
public $token;
/**
* The version number.
*
* @var string
* @access public
* @since 1.0.0
*/
public $version;
// Admin - Start
/**
* The admin object.
*
* @var object
* @access public
* @since 1.0.0
*/
public $admin;
/**
* Current theme template.
*
* @var String
*/
public $template;
/**
* Constructor function.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __construct() {
$this->token = 'amadeus-elementor';
$this->plugin_url = plugin_dir_url( __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->version = '2.0.0';
$this->template = get_template();
define( 'AMADEUS_ELEMENTOR__FILE__', __FILE__ );
define( 'AMADEUS_ELEMENTOR_PATH', $this->plugin_path );
define( 'AMADEUS_URL', plugins_url( '/', AMADEUS_ELEMENTOR__FILE__ ) );
define( 'AMADEUS_ASSETS_URL', AMADEUS_URL . 'assets/' );
define( 'AMADEUS_ELEMENTOR_VERSION', $this->version );
if($this->is_zeus_still_here()){
add_action( 'init', array( $this, 'thrill_kratos' ) );
}
add_action('init', array($this, 'please_kratos'));
// If Elementor is not activated.
if(!in_array('elementor/elementor.php', apply_filters("active_plugins", get_option("active_plugins")))){
add_action( 'admin_notices', array( $this, 'show_notices' ), 30 );
} else {
// Widgets.
$GLOBALS['amadeus_widgets'] = require_once AMADEUS_ELEMENTOR_PATH . 'widgets.php';
register_activation_hook( __FILE__, array( $this, 'install' ) );
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
add_action( 'plugins_loaded', array( $this, 'setup' ) );
register_activation_hook( __FILE__, array( $this, 'save_widgets_db' ) );
}
}
public static function is_zeus_still_here() {
$file_path = 'zeus-elementor/zeus-elementor.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$installed_plugins = get_plugins();
return isset( $installed_plugins[ $file_path ] );
}
public static function please_kratos(){
if(!get_option('is_kratos_pleased')){
update_option('amadeus_settings', get_option('zeus_settings'));
if(get_option('zeus_settings')){
delete_option('zeus_settings');
}
if(get_option('zeus_mailchimp_api_key')){
update_option('amadeus_mailchimp_api_key', get_option('zeus_mailchimp_api_key'));
delete_option('zeus_mailchimp_api_key');
}
if(get_option('zeus_google_map_api_key')){
update_option('amadeus_google_maps_api_key', get_option('zeus_google_map_api_key'));
delete_option('zeus_google_map_api_key');
}
if(get_option('zeus_review_notice_zeus_installed_time')){
delete_option('zeus_review_notice_zeus_installed_time');
}
if(get_option('olympus_notice_zeus_installed_time')){
delete_option('olympus_notice_zeus_installed_time');
}
if(get_option('zeus-elementor-version')){
delete_option('zeus-elementor-version');
}
$args = [
'numberposts' => -1,
'post_type' => 'any',
];
$posts = get_posts($args);
foreach($posts as $post){
$id = $post->ID;
error_log($id);
$content = wp_kses_post($post->post_content);
$modifiedcontent = wp_kses_post(preg_replace('/<!-- \.zeus/','<!-- .amadeus', $content));
$newedata = preg_replace('/zeus/', 'amadeus', get_post_meta($id, '_elementor_data', true));
$ecu = unserialize(get_post_meta($id, '_elementor_controls_usage', true));
$newecu = [];
foreach($ecu as $k => $v){
if(preg_match('/zeus/', $k)){
$kk = preg_replace('/zeus/', 'amadeus', $k);
$newecu[$kk] = $v;
} else {
$newecu[$k] = $v;
}
}
$newecu = serialize($newecu);
$postdata = [
'ID' => $id,
'post_content' => $modifiedcontent,
'meta_input' => [
'_elementor_data' => $newedata,
'_elementor_controls_usage' => $newecu
]
];
wp_update_post($postdata);
}
update_option('is_kratos_pleased', 1, true);
}
}
public static function thrill_kratos(){
if(in_array('zeus-elementor/zeus-elementor.php', apply_filters("active_plugins", get_option("active_plugins")))){
deactivate_plugins('zeus-elementor/zeus-elementor.php');
}
if(function_exists('request_filesystem_credentials')){
$deleted = delete_plugins(['zeus-elementor/zeus-elementor.php']);
if(is_wp_error($deleted)){
$msg = $deleted->get_error_messages;
error_log($msg);
}
} else {
add_filter('all_plugins', function($all_plugins){
unset($all_plugins['zeus-elementor/zeus-elementor.php']);
return $all_plugins;
});
add_filter('plugin_action_links_amadeus-elementor/amadeus-elementor.php', function($links){
$format = '<a href="%1$s" title="%2$s">%3$s</a>';
return array_merge(
$links,
array(
'<span class="delete">'.sprintf(
$format,
wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked=zeus-elementor%2Fzeus-elementor.php', 'bulk-plugins' ),
__('Delete Zeus Elementor (Recommended)', 'amadeus-elementor'),
__('Delete Zeus Elementor (Recommended)', 'amadeus-elementor')
).'</span>'
)
);
}, 10, 1);
}
}
/**
* Main Amadeus_Elementor Instance.
*
* Ensures only one instance of Amadeus_Elementor is loaded or can be loaded.
*
* @since 1.0.0
* @static
* @see Amadeus_Elementor()
* @return Amadeus_Elementor Main instance
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
} // End instance()
/**
* Load the localisation file.
*
* @access public
* @since 1.0.0
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'amadeus-elementor', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/**
* Cloning is forbidden.
*
* @since 1.0.0
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 1.0.0
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
}
/**
* Installation.
* Runs on activation. Logs the version number and assigns a notice message to a WordPress option.
*
* @access public
* @since 1.0.0
* @return void
*/
public function install() {
$this->log_version_number();
}
/**
* Log the plugin version number.
*
* @access private
* @since 1.0.0
* @return void
*/
private function log_version_number() {
// Log the version number.
update_option( $this->token . '-version', $this->version );
}
/**
* Check if Elementor is installed.
*
* @access private
* @since 1.0.1
* @return void
*/
private function is_elementor_installed() {
$file_path = 'elementor/elementor.php';
$installed_plugins = get_plugins();
return isset( $installed_plugins[ $file_path ] );
}
/**
* Add notice if Elementor is not activated.
*
* @return void
*/
public function show_notices() {
$screen = get_current_screen();
if ( isset( $screen->parent_file ) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id ) {
return;
}
$plugin = 'elementor/elementor.php';
if ( $this->is_elementor_installed() ) {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
$activation_url = wp_nonce_url( 'plugins.php?action=activate&plugin=' . $plugin . '&plugin_status=all&paged=1&s', 'activate-plugin_' . $plugin );
$message = '<p>' . __( 'Amadeus Elementor is not working because you need to activate the Elementor plugin.', 'amadeus-elementor' ) . '</p>';
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $activation_url, __( 'Activate Elementor Now', 'amadeus-elementor' ) ) . '</p>';
} else {
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), 'install-plugin_elementor' );
$message = '<p>' . __( 'Amadeus Elementor is not working because you need to install the Elementor plugin.', 'amadeus-elementor' ) . '</p>';
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $install_url, __( 'Install Elementor Now', 'amadeus-elementor' ) ) . '</p>';
}
echo '<div class="error">' . $message . '</div>';
}
/**
* Setup all the things.
*
* @return void
*/
public function setup() {
require AMADEUS_ELEMENTOR_PATH . 'includes/class-amadeus-notices.php';
require AMADEUS_ELEMENTOR_PATH . 'includes/plugin.php';
require_once AMADEUS_ELEMENTOR_PATH . 'includes/admin/settings.php';
require_once AMADEUS_ELEMENTOR_PATH . 'includes/helpers.php';
// If header or footer selected.
if ( amadeus_header_enabled() || amadeus_footer_enabled() ) {
if ( 'hello-elementor' === $this->template ) {
require_once AMADEUS_ELEMENTOR_PATH . 'includes/themes/class-hello-elementor-theme.php';
} elseif ( 'generatepress' === $this->template ) {
require_once AMADEUS_ELEMENTOR_PATH . 'includes/themes/class-generatepress-theme.php';
} elseif ( 'astra' === $this->template ) {
require_once AMADEUS_ELEMENTOR_PATH . 'includes/themes/class-astra-theme.php';
} elseif ( 'oceanwp' === $this->template ) {
require_once AMADEUS_ELEMENTOR_PATH . 'includes/themes/class-oceanwp-theme.php';
} elseif ( 'storefront' === $this->template ) {
require_once AMADEUS_ELEMENTOR_PATH . 'includes/themes/class-storefront-theme.php';
} else {
require_once AMADEUS_ELEMENTOR_PATH . 'includes/themes/default/class-default-theme.php';
}
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_header_footer_scripts' ) );
}
}
/**
* Save default widgets values to database.
*
* @since 1.0.0
*/
public function save_widgets_db() {
// If the widgets are not already in the database.
if ( ! get_option( 'zeus_settings' ) ) {
$defaults = array_fill_keys( array_keys( $GLOBALS['amadeus_widgets'] ), 1 );
$elements = array_merge( $defaults, array_fill_keys( array_keys( $defaults ), true ) );
// Update new settings.
return update_option( 'zeus_settings', $elements );
}
}
/**
* Enqueue styles and scripts.
*
* @since 1.0.0
*/
public function enqueue_header_footer_scripts() {
if ( class_exists( '\Elementor\Plugin' ) ) {
$elementor = \Elementor\Plugin::instance();
$elementor->frontend->enqueue_styles();
}
if ( class_exists( '\ElementorPro\Plugin' ) ) {
$elementor_pro = \ElementorPro\Plugin::instance();
$elementor_pro->enqueue_styles();
}
if ( amadeus_header_enabled() ) {
if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
$css_file = new \Elementor\Core\Files\CSS\Post( amadeus_header_id() );
} elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
$css_file = new \Elementor\Post_CSS_File( amadeus_header_id() );
}
$css_file->enqueue();
}
if ( amadeus_footer_enabled() ) {
if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
$css_file = new \Elementor\Core\Files\CSS\Post( amadeus_footer_id() );
} elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
$css_file = new \Elementor\Post_CSS_File( amadeus_footer_id() );
}
$css_file->enqueue();
}
}
}