elementskit-lite
Last commit date
compatibility
5 years ago
config
5 years ago
core
5 years ago
helpers
5 years ago
languages
5 years ago
libs
5 years ago
modules
5 years ago
traits
5 years ago
widgets
5 years ago
autoloader.php
5 years ago
elementskit-lite.php
5 years ago
plugin.php
5 years ago
readme.txt
5 years ago
plugin.php
331 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite; |
| 3 | |
| 4 | |
| 5 | |
| 6 | defined( 'ABSPATH' ) || exit; |
| 7 | |
| 8 | |
| 9 | /** |
| 10 | * ElementsKit - the God class. |
| 11 | * Initiate all necessary classes, hooks, configs. |
| 12 | * |
| 13 | * @since 1.0.0 |
| 14 | */ |
| 15 | class Plugin{ |
| 16 | |
| 17 | |
| 18 | /** |
| 19 | * The plugin instance. |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | * @access public |
| 23 | * @static |
| 24 | * |
| 25 | * @var Plugin |
| 26 | */ |
| 27 | public static $instance = null; |
| 28 | |
| 29 | /** |
| 30 | * Construct the plugin object. |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * @access public |
| 34 | */ |
| 35 | public function __construct() { |
| 36 | |
| 37 | // Enqueue frontend scripts. |
| 38 | add_action( 'wp_enqueue_scripts', [$this, 'enqueue_frontend'] ); |
| 39 | |
| 40 | // Enqueue admin scripts. |
| 41 | add_action( 'admin_enqueue_scripts', [$this, 'enqueue_admin'] ); |
| 42 | |
| 43 | // Enqueue inline scripts |
| 44 | Core\Build_Inline_Scripts::instance(); |
| 45 | |
| 46 | // Register plugin settings pages |
| 47 | Libs\Framework\Attr::instance(); |
| 48 | |
| 49 | // Register default widgets |
| 50 | Core\Build_Widgets::instance(); |
| 51 | |
| 52 | // Register default modules |
| 53 | Core\Build_Modules::instance(); |
| 54 | |
| 55 | add_action('wp_head', [$this, 'add_meta_for_search_excluded']); |
| 56 | |
| 57 | // Register ElementsKit supported widgets to Elementor from 3rd party plugins. |
| 58 | add_action( 'elementor/widgets/widgets_registered', [$this, 'register_widgets'], 1050); |
| 59 | |
| 60 | // Register wpml compability module |
| 61 | Compatibility\Wpml\Init::instance(); |
| 62 | Compatibility\Conflicts\Init::instance(); |
| 63 | |
| 64 | |
| 65 | $filter_string = ''; // elementskit,metform-pro |
| 66 | $filter_string .= ((!in_array('elementskit/elementskit.php', apply_filters('active_plugins', get_option('active_plugins')))) ? '' : ',elementskit'); |
| 67 | $filter_string .= (!class_exists('\MetForm\Plugin') ? '' : ',metform'); |
| 68 | $filter_string .= (!class_exists('\MetForm_Pro\Plugin') ? '' : ',metform-pro'); |
| 69 | |
| 70 | |
| 71 | /** |
| 72 | * Show WPMET stories widget in dashboard |
| 73 | */ |
| 74 | \Wpmet\Libs\Stories::instance('elementskit-lite') |
| 75 | // ->is_test(true) |
| 76 | ->set_filter($filter_string) |
| 77 | ->set_plugin('ElementsKit', 'https://wpmet.com/plugin/elementskit/') |
| 78 | ->set_api_url('https://api.wpmet.com/public/stories/') |
| 79 | ->call(); |
| 80 | |
| 81 | /** |
| 82 | * ---------------------------------------- |
| 83 | * Ask for rating ⭐⭐⭐⭐⭐ |
| 84 | * A rating notice will appear depends on |
| 85 | * @set_first_appear_day methods |
| 86 | * ---------------------------------------- |
| 87 | */ |
| 88 | |
| 89 | \Wpmet\Libs\Rating::instance('elementskit-lite') |
| 90 | ->set_plugin('ElementsKit', 'https://wordpress.org/plugins/elementskit-lite/') |
| 91 | ->set_plugin_logo('https://ps.w.org/elementskit-lite/assets/icon-128x128.png','width:150px !important') |
| 92 | ->set_allowed_screens('edit-elementskit_template') |
| 93 | ->set_allowed_screens('toplevel_page_elementskit') |
| 94 | ->set_allowed_screens('elementskit_page_elementskit-lite_get_help') |
| 95 | ->set_priority(10) |
| 96 | ->set_first_appear_day(7) |
| 97 | ->set_condition(true) |
| 98 | ->call(); |
| 99 | |
| 100 | |
| 101 | |
| 102 | /** |
| 103 | * Show WPMET banner (codename: jhanda) |
| 104 | */ |
| 105 | \Wpmet\Libs\Banner::instance('elementskit-lite') |
| 106 | // ->is_test(true) |
| 107 | ->set_filter(ltrim($filter_string, ',')) |
| 108 | ->set_api_url('https://api.wpmet.com/public/jhanda') |
| 109 | ->set_plugin_screens('edit-elementskit_template') |
| 110 | ->set_plugin_screens('toplevel_page_elementskit') |
| 111 | ->call(); |
| 112 | |
| 113 | $is_pro_active = in_array('elementskit/elementskit.php', apply_filters('active_plugins', get_option('active_plugins'))); |
| 114 | |
| 115 | /** |
| 116 | * Show go Premium menu |
| 117 | */ |
| 118 | \Wpmet\Libs\Pro_Awareness::instance('elementskit-lite') |
| 119 | ->set_parent_menu_slug('elementskit') |
| 120 | ->set_plugin_file('elementskit-lite/elementskit-lite.php') |
| 121 | ->set_pro_link( |
| 122 | ((\ElementsKit_Lite::package_type() != 'free') ? '' : 'http://go.wpmet.com/ekitpro') |
| 123 | ) |
| 124 | ->set_default_grid_thumbnail(\ElementsKit_Lite::lib_url() . 'pro-awareness/assets/support.png') |
| 125 | |
| 126 | ->set_page_grid([ |
| 127 | 'url' => 'https://go.wpmet.com/facebook-group', |
| 128 | 'title' => 'Join the Community', |
| 129 | 'thumbnail' => \ElementsKit_Lite::lib_url() . 'pro-awareness/assets/community.png', |
| 130 | ]) |
| 131 | ->set_page_grid([ |
| 132 | 'url' => 'https://www.youtube.com/playlist?list=PL3t2OjZ6gY8MVnyA4OLB6qXb77-roJOuY', |
| 133 | 'title' => 'Video Tutorials', |
| 134 | 'thumbnail' => \ElementsKit_Lite::lib_url() . 'pro-awareness/assets/videos.png', |
| 135 | ]) |
| 136 | ->set_page_grid([ |
| 137 | 'url' => 'https://wpmet.com/plugin/elementskit/roadmaps#ideas', |
| 138 | 'title' => 'Request a feature', |
| 139 | 'thumbnail' => \ElementsKit_Lite::lib_url() . 'pro-awareness/assets/request.png', |
| 140 | ]) |
| 141 | ->set_plugin_row_meta('Documentation','https://go.wpmet.com/ekitdoc', ['target'=>'_blank']) |
| 142 | ->set_plugin_row_meta('Facebook Community','http://go.wpmet.com/facebook-group', ['target'=>'_blank']) |
| 143 | ->set_plugin_row_meta('Rate the plugin � |
| 144 | � |
| 145 | � |
| 146 | � |
| 147 | � |
| 148 | ','https://wordpress.org/support/plugin/elementskit-lite/reviews/#new-post', ['target'=>'_blank']) |
| 149 | ->set_plugin_action_link('Settings',admin_url() . 'admin.php?page=elementskit') |
| 150 | ->set_plugin_action_link(($is_pro_active ? '' : 'Go Premium'),'https://wpmet.com/plugin/elementskit', ['target'=>'_blank', 'style' => 'color: #FCB214; font-weight: bold;']) |
| 151 | ->call(); |
| 152 | |
| 153 | |
| 154 | |
| 155 | // Adding pro lebel |
| 156 | if(\ElementsKit_Lite::package_type() == 'free'){ |
| 157 | new Libs\Pro_Label\Init(); |
| 158 | } |
| 159 | |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Check the admin screen and show the rating notice if eligible |
| 164 | * |
| 165 | * @access private |
| 166 | * @return boolean |
| 167 | */ |
| 168 | private function should_show_rating_notice() { |
| 169 | |
| 170 | if(\ElementsKit_Lite::package_type() == 'free'){ |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | if( !function_exists('get_current_screen') ) { |
| 175 | return false; |
| 176 | } |
| 177 | |
| 178 | $current_screen = (get_current_screen())->base; |
| 179 | $current_post_type = (get_current_screen())->post_type; |
| 180 | $eligible_post_type = ['elementskit_template']; |
| 181 | $eligible_screens = ['plugins', 'dashboard', 'elementskit', 'themes']; |
| 182 | |
| 183 | if (in_array($current_post_type, $eligible_post_type)){ |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | if (in_array($current_screen, $eligible_screens)){ |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Enqueue scripts |
| 198 | * |
| 199 | * Enqueue js and css to frontend. |
| 200 | * |
| 201 | * @since 1.0.0 |
| 202 | * @access public |
| 203 | */ |
| 204 | public function enqueue_frontend(){ |
| 205 | wp_enqueue_style( 'elementor-icons-ekiticons', \ElementsKit_Lite::module_url() . 'controls/assets/css/ekiticons.css', \ElementsKit_Lite::version() ); |
| 206 | wp_enqueue_script( 'elementskit-framework-js-frontend', \ElementsKit_Lite::lib_url() . 'framework/assets/js/frontend-script.js', ['jquery'], \ElementsKit_Lite::version(), true ); |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Enqueue scripts |
| 211 | * |
| 212 | * Enqueue js and css to admin. |
| 213 | * |
| 214 | * @since 1.0.0 |
| 215 | * @access public |
| 216 | */ |
| 217 | public function enqueue_admin(){ |
| 218 | $screen = get_current_screen(); |
| 219 | |
| 220 | if(!in_array($screen->id, ['nav-menus', 'toplevel_page_elementskit', 'edit-elementskit_template', 'elementskit_page_elementskit-license'])){ |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | wp_register_style( 'fontawesome', \ElementsKit_Lite::widget_url() . 'init/assets/css/font-awesome.min.css', \ElementsKit_Lite::version() ); |
| 225 | wp_register_style( 'elementskit-font-css-admin', \ElementsKit_Lite::module_url() . 'controls/assets/css/ekiticons.css', \ElementsKit_Lite::version() ); |
| 226 | wp_register_style( 'elementskit-lib-css-admin', \ElementsKit_Lite::lib_url() . 'framework/assets/css/framework.css', \ElementsKit_Lite::version() ); |
| 227 | wp_register_style( 'elementskit-init-css-admin', \ElementsKit_Lite::lib_url() . 'framework/assets/css/admin-style.css', \ElementsKit_Lite::version() ); |
| 228 | wp_register_style( 'elementskit-init-css-admin-ems', \ElementsKit_Lite::lib_url() . 'framework/assets/css/admin-style-ems-dev.css', \ElementsKit_Lite::version() ); |
| 229 | |
| 230 | wp_enqueue_style( 'fontawesome' ); |
| 231 | wp_enqueue_style( 'elementskit-font-css-admin' ); |
| 232 | wp_enqueue_style( 'elementskit-lib-css-admin' ); |
| 233 | wp_enqueue_style( 'elementskit-lib-css-admin' ); |
| 234 | wp_enqueue_style( 'elementskit-init-css-admin' ); |
| 235 | wp_enqueue_style( 'elementskit-init-css-admin-ems' ); |
| 236 | |
| 237 | wp_enqueue_script( 'ekit-admin-core', \ElementsKit_Lite::lib_url() . 'framework/assets/js/ekit-admin-core.js', ['jquery'], \ElementsKit_Lite::version(), true ); |
| 238 | |
| 239 | $data['rest_url'] = get_rest_url(); |
| 240 | $data['nonce'] = wp_create_nonce('wp_rest'); |
| 241 | |
| 242 | wp_localize_script('ekit-admin-core', 'rest_config', $data); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Control registrar. |
| 247 | * |
| 248 | * Register the custom controls for Elementor |
| 249 | * using `elementskit/widgets/widgets_registered` action. |
| 250 | * |
| 251 | * @since 1.0.0 |
| 252 | * @access public |
| 253 | */ |
| 254 | public function register_control($widgets_manager){ |
| 255 | do_action('elementskit/widgets/widgets_registered', $widgets_manager); |
| 256 | } |
| 257 | |
| 258 | |
| 259 | /** |
| 260 | * Widget registrar. |
| 261 | * |
| 262 | * Retrieve all the registered widgets |
| 263 | * using `elementor/widgets/widgets_registered` action. |
| 264 | * |
| 265 | * @since 1.0.0 |
| 266 | * @access public |
| 267 | */ |
| 268 | public function register_widgets($widgets_manager){ |
| 269 | do_action('elementskit/widgets/widgets_registered', $widgets_manager); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Excluding ElementsKit template and megamenu content from search engine. |
| 274 | * See - https://wordpress.org/support/topic/google-is-indexing-elementskit-content-as-separate-pages/ |
| 275 | * |
| 276 | * @since 1.4.5 |
| 277 | * @access public |
| 278 | */ |
| 279 | public function add_meta_for_search_excluded(){ |
| 280 | if ( in_array(get_post_type(), |
| 281 | ['elementskit_widget', 'elementskit_template', 'elementskit_content']) |
| 282 | ){ |
| 283 | echo '<meta name="robots" content="noindex,nofollow" />', "\n"; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Autoloader. |
| 289 | * |
| 290 | * ElementsKit autoloader loads all the classes needed to run the plugin. |
| 291 | * |
| 292 | * @since 1.0.0 |
| 293 | * @access private |
| 294 | */ |
| 295 | private static function registrar_autoloader() { |
| 296 | require_once \ElementsKit_Lite::plugin_dir() . '/autoloader.php'; |
| 297 | Autoloader::run(); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Instance. |
| 302 | * |
| 303 | * Ensures only one instance of the plugin class is loaded or can be loaded. |
| 304 | * |
| 305 | * @since 1.0.0 |
| 306 | * @access public |
| 307 | * @static |
| 308 | * |
| 309 | * @return Plugin An instance of the class. |
| 310 | */ |
| 311 | public static function instance() { |
| 312 | if ( is_null( self::$instance ) ) { |
| 313 | // Call the method for ElementsKit lite autoloader. |
| 314 | self::registrar_autoloader(); |
| 315 | |
| 316 | do_action( 'elementskit_lite/before_loaded' ); |
| 317 | |
| 318 | // Fire when ElementsKit instance. |
| 319 | self::$instance = new self(); |
| 320 | |
| 321 | do_action( 'elementskit/loaded' ); // legacy support |
| 322 | do_action( 'elementskit_lite/after_loaded' ); |
| 323 | } |
| 324 | |
| 325 | return self::$instance; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Run the instance. |
| 330 | Plugin::instance(); |
| 331 |