public function ajax_disable_updates() { if (!current_user_can('install_plugins')) { return; } $options = MPSUM_Updates_Manager::get_options('core'); $options = wp_parse_args($options, MPSUM_Admin_Core::get_defaults()); if ('on' == $_POST['new_val']) { $options['all_updates'] = 'on'; } else { $options['all_updates'] = 'off'; } MPSUM_Updates_Manager::update_options($options, 'core'); if ($options['all_updates'] == 'off') { $return = array('core_updates_off', 'plugin_updates_off', 'theme_updates_off', 'translation_updates_off'); } else { $return = array(); } die(json_encode($return)); }
/** * Determine whether the save the main options or not. * * Determine whether the save the main options or not. * * @since 5.0.0 * @access public * @see __construct * @internal Uses admin_init action * */ public function maybe_save_options() { if (!current_user_can('update_core')) { return; } if (!isset($_GET['page']) || $_GET['page'] != $this->slug) { return; } if (!isset($_REQUEST['action'])) { return; } if (!isset($_POST['options'])) { return; } if ('mpsum_save_core_options' !== $_REQUEST['action']) { return; } check_admin_referer('mpsum_main_update', '_mpsum'); $query_args = array(); $query_args['updated'] = "1"; //Save options $options = $_POST['options']; if (isset($_POST['reset'])) { $options = $this->get_defaults(); } $options_to_save = array(); foreach ($options as $key => $value) { $option_value = sanitize_text_field($value); $options_to_save[sanitize_key($key)] = $option_value; } MPSUM_Updates_Manager::update_options($options_to_save, 'core'); //Redirect back to settings screen wp_redirect(esc_url_raw(add_query_arg($query_args, MPSUM_Admin::get_url()))); exit; }
/** * Determine whether the save the advanced options or not. * * Determine whether the save the advanced options or not. * * @since 5.0.0 * @access public * @see __construct * @internal Uses admin_init action * */ public function maybe_save_options() { if (!current_user_can('update_core')) { return; } if (!isset($_GET['page']) || $_GET['page'] != $this->slug) { return; } if (!isset($_POST['action'])) { return; } if (!isset($_POST['_mpsum'])) { return; } //Get action $action = $_POST['action']; if (empty($action)) { return; } switch ($action) { case 'mpsum_save_excluded_users': check_admin_referer('mpsum_exclude_users', '_mpsum'); $users = $_POST['mpsum_excluded_users']; if (!is_array($users) || empty($users)) { return; } $users_to_save = array(); foreach ($users as $index => $user_id) { $user_id = absint($user_id); if (0 === $user_id) { continue; } $users_to_save[] = $user_id; } MPSUM_Updates_Manager::update_options($users_to_save, 'excluded_users'); break; case 'mpsum_reset_options': check_admin_referer('mpsum_reset_options', '_mpsum'); MPSUM_Updates_Manager::update_options(array()); break; case 'mpsum_force_updates': wp_schedule_single_event(time() + 10, 'wp_update_plugins'); wp_schedule_single_event(time() + 10, 'wp_version_check'); wp_schedule_single_event(time() + 10, 'wp_update_themes'); wp_schedule_single_event(time() + 45, 'wp_maybe_auto_update'); break; default: return; } //Redirect args $query_args = array(); $query_args['updated'] = "1"; $query_args['tab'] = $this->tab; $query_args['mpaction'] = $action; //Redirect back to settings screen wp_redirect(esc_url_raw(add_query_arg($query_args, MPSUM_Admin::get_url()))); exit; }
/** * Save the theme options based on the passed action. * * Save the theme options based on the passed action. * * @since 5.0.0 * @access private * @see maybe_save_theme_options * @param string $action Action to take action on * */ private function save_theme_update_options($action) { //Check capability $capability = 'update_themes'; //On single site, admins can use this, on multisite, only network admins can if (!current_user_can($capability)) { return; } $themes = isset($_REQUEST['checked']) ? (array) $_REQUEST['checked'] : array(); $theme_options = MPSUM_Updates_Manager::get_options('themes'); $theme_automatic_options = MPSUM_Updates_Manager::get_options('themes_automatic'); switch ($action) { case 'disallow-update-selected': foreach ($themes as $theme) { $theme_options[] = $theme; if (($key = array_search($theme, $theme_automatic_options)) !== false) { unset($theme_automatic_options[$key]); } } break; case 'allow-update-selected': foreach ($themes as $theme) { if (($key = array_search($theme, $theme_options)) !== false) { unset($theme_options[$key]); } } break; case 'allow-automatic-selected': foreach ($themes as $theme) { $theme_automatic_options[] = $theme; if (($key = array_search($theme, $theme_options)) !== false) { unset($theme_options[$key]); } } break; case 'disallow-automatic-selected': foreach ($themes as $theme) { if (($key = array_search($theme, $theme_automatic_options)) !== false) { unset($theme_automatic_options[$key]); } } break; default: return; } //Check nonce check_admin_referer('mpsum_theme_update', '_mpsum'); //Update option $theme_options = array_values(array_unique($theme_options)); $theme_automatic_options = array_values(array_unique($theme_automatic_options)); $options = MPSUM_Updates_Manager::get_options(); $options['themes'] = $theme_options; $options['themes_automatic'] = $theme_automatic_options; MPSUM_Updates_Manager::update_options($options); }