| Server IP : 38.190.208.107 / Your IP : 216.73.217.105 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.2/wp-content/themes/blocksy/inc/components/blocks/ |
Upload File : |
<?php
namespace Blocksy;
class LegacyWidgetsTransformer {
public function __construct() {
$sidebars_widgets = get_option('sidebars_widgets', []);
$did_change = false;
foreach ($sidebars_widgets as $sidebar_id => $widgets_list) {
if ($sidebar_id === 'wp_inactive_widgets') {
continue;
}
if (! is_array($widgets_list)) {
continue;
}
$new_widgets_descriptor = $this->migrate_sidebar($widgets_list);
if ($new_widgets_descriptor['new_blocks_count'] === 0) {
continue;
}
$did_change = true;
$sidebars_widgets[$sidebar_id] = $new_widgets_descriptor[
'new_sidebar'
];
}
if ($did_change) {
update_option('sidebars_widgets', $sidebars_widgets);
}
}
public function migrate_sidebar($widgets_list) {
$widget_block_data = get_option('widget_block');
$new_blocks_count = 0;
$new_sidebar = [];
foreach ($widgets_list as $widget_id) {
if (strpos($widget_id, 'blocksy_ct_') === 0) {
$widget_prefix = explode('-', $widget_id)[0];
$widget_numeric_id = explode('-', $widget_id)[1];
$data = get_option('widget_' . $widget_prefix);
if (! isset($data[$widget_numeric_id])) {
continue;
}
$data = $data[$widget_numeric_id];
$maybe_block_structure = $this->migrate_blocksy_widget_to_block(
$widget_prefix,
$data
);
if ($maybe_block_structure) {
$new_widget_id = 1;
$maybe_current_ids = array_filter(
array_keys($widget_block_data),
'is_numeric'
);
if (! empty($maybe_current_ids)) {
$new_widget_id = array_keys($widget_block_data);
$new_widget_id = max($maybe_current_ids) + 1;
}
$widget_block_data[$new_widget_id] = [
'content' => $maybe_block_structure
];
$posts_widget_data = get_option('widget_' . $widget_prefix);
unset($posts_widget_data[$widget_numeric_id]);
update_option(
'widget_' . $widget_prefix,
$posts_widget_data
);
$new_blocks_count++;
$new_sidebar[] = 'block-' . $new_widget_id;
continue;
}
}
$new_sidebar[] = $widget_id;
}
update_option('widget_block', $widget_block_data);
return [
'new_blocks_count' => $new_blocks_count,
'new_sidebar' => $new_sidebar
];
}
public function migrate_blocksy_widget_to_block($widget_id, $data) {
if ($widget_id === 'blocksy_ct_posts') {
$posts_migrator = new LegacyWidgetsPostsTransformer($data);
return $posts_migrator->get_block();
}
// Non-posts widgets...
if ($widget_id === 'blocksy_ct_about_me') {
$about_me_migrator = new LegacyWidgetsAboutMeTransformer($data);
return $about_me_migrator->get_block();
}
if ($widget_id === 'blocksy_ct_contact_info') {
$contact_info_migrator = new LegacyWidgetsContactInfoTransformer($data);
return $contact_info_migrator->get_block();
}
if ($widget_id === 'blocksy_ct_socials') {
$socials_migrator = new LegacyWidgetsSocialsTransformer($data);
return $socials_migrator->get_block();
}
if ($widget_id === 'blocksy_ct_advertisement') {
$advertisement_migrator = new LegacyWidgetsAdvertisementTransformer($data);
return $advertisement_migrator->get_block();
}
if ($widget_id === 'blocksy_ct_newsletter_subscribe') {
$advertisement_migrator = new LegacyWidgetsNewsletterSubscribeTransformer($data);
return $advertisement_migrator->get_block();
}
if ($widget_id === 'blocksy_ct_quote') {
$quote_migrator = new LegacyWidgetsQuoteTransformer($data);
return $quote_migrator->get_block();
}
return null;
}
}