admin.php
6 years ago
backup-handler.php
7 years ago
backup.php
6 years ago
cap-helper.php
6 years ago
filters-admin.php
6 years ago
filters-woocommerce.php
7 years ago
filters-wp_rest_workarounds.php
6 years ago
filters.php
6 years ago
functions-admin.php
6 years ago
functions.php
6 years ago
handler.php
6 years ago
inflect-cme.php
7 years ago
manager.php
6 years ago
network.php
6 years ago
pp-handler.php
6 years ago
pp-ui.php
6 years ago
publishpress-roles.php
6 years ago
backup-handler.php
115 lines
| 1 | <?php |
| 2 | |
| 3 | class Capsman_BackupHandler |
| 4 | { |
| 5 | var $cm; |
| 6 | |
| 7 | function __construct( $manager_obj ) { |
| 8 | if ( ! is_super_admin() && ! current_user_can( 'restore_roles' ) ) |
| 9 | wp_die( __( 'You do not have permission to restore roles.', 'capsman-enhanced' ) ); |
| 10 | |
| 11 | $this->cm = $manager_obj; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Processes backups and restores. |
| 16 | * |
| 17 | * @return void |
| 18 | */ |
| 19 | function processBackupTool () |
| 20 | { |
| 21 | if ( isset($_POST['Perform']) ) { |
| 22 | check_admin_referer('capsman-backup-tool'); |
| 23 | |
| 24 | global $wpdb; |
| 25 | $wp_roles = $wpdb->prefix . 'user_roles'; |
| 26 | $cm_roles = $this->cm->ID . '_backup'; |
| 27 | $cm_roles_initial = $this->cm->ID . '_backup_initial'; |
| 28 | |
| 29 | switch ( $_POST['action'] ) { |
| 30 | case 'backup': |
| 31 | if ( ! get_option( $cm_roles_initial ) ) { |
| 32 | if ( $current_backup = get_option( $cm_roles ) ) { |
| 33 | update_option( $cm_roles_initial, $current_backup, false ); |
| 34 | |
| 35 | if ( $initial_datestamp = get_option( $this->cm->ID . '_backup_datestamp' ) ) { |
| 36 | update_option($this->cm->ID . '_backup_initial_datestamp', $initial_datestamp, false ); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | $roles = get_option($wp_roles); |
| 42 | update_option($cm_roles, $roles, false); |
| 43 | update_option($this->cm->ID . '_backup_datestamp', current_time( 'timestamp' ), false ); |
| 44 | ak_admin_notify(__('New backup saved.', 'capsman-enhanced')); |
| 45 | break; |
| 46 | |
| 47 | case 'restore_initial': |
| 48 | $roles = get_option($cm_roles_initial); |
| 49 | if ( $roles ) { |
| 50 | update_option($wp_roles, $roles); |
| 51 | ak_admin_notify(__('Roles and Capabilities restored from initial backup.', 'capsman-enhanced')); |
| 52 | } else { |
| 53 | ak_admin_error(__('Restore failed. No backup found.', 'capsman-enhanced')); |
| 54 | } |
| 55 | break; |
| 56 | |
| 57 | case 'restore': |
| 58 | $roles = get_option($cm_roles); |
| 59 | if ( $roles ) { |
| 60 | update_option($wp_roles, $roles); |
| 61 | ak_admin_notify(__('Roles and Capabilities restored from last backup.', 'capsman-enhanced')); |
| 62 | } else { |
| 63 | ak_admin_error(__('Restore failed. No backup found.', 'capsman-enhanced')); |
| 64 | } |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Resets roles to WordPress defaults. |
| 72 | * |
| 73 | * @return void |
| 74 | */ |
| 75 | function backupToolReset () |
| 76 | { |
| 77 | check_admin_referer('capsman-reset-defaults'); |
| 78 | |
| 79 | require_once(ABSPATH . 'wp-admin/includes/schema.php'); |
| 80 | |
| 81 | if ( ! function_exists('populate_roles') ) { |
| 82 | ak_admin_error(__('Needed function to create default roles not found!', 'capsman-enhanced')); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | $roles = array_keys( ak_get_roles(true) ); |
| 87 | |
| 88 | foreach ( $roles as $role) { |
| 89 | remove_role($role); |
| 90 | } |
| 91 | |
| 92 | populate_roles(); |
| 93 | $this->cm->setAdminCapability(); |
| 94 | |
| 95 | $msg = __('Roles and Capabilities reset to WordPress defaults', 'capsman-enhanced'); |
| 96 | |
| 97 | if ( function_exists( 'pp_populate_roles' ) ) { |
| 98 | pp_populate_roles(); |
| 99 | } else { |
| 100 | // force PP to repopulate roles |
| 101 | $pp_ver = get_option( 'pp_c_version', true ); |
| 102 | if ( $pp_ver && is_array($pp_ver) ) { |
| 103 | $pp_ver['version'] = ( preg_match( "/dev|alpha|beta|rc/i", $pp_ver['version'] ) ) ? '0.1-beta' : 0.1; |
| 104 | } else { |
| 105 | $pp_ver = array( 'version' => '0.1', 'db_version' => '1.0' ); |
| 106 | } |
| 107 | |
| 108 | update_option( 'pp_c_version', $pp_ver ); |
| 109 | delete_option( 'ppperm_added_role_caps_10beta' ); |
| 110 | } |
| 111 | |
| 112 | ak_admin_notify($msg); |
| 113 | } |
| 114 | } |
| 115 |