| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
final class Easyel_Elements_Elementor_Extension { |
| 7 |
|
| 8 |
const VERSION = EASYELEMENTS_VER; |
| 9 |
|
| 10 |
private static $_instance = null; |
| 11 |
|
| 12 |
public static function instance() { |
| 13 |
if ( is_null( self::$_instance ) ) { |
| 14 |
self::$_instance = new self(); |
| 15 |
} |
| 16 |
return self::$_instance; |
| 17 |
} |
| 18 |
|
| 19 |
public function __construct() { |
| 20 |
add_action( 'init', [ $this, 'init' ] ); |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
public function init() { |
| 25 |
// Safety checks |
| 26 |
|
| 27 |
add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] ); |
| 28 |
add_action( 'elementor/elements/categories_registered', [ $this, 'add_elementor_categories' ] ); |
| 29 |
|
| 30 |
add_filter( 'body_class', [ $this, "easy_add_extra_body_class" ] ); |
| 31 |
add_action( 'easy_header', [ $this, 'easyel_before_content_container_hfe'], 20 ); |
| 32 |
add_action( 'easy_footer', [ $this, 'easyel_after_content_container_hfe' ], 5 ); |
| 33 |
|
| 34 |
add_action( 'admin_notices', [ $this, 'easyelements_admin_notice_missing_elementor' ] ); |
| 35 |
|
| 36 |
} |
| 37 |
|
| 38 |
public function easyelements_admin_notice_missing_elementor() { |
| 39 |
|
| 40 |
$elementor = 'elementor/elementor.php'; |
| 41 |
|
| 42 |
if ( current_user_can( 'activate_plugins' ) && isset( $_GET['activate'], $_GET['_wpnonce'] ) ) { |
| 43 |
|
| 44 |
$nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : ''; |
| 45 |
|
| 46 |
if ( wp_verify_nonce( $nonce, 'activate-plugin_' . $elementor ) ) { |
| 47 |
unset( $_GET['activate'] ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
if ( ! current_user_can( 'install_plugins' ) ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
$elementor = 'elementor/elementor.php'; |
| 56 |
$elementor_path = WP_PLUGIN_DIR . '/' . $elementor; |
| 57 |
|
| 58 |
$is_installed = file_exists( $elementor_path ); |
| 59 |
$is_active = function_exists( 'is_plugin_active' ) && is_plugin_active( $elementor ); |
| 60 |
|
| 61 |
if ( $is_active ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if ( $is_installed ) { |
| 66 |
$action_url = wp_nonce_url( |
| 67 |
self_admin_url( 'plugins.php?action=activate&plugin=' . $elementor ), |
| 68 |
'activate-plugin_' . $elementor |
| 69 |
); |
| 70 |
|
| 71 |
$button_label = esc_html__( 'Activate Elementor', 'easy-elements' ); |
| 72 |
$notice_text = esc_html__( 'Easy Elements is not working because the Elementor plugin is inactive.', 'easy-elements' ); |
| 73 |
|
| 74 |
} else { |
| 75 |
$action_url = wp_nonce_url( |
| 76 |
self_admin_url( 'update.php?action=install-plugin&plugin=elementor' ), |
| 77 |
'install-plugin_elementor' |
| 78 |
); |
| 79 |
|
| 80 |
$button_label = esc_html__( 'Install Elementor', 'easy-elements' ); |
| 81 |
$notice_text = esc_html__( 'Easy Elements requires the Elementor plugin to be installed.', 'easy-elements' ); |
| 82 |
} |
| 83 |
|
| 84 |
$message = '<p>' . $notice_text . '</p>'; |
| 85 |
$message .= '<p><a href="' . esc_url( $action_url ) . '" class="button-primary">' . $button_label . '</a></p>'; |
| 86 |
|
| 87 |
printf( |
| 88 |
'<div class="notice notice-error is-dismissible">%s</div>', |
| 89 |
wp_kses_post( $message ) |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
// Container Full site |
| 94 |
public function easyel_before_content_container_hfe() { |
| 95 |
if ( is_admin() ) return; |
| 96 |
if ( function_exists( 'elementor_theme_do_location' ) && \Elementor\Plugin::$instance->preview->is_preview() ) { |
| 97 |
return; |
| 98 |
} |
| 99 |
echo '<div class="easyel-content-container">'; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Close container before HFE Footer |
| 104 |
*/ |
| 105 |
function easyel_after_content_container_hfe() { |
| 106 |
if ( is_admin() ) return; |
| 107 |
if ( function_exists( 'elementor_theme_do_location' ) && \Elementor\Plugin::$instance->preview->is_preview() ) { |
| 108 |
return; |
| 109 |
} |
| 110 |
echo '</div>'; |
| 111 |
} |
| 112 |
|
| 113 |
public function easy_add_extra_body_class( $classes ) { |
| 114 |
if ( is_plugin_active( 'easy-elements/easy-elements.php' ) ) { |
| 115 |
$classes[] = 'eel-easy-elements'; |
| 116 |
} |
| 117 |
|
| 118 |
return $classes; |
| 119 |
} |
| 120 |
|
| 121 |
public function add_elementor_categories( $elements_manager ) { |
| 122 |
$elements_manager->add_category( 'easyelements_category', [ |
| 123 |
'title' => esc_html__( 'Easy Elements', 'easy-elements' ), |
| 124 |
'icon' => 'fa fa-plug', |
| 125 |
] ); |
| 126 |
$elements_manager->add_category( 'easyelements_post_category', [ |
| 127 |
'title' => esc_html__( 'Easy Post Type Elements', 'easy-elements' ), |
| 128 |
'icon' => 'fa fa-file-alt', |
| 129 |
] ); |
| 130 |
$elements_manager->add_category( 'easyelements_header_footer_category', [ |
| 131 |
'title' => esc_html__( 'Easy Header Footer Elements', 'easy-elements' ), |
| 132 |
'icon' => 'fa fa-header', |
| 133 |
] ); |
| 134 |
$elements_manager->add_category( 'easyelements_category_form', [ |
| 135 |
'title' => esc_html__( 'Easy Elements Form', 'easy-elements' ), |
| 136 |
'icon' => 'fa fa-plug', |
| 137 |
] ); |
| 138 |
$elements_manager->add_category( 'easyelements_category_pro', [ |
| 139 |
'title' => esc_html__( 'Easy Elements Pro', 'easy-elements' ), |
| 140 |
'icon' => 'fa fa-plug', |
| 141 |
] ); |
| 142 |
} |
| 143 |
|
| 144 |
public function init_widgets() { |
| 145 |
$widgets_manager = \Elementor\Plugin::instance()->widgets_manager; |
| 146 |
|
| 147 |
$widgets = [ |
| 148 |
'site_logo' => [ |
| 149 |
'class' => '\Easyel_Site_Logo_Widget', |
| 150 |
'file' => __DIR__ . '/widgets/site-logo/site-logo.php', |
| 151 |
'tab' => 'widget', |
| 152 |
], |
| 153 |
'heading' => [ |
| 154 |
'class' => '\Easyel_Heading_Widget', |
| 155 |
'file' => __DIR__ . '/widgets/heading/heading.php', |
| 156 |
'tab' => 'widget', |
| 157 |
], |
| 158 |
'clients_logo' => [ |
| 159 |
'class' => '\Easyel_Clients_Logo__Widget', |
| 160 |
'file' => __DIR__ . '/widgets/clients-logo-grid/logo.php', |
| 161 |
'tab' => 'widget', |
| 162 |
], |
| 163 |
'icon_box' => [ |
| 164 |
'class' => '\Easyel_Icon_Box__Widget', |
| 165 |
'file' => __DIR__ . '/widgets/icon-box/icon.php', |
| 166 |
'tab' => 'widget', |
| 167 |
], |
| 168 |
'tab' => [ |
| 169 |
'class' => '\Easyel_Tab_Widget', |
| 170 |
'file' => __DIR__ . '/widgets/tab/tab.php', |
| 171 |
'tab' => 'widget', |
| 172 |
], |
| 173 |
'testimonials' => [ |
| 174 |
'class' => '\Easyel_Testimonials__Widget', |
| 175 |
'file' => __DIR__ . '/widgets/testimonials-grid/testimonials.php', |
| 176 |
'tab' => 'widget', |
| 177 |
], |
| 178 |
'team_grid' => [ |
| 179 |
'class' => '\Easyel_Team_Grid__Widget', |
| 180 |
'file' => __DIR__ . '/widgets/team-grid/team-grid.php', |
| 181 |
'tab' => 'widget', |
| 182 |
], |
| 183 |
'search' => [ |
| 184 |
'class' => '\Easyel_Search_Widget', |
| 185 |
'file' => __DIR__ . '/widgets/search/search.php', |
| 186 |
'tab' => 'widget', |
| 187 |
], |
| 188 |
'contact_box' => [ |
| 189 |
'class' => '\Easyel_Contact_Box__Widget', |
| 190 |
'file' => __DIR__ . '/widgets/contact-box/contact.php', |
| 191 |
'tab' => 'widget', |
| 192 |
], |
| 193 |
'faq' => [ |
| 194 |
'class' => '\Easyel_FAQ_Accordion_Widget', |
| 195 |
'file' => __DIR__ . '/widgets/faq/faq.php', |
| 196 |
'tab' => 'widget', |
| 197 |
], |
| 198 |
'blog_grid' => [ |
| 199 |
'class' => '\Easyel_Blog_Grid__Widget', |
| 200 |
'file' => __DIR__ . '/widgets/blog-grid/blog-grid.php', |
| 201 |
'tab' => 'widget', |
| 202 |
], |
| 203 |
'video' => [ |
| 204 |
'class' => '\Easyel_Video_Popup_Widget', |
| 205 |
'file' => __DIR__ . '/widgets/video/video.php', |
| 206 |
'tab' => 'widget', |
| 207 |
], |
| 208 |
'pricing_table' => [ |
| 209 |
'class' => '\Easyel_Pricing_Table_Widget', |
| 210 |
'file' => __DIR__ . '/widgets/pricing-table/pricing.php', |
| 211 |
'tab' => 'widget', |
| 212 |
], |
| 213 |
'pricing_list' => [ |
| 214 |
'class' => '\Easyel_Pricing_Table_List_Widget', |
| 215 |
'file' => __DIR__ . '/widgets/pricing-list/pricing-list.php', |
| 216 |
'tab' => 'widget', |
| 217 |
], |
| 218 |
'service_list' => [ |
| 219 |
'class' => '\Easyel_Service_List_Widget', |
| 220 |
'file' => __DIR__ . '/widgets/service-list/service-list.php', |
| 221 |
'tab' => 'widget', |
| 222 |
], |
| 223 |
'navigation_menu' => [ |
| 224 |
'class' => '\Easyel_Navigation_Menu_Widget', |
| 225 |
'file' => __DIR__ . '/widgets/navigation-menu/navigation-menu.php', |
| 226 |
'tab' => 'widget', |
| 227 |
], |
| 228 |
'page_title' => [ |
| 229 |
'class' => '\Easyel_Page_Title_Widget', |
| 230 |
'file' => __DIR__ . '/widgets/page-title/page-title.php', |
| 231 |
'tab' => 'widget', |
| 232 |
], |
| 233 |
'button' => [ |
| 234 |
'class' => '\Easyel_Button_Widget', |
| 235 |
'file' => __DIR__ . '/widgets/button/button.php', |
| 236 |
'tab' => 'widget', |
| 237 |
], |
| 238 |
'social_share' => [ |
| 239 |
'class' => '\Easyel_Social_Share_Widget', |
| 240 |
'file' => __DIR__ . '/widgets/social-share/social-share.php', |
| 241 |
'tab' => 'widget', |
| 242 |
], |
| 243 |
'typewriter' => [ |
| 244 |
'class' => '\Easyel_Typewriter_Widget', |
| 245 |
'file' => __DIR__ . '/widgets/typewriter/typewriter.php', |
| 246 |
'tab' => 'widget', |
| 247 |
], |
| 248 |
'social_icon' => [ |
| 249 |
'class' => '\Easyel_Social_Icon_Widget', |
| 250 |
'file' => __DIR__ . '/widgets/social-icon/social.php', |
| 251 |
'tab' => 'widget', |
| 252 |
], |
| 253 |
'breadcrumb' => [ |
| 254 |
'class' => '\Easyel_Breadcrumb_Widget', |
| 255 |
'file' => __DIR__ . '/widgets/breadcrumb/breadcrumb.php', |
| 256 |
'tab' => 'widget', |
| 257 |
], |
| 258 |
'domain_search' => [ |
| 259 |
'class' => '\Easyel_Domain_Search_Widget', |
| 260 |
'file' => __DIR__ . '/widgets/domain-search/domain-search.php', |
| 261 |
'tab' => 'widget', |
| 262 |
], |
| 263 |
'easy_offcanvas' => [ |
| 264 |
'class' => '\Easyel_Offcanvas_Widget', |
| 265 |
'file' => __DIR__ . '/widgets/offcanvas/offcanvas.php', |
| 266 |
'tab' => 'widget', |
| 267 |
], |
| 268 |
'easy_scroll_to_top' => [ |
| 269 |
'class' => '\Easyel_Scroll_To_Top_Widget', |
| 270 |
'file' => __DIR__ . '/widgets/scroll-to-top/scroll.php', |
| 271 |
'tab' => 'widget', |
| 272 |
], |
| 273 |
'easy_table' => [ |
| 274 |
'class' => '\Easyel_Table_Elementor_Widget', |
| 275 |
'file' => __DIR__ . '/widgets/table/table-normal.php', |
| 276 |
'tab' => 'widget', |
| 277 |
], |
| 278 |
'easy_cf7' => [ |
| 279 |
'class' => '\easyel__CF7_Widget', |
| 280 |
'file' => __DIR__ . '/widgets/cf7/contact-cf7.php', |
| 281 |
'tab' => 'widget', |
| 282 |
], |
| 283 |
'easy_gallery' => [ |
| 284 |
'class' => '\Easyel__Gallery_Widget', |
| 285 |
'file' => __DIR__ . '/widgets/gallery/gallery.php', |
| 286 |
'tab' => 'widget', |
| 287 |
], |
| 288 |
'image_reveal' => [ |
| 289 |
'class' => '\Easyel_Image_Reveal__Widget', |
| 290 |
'file' => __DIR__ . '/widgets/reveal/reveal.php', |
| 291 |
'tab' => 'widget', |
| 292 |
], |
| 293 |
'rotate_text' => [ |
| 294 |
'class' => '\Easyel_Rotate_Text__Widget', |
| 295 |
'file' => __DIR__ . '/widgets/rotate-text/rotate-text.php', |
| 296 |
'tab' => 'widget', |
| 297 |
], |
| 298 |
|
| 299 |
'easy_progress' => [ |
| 300 |
'class' => '\Easyel_Progress_Widget', |
| 301 |
'file' => __DIR__ . '/widgets/progress/progress.php', |
| 302 |
'tab' => 'widget', |
| 303 |
], |
| 304 |
'typewriter' => [ |
| 305 |
'class' => '\Easyel_Typewriter_Widget', |
| 306 |
'file' => __DIR__ . '/widgets/typewriter/typewriter.php', |
| 307 |
'tab' => 'widget', |
| 308 |
], |
| 309 |
]; |
| 310 |
|
| 311 |
foreach ( $widgets as $key => $data ) { |
| 312 |
$option_name = 'easy_element_' . $data['tab'] . '_' . $key; |
| 313 |
$enabled = get_option( $option_name, '1' ); |
| 314 |
|
| 315 |
if ( 1 !== ( int ) $enabled ) { |
| 316 |
continue; // Skip disabled widgets |
| 317 |
} |
| 318 |
|
| 319 |
if ( file_exists( $data['file'] ) ) { |
| 320 |
require_once $data['file']; |
| 321 |
|
| 322 |
if ( class_exists( $data['class'] ) ) { |
| 323 |
$widgets_manager->register( new $data['class']() ); |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
} |
| 330 |
|
| 331 |
Easyel_Elements_Elementor_Extension::instance(); |