This commit is contained in:
2025-11-18 16:39:33 +00:00
parent c70394d367
commit df1f90c6cd
9673 changed files with 3464697 additions and 34 deletions
@@ -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;
}
}