WP init
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Helpers;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Module_List extends \ElementsKit_Lite\Config\Module_List {
|
||||
//
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
if ( ! class_exists( 'ElementsKit' ) ) {
|
||||
class ElementsKit {
|
||||
// for backward compatibility
|
||||
|
||||
const VERSION = '1.5.9';
|
||||
|
||||
const PACKAGE_TYPE = 'pro';
|
||||
|
||||
const PRODUCT_ID = '9';
|
||||
|
||||
const MINIMUM_ELEMENTOR_VERSION = '2.4.0';
|
||||
|
||||
const MINIMUM_PHP_VERSION = '5.6';
|
||||
|
||||
static function api_url() {
|
||||
return 'https://api.wpmet.com/public/';
|
||||
}
|
||||
|
||||
static function plugin_url() {
|
||||
return trailingslashit( plugin_dir_url( __FILE__ ) );
|
||||
}
|
||||
|
||||
static function plugin_dir() {
|
||||
return trailingslashit( plugin_dir_path( __FILE__ ) );
|
||||
}
|
||||
|
||||
static function widget_dir() {
|
||||
return self::plugin_dir() . 'widgets/';
|
||||
}
|
||||
|
||||
static function widget_url() {
|
||||
return self::plugin_url() . 'widgets/';
|
||||
}
|
||||
|
||||
static function module_dir() {
|
||||
return self::plugin_dir() . 'modules/';
|
||||
}
|
||||
|
||||
static function module_url() {
|
||||
return self::plugin_url() . 'modules/';
|
||||
}
|
||||
|
||||
static function lib_dir() {
|
||||
return self::plugin_dir() . 'libs/';
|
||||
}
|
||||
|
||||
static function lib_url() {
|
||||
return self::plugin_url() . 'libs/';
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace ElementsKit;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Global helper class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
class Utils extends \ElementsKit_Lite\Utils {
|
||||
//
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace ElementsKit;
|
||||
|
||||
class Elementskit_Menu_Walker extends \ElementsKit_Lite\ElementsKit_Menu_Walker {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Helpers;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Widget_List extends \ElementsKit_Lite\Config\Widget_List {
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Compatibility\Conflicts;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
/**
|
||||
* Init
|
||||
* Initiate all necessary classes, hooks, configs.
|
||||
*
|
||||
* @since 1.2.6
|
||||
*/
|
||||
class Init {
|
||||
|
||||
/**
|
||||
* Member Variable
|
||||
*
|
||||
* @var instance
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* Ensures only one instance of the plugin class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return Init An instance of the class.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
|
||||
// Fire when ElementsKit_Lite instance.
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the plugin object.
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {
|
||||
Scripts::instance();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Compatibility\Conflicts;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
/**
|
||||
* Init
|
||||
* Initiate all necessary classes, hooks, configs.
|
||||
*
|
||||
* @since 1.2.6
|
||||
*/
|
||||
class Scripts {
|
||||
|
||||
/**
|
||||
* Member Variable
|
||||
*
|
||||
* @var instance
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* Ensures only one instance of the plugin class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return Init An instance of the class.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
|
||||
// Fire when ElementsKit_Lite instance.
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct the plugin object.
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'deregister_from_admin' ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Conflicted script deregister function
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
*/
|
||||
public function deregister_from_admin() {
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( in_array( $screen->id, array( 'edit-elementskit_template', 'toplevel_page_elementskit', 'elementskit_page_elementskit-license', 'nav-menus' ) ) ) {
|
||||
wp_deregister_script( 'wpsp_wp_admin_jquery2' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Compatibility\Data_Migration;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Settings_Db {
|
||||
public function __construct() {
|
||||
|
||||
$widget_list = \ElementsKit_Lite\Config\Widget_List::instance()->get_list();
|
||||
$this->migrate($widget_list, 'widget');
|
||||
|
||||
$module_list = \ElementsKit_Lite\Config\Module_List::instance()->get_list();
|
||||
$this->migrate($module_list, 'module');
|
||||
|
||||
// TODO - remove this after 3.10.0 release
|
||||
add_action( 'upgrader_process_complete', [$this, 'clear_cache'], 10, 2 );
|
||||
}
|
||||
|
||||
private function migrate($list, $type) {
|
||||
$list_db = \ElementsKit_Lite\Libs\Framework\Attr::instance()->utils->get_option($type . '_list', array());
|
||||
$list_prepared = array();
|
||||
|
||||
if (empty($list_db[0]) || is_array($list_db[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($list as $slug => $info) {
|
||||
if (isset($info['package']) && $info['package'] == 'pro-disabled') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($info['attributes']) && in_array('new', $info['attributes'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$info['status'] = (in_array($slug, $list_db) ? 'active' : 'inactive');
|
||||
|
||||
$list_prepared[$slug] = $info;
|
||||
}
|
||||
|
||||
\ElementsKit_Lite\Libs\Framework\Attr::instance()->utils->save_option($type . '_list', $list_prepared);
|
||||
}
|
||||
|
||||
public function clear_cache($upgrader_object, $options){
|
||||
$our_plugin = 'elementskit-lite/elementskit-lite.php';
|
||||
if (!empty($options['plugins']) && $options['action'] == 'update' && $options['type'] == 'plugin' ) {
|
||||
foreach($options['plugins'] as $plugin) {
|
||||
if ($plugin == $our_plugin) {
|
||||
$this->regenerate_widget_builder_widgets();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function regenerate_widget_builder_widgets() {
|
||||
$args = array(
|
||||
'post_type' => 'elementskit_widget',
|
||||
'post_status' => 'publish', // Only get published posts
|
||||
'posts_per_page' => -1,
|
||||
);
|
||||
|
||||
$posts = get_posts($args);
|
||||
|
||||
if ($posts) {
|
||||
foreach ($posts as $post) {
|
||||
$id = $post->ID;
|
||||
$widget_data = get_post_meta($id, 'elementskit_custom_widget_data', true);
|
||||
if(!empty($widget_data) && is_object( $widget_data )) {
|
||||
\ElementsKit_Lite\Modules\Widget_Builder\Widget_File::instance()->create( $widget_data, $id );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace ElementsKit_Lite\Compatibility\Data_Migration;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
class Translate_File {
|
||||
|
||||
use \ElementsKit_Lite\Traits\Singleton;
|
||||
|
||||
private $OK_Translate_File = 'ekit_translate_file_checked';
|
||||
|
||||
public static function load_filesystem() {
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
|
||||
WP_Filesystem();
|
||||
}
|
||||
|
||||
public function init() {
|
||||
|
||||
$option = get_option( $this->OK_Translate_File, 'no' );
|
||||
|
||||
if ( $option == 'no' ) {
|
||||
|
||||
self::load_filesystem();
|
||||
|
||||
global $wp_filesystem;
|
||||
|
||||
$the_dir = WP_LANG_DIR . '/plugins/';
|
||||
$files = $wp_filesystem->dirlist( $the_dir );
|
||||
|
||||
$o_dom = 'elementskit-';
|
||||
$n_dom = 'elementskit-lite-';
|
||||
|
||||
$file_pattern = 'elementskit-';
|
||||
$ln = strlen( $file_pattern );
|
||||
$invalid_pattern = '/elementskit\-.+\-.+/';
|
||||
|
||||
if ( ! empty( $files ) ) {
|
||||
foreach ( $files as $file ) {
|
||||
|
||||
$nm = $file['name'];
|
||||
|
||||
$dbg['cont']['pahase0'][] = 9;
|
||||
|
||||
/**
|
||||
* Checking if file name is started with elementskit-
|
||||
*/
|
||||
if ( substr( $nm, 0, $ln ) == $file_pattern ) {
|
||||
|
||||
/**
|
||||
* Checking if file name is like this pattern elementskit-blabla-
|
||||
* If so we will not process it
|
||||
*
|
||||
*/
|
||||
if ( preg_match( $invalid_pattern, $nm ) ) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Preparing a new name for the file
|
||||
* and copying it i the same directory
|
||||
*
|
||||
*/
|
||||
$new_name = str_replace( $o_dom, $n_dom, $nm );
|
||||
$wp_filesystem->copy( $the_dir . $nm, $the_dir . $new_name, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As we have copied all the files
|
||||
* we do not want to run this every time
|
||||
* so we are updating the flag in WordPress option
|
||||
*/
|
||||
|
||||
update_option( $this->OK_Translate_File, 'yes' );
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Compatibility\Element_Manager;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class Init {
|
||||
|
||||
public function __construct() {
|
||||
add_action('update_option_elementor_disabled_elements', [$this, 'sync_with_elementor'], 10, 2);
|
||||
add_action('elementskit/widgets/status/update', [$this, 'sync_with_elementskit']);
|
||||
add_action('upgrader_process_complete', [$this, 'reset_widget_statuses'], 10, 2);
|
||||
}
|
||||
|
||||
public function sync_with_elementor($old_value, $new_value) {
|
||||
$disabled_elements = (array) get_option( 'elementor_disabled_elements', [] );
|
||||
|
||||
if($new_value) {
|
||||
$widgets_to_disable = array_filter(
|
||||
$disabled_elements,
|
||||
function( $element ) {
|
||||
return preg_match( '/^(elementskit-|ekit-)/', $element );
|
||||
}
|
||||
);
|
||||
|
||||
if($widgets_to_disable) {
|
||||
$this->disable_widgets($widgets_to_disable);
|
||||
}
|
||||
} else {
|
||||
// Re-enable all ElementsKit widgets if none are disabled
|
||||
$this->disable_widgets();
|
||||
}
|
||||
}
|
||||
|
||||
public function disable_widgets($widgets_to_disable = []) {
|
||||
$elementskit_options = get_option('elementskit_options');
|
||||
if (!$elementskit_options) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Normalize widget keys by removing "elementskit-" or "ekit-" prefix
|
||||
$widgets_to_disable = array_map(function ($widget) {
|
||||
return preg_replace('/^(elementskit-|ekit-)/', '', $widget);
|
||||
}, $widgets_to_disable);
|
||||
|
||||
// Correct widget names if needed
|
||||
$widgets_to_disable = array_map(function ($widget) {
|
||||
return $this->correct_widget_name($widget);
|
||||
}, $widgets_to_disable);
|
||||
|
||||
$widgets_list = isset($elementskit_options['widget_list']) ? $elementskit_options['widget_list'] : [];
|
||||
|
||||
if (is_array($widgets_list)) {
|
||||
$changed = false;
|
||||
|
||||
foreach ($widgets_list as $widget_key => &$widget_data) {
|
||||
$new_status = in_array($widget_key, $widgets_to_disable, true) ? 'inactive' : 'active';
|
||||
|
||||
// Only update if the status is different
|
||||
if (!isset($widget_data['status']) || $widget_data['status'] !== $new_status) {
|
||||
$widget_data['status'] = $new_status;
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
unset($widget_data); // break reference
|
||||
|
||||
// Save updated options only if changes were made
|
||||
if ($changed) {
|
||||
$elementskit_options['widget_list'] = $widgets_list;
|
||||
update_option('elementskit_options', $elementskit_options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function sync_with_elementskit($widgets_list) {
|
||||
if (empty($widgets_list) || !is_array($widgets_list)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Current disabled elements (Elementor expects prefixed keys, e.g. elementskit-foo / ekit-foo)
|
||||
$disabled_widgets = (array) get_option('elementor_disabled_elements', []);
|
||||
$original = $disabled_widgets;
|
||||
|
||||
foreach ($widgets_list as $key => $widget) {
|
||||
// Prefer $widget['slug'] if present; fallback to array key
|
||||
$raw_slug = isset($widget['slug']) && $widget['slug'] ? $widget['slug'] : $key;
|
||||
|
||||
// Resolve to the canonical/expected slug before prefixing
|
||||
$slug = $this->correct_widget_name($raw_slug, true);
|
||||
|
||||
$key_one = 'elementskit-' . $slug;
|
||||
$key_two = 'ekit-' . $slug;
|
||||
|
||||
$status = isset($widget['status']) ? $widget['status'] : null;
|
||||
if ($status === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($status === 'inactive') {
|
||||
// Ensure both prefixed keys exist
|
||||
if ($this->is_registered_widget($key_one) && !isset($disabled_widgets[$key_one])) {
|
||||
$disabled_widgets[] = $key_one;
|
||||
}
|
||||
if ($this->is_registered_widget($key_two) && !isset($disabled_widgets[$key_two])) {
|
||||
$disabled_widgets[] = $key_two;
|
||||
}
|
||||
} else { // active -> ensure both are removed
|
||||
if (in_array($key_one, $disabled_widgets)) {
|
||||
$disabled_widgets = array_values(array_diff($disabled_widgets, [$key_one]));
|
||||
}
|
||||
if (in_array($key_two, $disabled_widgets)) {
|
||||
$disabled_widgets = array_values(array_diff($disabled_widgets, [$key_two]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only write if something actually changed
|
||||
if ($disabled_widgets !== $original) {
|
||||
update_option('elementor_disabled_elements', $disabled_widgets);
|
||||
}
|
||||
}
|
||||
|
||||
public function reset_widget_statuses($upgrader_object, $options) {
|
||||
$should_run = true;
|
||||
$our_plugin = 'elementskit-lite/elementskit-lite.php';
|
||||
if (!empty($options['plugins']) && $options['action'] == 'update' && $options['type'] == 'plugin' ) {
|
||||
foreach($options['plugins'] as $plugin) {
|
||||
if ($plugin != $our_plugin) {
|
||||
$should_run = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if should run
|
||||
if(!$should_run) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if already updated
|
||||
$is_already_update = get_transient('ekit_element_manager_compatibity');
|
||||
if($is_already_update) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Run the update
|
||||
$elementskit_options = get_option('elementskit_options');
|
||||
if (!$elementskit_options) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get all widgets
|
||||
$widgets_list = $elementskit_options['widget_list'] ?? [];
|
||||
$widgets_to_disable = array_filter($widgets_list, function ($widget) {
|
||||
return isset($widget['status']) && $widget['status'] === 'inactive';
|
||||
});
|
||||
|
||||
if($widgets_to_disable) {
|
||||
$this->sync_with_elementskit($widgets_to_disable);
|
||||
}
|
||||
|
||||
// Set transient to avoid running again
|
||||
set_transient('ekit_element_manager_compatibity', true);
|
||||
}
|
||||
|
||||
public function correct_widget_name($slug = '', $reverse = false) {
|
||||
if($reverse) {
|
||||
if($slug === 'advanced-accordion') {
|
||||
return 'advance-accordion';
|
||||
}
|
||||
|
||||
if($slug === 'advanced-tab') {
|
||||
return 'tab';
|
||||
}
|
||||
|
||||
if($slug === 'social') {
|
||||
return 'social-media';
|
||||
}
|
||||
|
||||
if($slug === 'tab') {
|
||||
return 'simple-tab';
|
||||
}
|
||||
} else {
|
||||
if($slug === 'advance-accordion') {
|
||||
return 'advanced-accordion';
|
||||
}
|
||||
|
||||
if($slug === 'tab') {
|
||||
return 'advanced-tab';
|
||||
}
|
||||
|
||||
if($slug === 'social-media') {
|
||||
return 'social';
|
||||
}
|
||||
|
||||
if($slug === 'simple-tab') {
|
||||
return 'tab';
|
||||
}
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
|
||||
public function is_registered_widget($id = '') {
|
||||
$widgets_manager = \Elementor\Plugin::instance()->widgets_manager;
|
||||
$widgets = $widgets_manager->get_widget_types();
|
||||
|
||||
$widget_list = [];
|
||||
foreach ( $widgets as $widget ) {
|
||||
$widget_list[$widget->get_name()] = [
|
||||
'slug' => $widget->get_name(), // unique ID (e.g., 'heading', 'button', 'image-box')
|
||||
'title'=> $widget->get_title(), // display title
|
||||
];
|
||||
}
|
||||
|
||||
if($id) {
|
||||
return isset($widget_list[$id]) ? $widget_list[$id] : null;
|
||||
}
|
||||
|
||||
return $widget_list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace ElementsKit_Lite\Compatibility\Wpml;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
|
||||
/**
|
||||
* Init
|
||||
* Initiate all necessary classes, hooks, configs.
|
||||
*
|
||||
* @since 1.2.6
|
||||
*/
|
||||
class Init {
|
||||
|
||||
/**
|
||||
* Member Variable
|
||||
*
|
||||
* @var instance
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Instance.
|
||||
*
|
||||
* Ensures only one instance of the plugin class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
* @static
|
||||
*
|
||||
* @return Init An instance of the class.
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$instance ) ) {
|
||||
|
||||
// Fire when ElementsKit_Lite instance.
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the plugin object.
|
||||
*
|
||||
* @since 1.2.6
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
if(defined('ICL_SITEPRESS_VERSION')){
|
||||
add_filter( 'elementor/documents/get/post_id', [$this, 'wpml_template_translation']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID in the current language or in another language you specify
|
||||
* @param $id
|
||||
* @return string or array of object ids
|
||||
* @since 2.6.1
|
||||
* @access public
|
||||
*/
|
||||
public function wpml_template_translation($element_id){
|
||||
|
||||
$element_type = get_post_type($element_id);
|
||||
|
||||
if (in_array($element_type, ['elementskit_template', 'elementskit_content'])) {
|
||||
return apply_filters('wpml_object_id', $element_id, $element_type, true);
|
||||
}
|
||||
|
||||
return $element_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user