options=new WPvivid_Snapshot_Option_Ex(); /* if (is_multisite()) { add_action('network_admin_menu',array( $this,'add_admin_menu')); } else { add_action('admin_menu',array( $this,'add_admin_menu')); } add_filter('wpvivid_snapshot_get_screen_ids', array($this,'get_screen_ids'), 9999); */ add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),22); add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),12); add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'), 11); add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 11); add_action('wp_ajax_wpvivid_create_snapshot',array( $this,'create_snapshot')); add_action('wp_ajax_wpvivid_get_snapshot_progress',array( $this,'get_snapshot_progress')); // add_action('wp_ajax_wpvivid_resume_create_snapshot',array( $this,'resume_create_snapshot')); add_action('wp_ajax_wpvivid_restore_snapshot',array( $this,'restore_snapshot')); add_action('wp_ajax_wpvivid_get_restore_snapshot_status',array( $this,'get_restore_snapshot_status')); add_action('wp_ajax_wpvivid_delete_snapshot',array( $this,'delete_snapshot')); add_filter('wpvivid_check_create_snapshot',array($this,'check_create_snapshot')); add_action('wpvivid_create_snapshot',array($this,'create_snapshot_ex'),10,1); add_action('wp_ajax_wpvivid_set_snapshot_setting',array( $this,'set_setting')); // add_action('wpvivid_snapshot_add_sidebar',array( $this,'add_sidebar')); add_action('wpvivid_snapshot_add_sidebar_free', array( $this, 'add_sidebar_free' )); $snapshot_setting=$this->options->get_option('wpvivid_snapshot_setting'); $quick_snapshot=isset($snapshot_setting['quick_snapshot'])?$snapshot_setting['quick_snapshot']:false; if($quick_snapshot) { add_action('admin_bar_menu',array( $this,'add_toolbar_items'),100); add_action('admin_footer',array( $this,'quick_snapshot')); } } } public function get_admin_menus($submenus) { $submenu['parent_slug']=apply_filters('wpvivid_white_label_slug', WPVIVID_PLUGIN_SLUG); $submenu['page_title']= apply_filters('wpvivid_white_label_display', 'WPvivid Backup'); $submenu['menu_title']=__('Database Snapshots', 'wpvivid-backuprestore'); $submenu['capability']='administrator'; $submenu['menu_slug']=strtolower(sprintf('%s-snapshot-ex', apply_filters('wpvivid_white_label_slug', 'wpvivid'))); $submenu['index']=2; $submenu['function']=array($this, 'init_page'); $submenus[$submenu['menu_slug']]=$submenu; return $submenus; } public function get_screen_ids($screen_ids) { $screen_ids[]=apply_filters('wpvivid_white_label_screen_id', 'wpvivid-backup_page_wpvivid-snapshot-ex'); return $screen_ids; } public function add_toolbar_items($wp_admin_bar) { $wp_admin_bar->add_menu(array( 'id' => 'wpvivid_snapshot_admin_menu', 'title' => ''.'Quick Snapshot', 'meta' =>array( 'class' => 'wpvivid-quick-create-snapshot', ) )); } public function add_admin_menu() { $page_title=apply_filters('wpvivid_white_label_display', 'WPvivid Snapshot'); $menu_title=apply_filters('wpvivid_white_label_display', 'WPvivid Snapshot'); $capability = 'administrator'; $menu_slug ='wpvivid-snapshot'; $function=array($this, 'init_page'); $icon_url='dashicons-camera-alt'; $position=100; $menu['page_title']= $page_title; $menu['menu_title']= $menu_title; $menu['capability']='administrator'; $menu['menu_slug']=$menu_slug; $menu['function']=array($this, 'init_page'); $menu['icon_url']=$icon_url; $menu['position']=100; $menu=apply_filters('wpvivid_snapshot_get_main_admin_menus', $menu); if($menu!=false) add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position); } public function get_dashboard_menu($submenus,$parent_slug) { $display = apply_filters('wpvivid_get_menu_capability_addon', 'menu_database_snapshot'); if($display) { $submenu['menu_slug'] = strtolower(sprintf('%s-snapshot', apply_filters('wpvivid_white_label_slug', 'wpvivid'))); if(isset($submenus[$submenu['menu_slug']])) { unset($submenus[$submenu['menu_slug']]); } $submenu['parent_slug'] = $parent_slug; $submenu['page_title'] = apply_filters('wpvivid_white_label_display', 'Database Snapshots'); $submenu['menu_title'] = 'Database Snapshots'; $submenu['capability'] = 'administrator'; $submenu['index'] = 11;//10; $submenu['function'] = array($this, 'init_page_pro'); $submenus[$submenu['menu_slug']] = $submenu; } return $submenus; } public function get_dashboard_screens($screens) { $screen['menu_slug']='wpvivid-snapshot'; $screen['screen_id']='wpvivid-plugin_page_wpvivid-snapshot'; $screen['is_top']=false; $screens[]=$screen; return $screens; } public function get_main_admin_menus($menu) { if(class_exists('WPvivid_backup_pro')) return false; else return $menu; } /* public function get_screen_ids($screen_ids) { $screen_ids=array(); $screen['menu_slug']='wpvivid-snapshot'; $screen['screen_id']='toplevel_page_wpvivid-snapshot'; $screen['is_top']=true; $screens[]=$screen; foreach ($screens as $screen) { $screen_ids[]=$screen['screen_id']; if(is_multisite()) { if(substr($screen['screen_id'],-8)=='-network') continue; $screen_ids[]=$screen['screen_id'].'-network'; } else { $screen_ids[]=$screen['screen_id']; } } return $screen_ids; } */ public function enqueue_styles() { $screen_ids=array(); $screen_ids=apply_filters('wpvivid_get_screen_ids',$screen_ids); if(in_array(get_current_screen()->id,$screen_ids)) { wp_enqueue_style('wpvivid_snapshot_ex', WPVIVID_PLUGIN_DIR_URL . 'css/wpvivid-snapshot-style.css', array(), WPVIVID_PLUGIN_VERSION, 'all'); } } public function enqueue_scripts() { $snapshot_setting=$this->options->get_option('wpvivid_snapshot_setting'); $quick_snapshot=isset($snapshot_setting['quick_snapshot'])?$snapshot_setting['quick_snapshot']:false; if($quick_snapshot) { wp_enqueue_style('wpvivid_quick_snapshot_ex', WPVIVID_PLUGIN_DIR_URL . 'css/wpvivid-quick-snapshot-style.css', array(), WPVIVID_PLUGIN_VERSION, 'all'); wp_enqueue_style ( 'wp-jquery-ui-dialog'); wp_enqueue_script( 'jquery-ui-dialog' ); wp_enqueue_script ( 'wpvivid_qucick_snapshot_ex_js' , // handle WPVIVID_PLUGIN_DIR_URL . 'js/wpvivid-quick-snapshot.js' , // source array('jquery-ui-dialog'), WPVIVID_PLUGIN_VERSION, false ); wp_localize_script('wpvivid_qucick_snapshot_ex_js', 'wpvivid_quick_snapshot_ajax_object', array('ajax_url' => admin_url('admin-ajax.php'),'ajax_nonce'=>wp_create_nonce('wpvivid_ajax'))); } } public function added_quick_snapshot($added) { return true; } public function quick_snapshot() { if(apply_filters('wpvivid_added_quick_snapshot',false)) { return; } add_filter('wpvivid_added_quick_snapshot',array( $this,'added_quick_snapshot')); $current_url = $_SERVER['REQUEST_URI']; if (preg_match('/post.php?/', $current_url)) { return; } ?>
Are you sure you want to create a snapshot now?
Comment the snapshot(optional):
Comment the snapshot(optional):
|
Up to snapshots retained It is not recommended to create too many snapshots. |
|
|
|
100% completed
Action:Create snapshot completed.
'; } else { $progress=$snapshot->get_progress(); $ret['progress'] = ''.$progress['main_percent'].' completed
Action:'.$progress['doing'].'
'; } } echo wp_json_encode($ret); die(); } public function get_snapshot_progress() { check_ajax_referer( 'wpvivid_ajax', 'nonce' ); $check=current_user_can('manage_options'); $check=apply_filters('wpvivid_ajax_check_security',$check); if(!$check) { die(); } set_time_limit(300); $snapshot=new WPvivid_Snapshot_Function_Ex(); $progress=$snapshot->get_progress(); $ret['progress'] = ''.$progress['main_percent'].' completed
Action:'.$progress['doing'].'
'; echo wp_json_encode($ret); die(); } public function resume_create_snapshot() { check_ajax_referer( 'wpvivid_ajax', 'nonce' ); $check=current_user_can('manage_options'); $check=apply_filters('wpvivid_ajax_check_security',$check); if(!$check) { die(); } set_time_limit(300); $snapshot=new WPvivid_Snapshot_Function_Ex(); $ret=$snapshot->resume_create_snapshot(); if($ret['result']=='success') { if($ret['finished']==1) { $ret['progress'] = '100% completed
Action:Create snapshot completed.
'; } else { $progress=$snapshot->get_progress(); $ret['progress'] = ''.$progress['main_percent'].' completed
Action:'.$progress['doing'].'
'; } } echo wp_json_encode($ret); die(); } public function restore_snapshot() { check_ajax_referer( 'wpvivid_ajax', 'nonce' ); $check=current_user_can('manage_options'); $check=apply_filters('wpvivid_ajax_check_security',$check); if(!$check) { die(); } if(isset($_POST['id'])) { $snapshot_id=sanitize_text_field($_POST['id']); set_time_limit(300); $snapshot=new WPvivid_Snapshot_Function_Ex(); $ret=$snapshot->restore_snapshot($snapshot_id); if($ret['result']=='success') { $ret['progress'] = '100% completed
Action:Restoring the snapshot completed.
'; } echo wp_json_encode($ret); } die(); } public function get_restore_snapshot_status() { check_ajax_referer( 'wpvivid_ajax', 'nonce' ); $check=current_user_can('manage_options'); $check=apply_filters('wpvivid_ajax_check_security',$check); if(!$check) { die(); } set_time_limit(300); $snapshot=new WPvivid_Snapshot_Function_Ex(); $ret=$snapshot->get_restore_task_data(); if($ret['result']!='failed') { $finished=true; $i_sum=count($ret['snapshot_tables']); $i_finished=0; foreach ($ret['snapshot_tables'] as $table) { if($table['finished']==0) { $finished=false; } else { $i_finished++; } } $i_progress=intval(($i_finished/$i_sum)*100); $progress['main_percent']=$i_progress.'%'; $progress['doing']="Restoring the snapshot."; $ret['progress'] = ''.$progress['main_percent'].' completed
Action:'.$progress['doing'].'
'; $ret['finished']=$finished; } echo wp_json_encode($ret); die(); } public function delete_snapshot() { check_ajax_referer( 'wpvivid_ajax', 'nonce' ); $check=current_user_can('manage_options'); $check=apply_filters('wpvivid_ajax_check_security',$check); if(!$check) { die(); } if(isset($_POST['id'])) { $snapshot_id=sanitize_text_field($_POST['id']); set_time_limit(300); $snapshot=new WPvivid_Snapshot_Function_Ex(); $ret=$snapshot->remove_snapshot($snapshot_id); if($ret['result']=='success') { $snapshot_data=$snapshot->get_snapshots(); $Snapshots_list = new WPvivid_Snapshots_List_Ex(); $Snapshots_list->set_list($snapshot_data); $Snapshots_list->prepare_items(); ob_start(); $Snapshots_list->display(); $html = ob_get_clean(); $ret['html']=$html; } echo wp_json_encode($ret); } die(); } public function check_create_snapshot($check) { return true; } public function create_snapshot_ex($comment) { set_time_limit(300); $snapshot=new WPvivid_Snapshot_Function_Ex(); $snapshot->create_snapshot('manual',$comment); } public function set_setting() { check_ajax_referer( 'wpvivid_ajax', 'nonce' ); $check=current_user_can('manage_options'); $check=apply_filters('wpvivid_ajax_check_security',$check); if(!$check) { die(); } if(isset($_POST['setting'])&&!empty($_POST['setting'])) { $json_setting = sanitize_text_field($_POST['setting']); $json_setting = stripslashes($json_setting); $setting = json_decode($json_setting, true); if (is_null($setting)) { $ret['result']='failed'; $ret['error']='json decode failed'; echo wp_json_encode($ret); die(); } $old_setting=$this->options->get_option('wpvivid_snapshot_setting'); if(empty($setting)) { $setting=array(); } if(isset($setting['snapshot_retention'])) { $old_setting['snapshot_retention']=intval($setting['snapshot_retention']); } if(isset($setting['quick_snapshot'])) { $old_setting['quick_snapshot']=intval($setting['quick_snapshot']); } $this->options->update_option('wpvivid_snapshot_setting',$old_setting); } $ret['result']='success'; echo wp_json_encode($ret); die(); } public function add_sidebar_free() { if(defined('WPVIVID_SNAPSHOT_VERSION')) { $wpvivid_snapshot_version = WPVIVID_SNAPSHOT_VERSION; } else { $wpvivid_snapshot_version = WPVIVID_PLUGIN_VERSION; } ?>