Пример #1
0
/**
 * Displays admin notices for various error / warning
 * conditions
 *
 * @return void
 */
function hmbkp_admin_notices()
{
    // If the form has been submitted, display updated notification
    // Display  notifications for any errors in the settings form.
    if (!empty($_POST['hmbkp_settings_submit'])) {
        function hmbkp_advanced_settings_saved()
        {
            echo '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>Settings saved.</strong></p></div>';
            global $hmbkp_errors;
            if (!empty($hmbkp_errors) && $hmbkp_errors->get_error_code()) {
                foreach ($hmbkp_errors->get_error_messages() as $hmbkp_error) {
                    echo '<div class="error"><p>' . $hmbkp_error . '</p></div>';
                }
            }
        }
        add_action('admin_notices', 'hmbkp_advanced_settings_saved');
    }
    // If the backups directory doesn't exist and can't be automatically created
    if (!is_dir(hmbkp_path())) {
        function hmbkp_path_exists_warning()
        {
            $php_user = exec('whoami');
            $php_group = reset(explode(' ', exec('groups')));
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress is almost ready.', 'hmbkp') . '</strong> ' . sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable, run %s or %s or create the folder yourself.', 'hmbkp'), '<code>wp-content</code>', '<code>chown ' . $php_user . ':' . $php_group . ' ' . WP_CONTENT_DIR . '</code>', '<code>chmod 777 ' . WP_CONTENT_DIR . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_path_exists_warning');
    }
    // If the backups directory exists but isn't writable
    if (is_dir(hmbkp_path()) && !is_writable(hmbkp_path())) {
        function hmbkp_writable_path_warning()
        {
            $php_user = exec('whoami');
            $php_group = reset(explode(' ', exec('groups')));
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress is almost ready.', 'hmbkp') . '</strong> ' . sprintf(__('Your backups directory isn\'t writable. run %s or %s or set the permissions yourself.', 'hmbkp'), '<code>chown -R ' . $php_user . ':' . $php_group . ' ' . hmbkp_path() . '</code>', '<code>chmod -R 777 ' . hmbkp_path() . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_writable_path_warning');
    }
    // If safe mode is active
    if (hmbkp_is_safe_mode_active()) {
        function hmbkp_safe_mode_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__(' %s is running in %s. Please contact your host and ask them to disable %s.', 'hmbkp'), '<code>PHP</code>', '<a href="http://php.net/manual/en/features.safe-mode.php"><code>Safe Mode</code></a>', '<code>Safe Mode</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_safe_mode_warning');
    }
    // If both HMBKP_FILES_ONLY & HMBKP_DATABASE_ONLY are defined at the same time
    if (hmbkp_get_files_only() && hmbkp_get_database_only()) {
        function hmbkp_nothing_to_backup_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('You have both %s and %s defined so there isn\'t anything to back up.', 'hmbkp'), '<code>HMBKP_DATABASE_ONLY</code>', '<code>HMBKP_FILES_ONLY</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_nothing_to_backup_warning');
    }
    // If the email address is invalid
    if (hmbkp_get_email_address() && !is_email(hmbkp_get_email_address())) {
        function hmbkp_email_invalid_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('%s is not a valid email address.', 'hmbkp'), '<code>' . hmbkp_get_email_address() . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_email_invalid_warning');
    }
    // If the email failed to send
    if (hmbkp_get_email_address() && get_option('hmbkp_email_error')) {
        function hmbkp_email_failed_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . __('The last backup email failed to send. It\'s likely that the file is to large.', 'hmbkp') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_email_failed_warning');
    }
    // If a custom backups directory is defined and it doesn't exist and can't be created
    if (defined('HMBKP_PATH') && HMBKP_PATH && !is_dir(HMBKP_PATH)) {
        function hmbkp_custom_path_exists_warning()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('Your custom backups directory %s doesn\'t exist and can\'t be created, your backups will be saved to %s instead.', 'hmbkp'), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_custom_path_exists_warning');
    }
    // If a custom backups directory is defined and exists but isn't writable
    if (defined('HMBKP_PATH') && HMBKP_PATH && is_dir(HMBKP_PATH) && !is_writable(HMBKP_PATH)) {
        function hmbkp_custom_path_writable_notice()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('Your custom backups directory %s isn\'t writable, new backups will be saved to %s instead.', 'hmbkp'), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_custom_path_writable_notice');
    }
    // If there are custom excludes defined and any of the files or directories don't exist
    if (hmbkp_invalid_custom_excludes()) {
        function hmbkp_invalid_exclude_notice()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has detected a problem.', 'hmbkp') . '</strong> ' . sprintf(__('You have defined a custom exclude list but the following paths don\'t exist %s, are you sure you entered them correctly?', 'hmbkp'), '<code>' . implode('</code>, <code>', (array) hmbkp_invalid_custom_excludes()) . '</code>') . '</p></div>';
        }
        add_action('admin_notices', 'hmbkp_invalid_exclude_notice');
    }
    // If there are any errors reported in the backup
    if (hmbkp_backup_errors_message()) {
        function hmbkp_backup_errors_notice()
        {
            echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress detected issues with your last backup.', 'hmbkp') . '</strong><a href="' . add_query_arg('action', 'hmbkp_dismiss_error') . '" style="float: right;" class="button">Dismiss</a></p>' . hmbkp_backup_errors_message() . '</div>';
        }
        add_action('admin_notices', 'hmbkp_backup_errors_notice');
    }
}
Пример #2
0
 function __construct($args, $assoc_args)
 {
     // Make sure it's possible to do a backup
     if (hmbkp_is_safe_mode_active()) {
         WP_CLI::error('Backup not possible when php is running safe_mode on');
         return false;
     }
     remove_action('hmbkp_backup_started', 'hmbkp_set_status', 10, 0);
     remove_action('hmbkp_mysqldump_started', 'hmbkp_set_status_dumping_database');
     remove_action('hmbkp_archive_started', 'hmbkp_set_status_archiving');
     add_action('hmbkp_mysqldump_started', function () {
         WP_CLI::line('Backup: Dumping database...');
     });
     add_action('hmbkp_archive_started', function () {
         WP_CLI::line('Backup: Zipping everything up...');
     });
     // Clean up any mess left by a previous backup
     hmbkp_cleanup();
     $hm_backup = HM_Backup::get_instance();
     if (!empty($assoc_args['path'])) {
         $hm_backup->path = $assoc_args['path'];
     }
     if (!empty($assoc_args['root'])) {
         $hm_backup->root = $assoc_args['root'];
     }
     if (!is_dir($hm_backup->path()) && (!is_writable(dirname($hm_backup->path())) || !mkdir($hm_backup->path())) || !is_writable($hm_backup->path())) {
         WP_CLI::error('Invalid backup path');
         return false;
     }
     if (!is_dir($hm_backup->root()) || !is_readable($hm_backup->root())) {
         WP_CLI::error('Invalid root path');
         return false;
     }
     // Default to both
     $hm_backup->files_only = false;
     $hm_backup->database_only = false;
     if (!empty($assoc_args['files_only'])) {
         $hm_backup->files_only = true;
     }
     if (!empty($assoc_args['database_only'])) {
         $hm_backup->database_only = true;
     }
     if (!empty($assoc_args['mysqldump_command_path'])) {
         $hm_backup->mysqldump_command_path = empty($assoc_args['mysqldump_command_path']) || $assoc_args['mysqldump_command_path'] === 'false' ? false : true;
     }
     if (!empty($assoc_args['zip_command_path'])) {
         $hm_backup->zip_command_path = empty($assoc_args['zip_command_path']) || $assoc_args['zip_command_path'] === 'false' ? false : true;
     }
     if (!empty($assoc_args['excludes'])) {
         $hm_backup->excludes = $valid_rules = array_filter(array_map('trim', explode(',', $assoc_args['excludes'])));
     }
     $hm_backup->backup();
     WP_CLI::line('Backup: Deleting old backups...');
     // Delete any old backup files
     hmbkp_delete_old_backups();
     if (file_exists(HM_Backup::get_instance()->archive_filepath())) {
         WP_CLI::success('Backup Complete: ' . HM_Backup::get_instance()->archive_filepath());
     } else {
         WP_CLI::error('Backup Failed');
     }
 }