title. * * @return array */ public static function pages() { return array( self::SLUG => __( 'Export', 'shiftbox' ), self::SLUG . '-import' => __( 'Import', 'shiftbox' ), self::SLUG . '-backups' => __( 'Backups', 'shiftbox' ), self::SLUG . '-settings' => __( 'Settings', 'shiftbox' ), ); } /** * Adds the menu and its sub-pages. * * @return void */ public static function menu() { $cap = Shiftbox_Ajax::capability(); $count = count( Shiftbox_Storage::list_backups() ); add_menu_page( __( 'Shiftbox', 'shiftbox' ), __( 'Shiftbox', 'shiftbox' ), $cap, self::SLUG, array( __CLASS__, 'render' ), 'dashicons-migrate', 76 ); foreach ( self::pages() as $slug => $title ) { $label = $title; if ( self::SLUG . '-backups' === $slug && $count > 0 ) { $label .= ' ' . number_format_i18n( $count ) . ''; } self::$hooks[] = add_submenu_page( self::SLUG, $title . ' ‹ ' . __( 'Shiftbox', 'shiftbox' ), $label, $cap, $slug, array( __CLASS__, 'render' ) ); } } /** * Settings registration. * * @return void */ public static function register_settings() { register_setting( 'shiftbox', Shiftbox_Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'Shiftbox_Settings', 'sanitize' ), 'default' => Shiftbox_Settings::defaults(), ) ); } /** * Plugins-screen link. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Backups', 'shiftbox' ) . '' ); return $links; } /** * Loads CSS and JS on our page only. * * @param string $hook Hook suffix. * @return void */ public static function assets( $hook ) { if ( ! in_array( $hook, self::$hooks, true ) ) { return; } // Version by file time as well, so browsers never keep an old copy after the plugin files change. $css = SHIFTBOX_VERSION . '.' . (int) filemtime( SHIFTBOX_DIR . 'assets/css/admin.css' ); $js = SHIFTBOX_VERSION . '.' . (int) filemtime( SHIFTBOX_DIR . 'assets/js/admin.js' ); wp_enqueue_style( 'shiftbox-admin', SHIFTBOX_URL . 'assets/css/admin.css', array(), $css ); wp_enqueue_script( 'shiftbox-admin', SHIFTBOX_URL . 'assets/js/admin.js', array(), $js, true ); wp_localize_script( 'shiftbox-admin', 'ShiftboxData', array( 'ajax' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( Shiftbox_Ajax::NONCE ), 'maxImport' => (int) Shiftbox_Settings::get( 'max_import' ), 'speedCap' => (float) Shiftbox_Settings::get( 'speed_cap' ), 'active' => Shiftbox_Job::active(), 'i18n' => array( 'confirmDelete' => __( 'Delete this backup? This cannot be undone.', 'shiftbox' ), 'confirmRestore' => __( 'Restore this backup? This site\'s content, database, plugins and themes will be replaced.', 'shiftbox' ), 'confirmCancel' => __( 'Stop this job? Nothing on your live site has been changed yet.', 'shiftbox' ), 'uploading' => __( 'Uploading', 'shiftbox' ), 'resuming' => __( 'Connection dropped. Resuming…', 'shiftbox' ), 'tooBig' => __( 'This file is larger than the import limit set in Settings.', 'shiftbox' ), 'wrongType' => __( 'Choose a .shiftbox or .wpress backup file.', 'shiftbox' ), 'backupDone' => __( 'Backup ready.', 'shiftbox' ), 'restoreDone' => __( 'Restore complete. Taking you to the login page…', 'shiftbox' ), 'failed' => __( 'Something went wrong', 'shiftbox' ), 'leave' => __( 'A backup or restore is running. Leaving now pauses it.', 'shiftbox' ), 'left' => __( 'left', 'shiftbox' ), 'calc' => __( 'calculating…', 'shiftbox' ), 'preBackup' => __( 'Backing up this site first…', 'shiftbox' ), 'from' => __( 'From', 'shiftbox' ), 'created' => __( 'Created', 'shiftbox' ), 'size' => __( 'Size', 'shiftbox' ), 'files' => __( 'Files', 'shiftbox' ), 'type' => __( 'Made with', 'shiftbox' ), 'download' => __( 'Download', 'shiftbox' ), 'allBackups' => __( 'See all backups', 'shiftbox' ), 'nothing' => __( 'Tick at least one of Database, Media library, Themes or Plugins.', 'shiftbox' ), 'exportDone' => __( 'Backup complete', 'shiftbox' ), 'uploadDone' => __( 'Upload complete. Check the details and confirm the restore.', 'shiftbox' ), 'restoreTitle' => __( 'Restore complete', 'shiftbox' ), 'loginAgain' => __( 'Log in again', 'shiftbox' ), 'fileLabel' => __( 'File', 'shiftbox' ), 'included' => __( 'Included', 'shiftbox' ), 'took' => __( 'Took', 'shiftbox' ), ), ) ); } /** * Rows of the backups table. * * @return string */ public static function backups_rows( $from = '' ) { $ai1wm = 'ai1wm' === $from; $backups = $ai1wm ? Shiftbox_Storage::list_ai1wm() : Shiftbox_Storage::list_backups(); if ( empty( $backups ) ) { return '' . esc_html__( 'No backups yet. Go to Shiftbox > Export to create one. It takes a minute on most sites.', 'shiftbox' ) . ''; } $html = ''; foreach ( $backups as $b ) { $url = wp_nonce_url( add_query_arg( array( 'action' => 'shiftbox_download', 'file' => rawurlencode( $b['name'] ) ), admin_url( 'admin-ajax.php' ) ), 'shiftbox_download' ); if ( $ai1wm ) { $html .= '' . '' . esc_html( $b['name'] ) . '' . '' . esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $b['time'] ) ) . '' . '' . esc_html( size_format( $b['size'], 1 ) ) . '' . ''; continue; } $html .= '' . '' . esc_html( $b['name'] ) . '' . '' . esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $b['time'] ) ) . '' . '' . esc_html( size_format( $b['size'], 1 ) ) . '' . '' . '' . esc_html__( 'Download', 'shiftbox' ) . ' ' . ' ' . '' . ''; } return $html; } /** * Renders whichever Shiftbox page is open. * * @return void */ public static function render() { if ( ! current_user_can( Shiftbox_Ajax::capability() ) ) { return; } Shiftbox_Storage::ensure(); Shiftbox_Job::cleanup_stale(); $s = Shiftbox_Settings::all(); $chunk = Shiftbox_Settings::upload_chunk(); $free = Shiftbox_Storage::free_space(); $writable = wp_is_writable( Shiftbox_Storage::dir() ); $pages = self::pages(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Page routing only. $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : self::SLUG; $page = isset( $pages[ $page ] ) ? $page : self::SLUG; ?>

= 0 ? size_format( $free, 1 ) : __( 'unknown', 'shiftbox' ) ); ?>

__( 'Database (posts, pages, users, settings)', 'shiftbox' ), 'revisions' => __( 'Post revisions', 'shiftbox' ), 'spam' => __( 'Spam comments', 'shiftbox' ), 'media' => __( 'Media library', 'shiftbox' ), 'themes' => __( 'Themes', 'shiftbox' ), 'inactive_themes' => __( 'Inactive themes', 'shiftbox' ), 'plugins' => __( 'Plugins', 'shiftbox' ), 'inactive_plugins' => __( 'Inactive plugins', 'shiftbox' ), ); $parent = array( 'inactive_themes' => 'themes', 'inactive_plugins' => 'plugins', 'revisions' => 'database', 'spam' => 'database', ); ?>

$label ) : ?>

' . esc_html__( 'File', 'shiftbox' ) . '' . esc_html__( 'Created', 'shiftbox' ) . '' . esc_html__( 'Size', 'shiftbox' ) . '' . esc_html__( 'Actions', 'shiftbox' ) . ''; ?>

  1. Export, create a backup and download it.', 'shiftbox' ); ?>

array( __( 'Import size limit', 'shiftbox' ), __( 'Largest backup file this site accepts for restore or move.', 'shiftbox' ) ), 'max_backup' => array( __( 'Backup size limit', 'shiftbox' ), __( 'Stop a backup that grows beyond this size.', 'shiftbox' ) ), ) as $key => $text ) : list( $val, $unit ) = Shiftbox_Settings::split( $s[ $key ] ); ?>