ate_option('ZhUpClient_options', $converted_data['old']); } } public function saveOption() { self::securityCheck(); $settings = $_REQUEST; foreach ($this->moduleWithSettings as $module){ $module->setSetting($settings); } $converted_data=$this->convert_new_option_to_old($settings); update_option('ZhUpClient_options', $converted_data['old']); delete_site_transient( 'update_themes' ); delete_site_transient( 'update_plugins' ); if (!empty($converted_data['old']['send-data']) && $converted_data['old']['send-data']=='1'){ if (!wp_next_scheduled('ZhUpClient_send_site_data')) { wp_schedule_event(time(), 'daily', 'ZhUpClient_send_site_data'); } }else{ wp_clear_scheduled_hook('ZhUpClient_send_site_data'); } return wp_send_json(array('success' => true, 'message' => esc_html__('Setting Saved !','zhaket-updater'),'setting'=>$converted_data['new'])); } private function getInstalledItemList() { $all_plugins = get_plugins(); $plugins_list = []; $plugin_default = []; foreach ( (array)$all_plugins as $plugin_key => $plugin_data ) { $text_domain = !empty($plugin_data['TextDomain']) ? $plugin_data['TextDomain'] : 'default'; $plugins_list[ $plugin_key ] = translate( $plugin_data['Name'], $text_domain ); $plugin_default[ $plugin_key ] = 1; } $all_themes = wp_get_themes(); $themes_list = []; $themes_default = []; foreach ( (array)$all_themes as $theme_key => $theme_data ) { $text_domain = !empty( $theme_data->textdomain_loaded ) ? $theme_data->textdomain_loaded : 'default'; $themes_list[ $theme_key ] = translate( $theme_data->get_stylesheet(), $text_domain ); $themes_default[ $theme_key ] = 1; } return [ 'plugins' => [ $plugins_list, $plugin_default ], 'themes' => [ $themes_list, $themes_default ], ]; } public function convert_new_option_to_old($new) { $new=Helper::convertArrayKeysAndValues($new); $old=[]; $old['check-spacial-plugins']=[]; $old['check-spacial-themes']=[]; $old['ai']=[]; $old['ai']['default_image_model']= Helper::convert_bool_to_int($new['ai']['default_image_model'] ?? null); $old['ai']['default_text_model']= Helper::convert_bool_to_int($new['ai']['default_text_model'] ?? null); $old['ai']['default_content_written']= Helper::convert_bool_to_int($new['ai']['default_content_written'] ?? null); $old['ai']['default_content_persona']= Helper::convert_bool_to_int($new['ai']['default_content_persona'] ?? null); $old['all-plugins']= Helper::convert_bool_to_int($new['checkUpdate']['allPlugins']??true); $old['all-themes']= Helper::convert_bool_to_int($new['checkUpdate']['allThemes'] ?? true); $old['remove-old-backup']=Helper::convert_bool_to_int($new['backup']['backup']??true); $old['backup-keep-count']=(string)($new['backup']['backupCount'] ?? 2); $old['send-notifications']= Helper::convert_bool_to_int($new['notifications']['all_notice']??true); $old['email-address']=$new['notifications']['email_for_notice']?? get_bloginfo('admin_email'); $old['send-email-delay']=(string)($new['notifications']['email_interval'] ?? 2); $old['send-admin-notifications']= Helper::convert_bool_to_int($new['notifications']['email_notice']?? true); $old['show-admin-notifications']= Helper::convert_bool_to_int($new['notifications']['wordpress_notice'] ?? true); $old['send-data']= Helper::convert_bool_to_int($new['notifications']['send_data'] ?? false); $old['show-admin-offer']= Helper::convert_bool_to_int($new['notifications']['wordpress_offer']??true); $old['use-second-way-domain-test']=Helper::convert_bool_to_int($new['settings']['alternative_domain']?? false); $old['use-second-way-download']=Helper::convert_bool_to_int($new['settings']['alternative_update']?? false); $old['use-second-download-server']=Helper::convert_bool_to_int($new['settings']['alternative_server']?? false); $plugins = []; $old_setting_plugin_data = array_column(($new['checkUpdate']['spacialPlugins']??[]),'value','slug'); $parameters = $this->getInstalledItemList(); if (is_array($parameters['plugins'][0])) foreach ($parameters['plugins'][0] as $slug => $plugin) { $value=!isset($old_setting_plugin_data[$slug])? true : $old_setting_plugin_data[$slug]; $plugins[]=[ 'slug'=>$slug, 'name'=>$plugin, 'value'=>$value ]; } $new['checkUpdate']['spacialPlugins']=$plugins; $themes = []; $old_setting_theme_data = array_column(( $new['checkUpdate']['spacialThemes']??[]),'value','slug'); if (is_array($parameters['themes'][0])) foreach ($parameters['themes'][0] as $slug => $theme) { $value=!isset($old_setting_theme_data[$slug])? true : $old_setting_theme_data[$slug]; $themes[]=[ 'slug'=>$slug, 'name'=>$theme, 'value'=>$value ]; } $new['checkUpdate']['spacialThemes']=$themes; foreach ((array)($new['checkUpdate']['spacialPlugins']??[]) as $value){ $old['check-spacial-plugins'][$value['slug']]=!empty($value['value'])?'1':'0'; } foreach ((array)($new['checkUpdate']['spacialThemes']??[]) as $value){ $old['check-spacial-themes'][$value['slug']]=!empty($value['value'])?'1':'0'; } return ['old'=>$old,'new'=>$new]; } public function generate_product_link() { self::securityCheck(); if (!DependencyChecker::getInstance()->canRunApplication() || !class_exists('ZhUpClientUpdater\zhUpClient_check')){ wp_send_json_error(esc_html__('dependency check failed','zhaket-updater')); } zhUpClient_check::generate_downlaod_address($_REQUEST['product_id']); } }