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 '
= 0 ? size_format( $free, 1 ) : __( 'unknown', 'shiftbox' ) ); ?>