Skip to content

Commit

Permalink
refactor function to update settings
Browse files Browse the repository at this point in the history
works for both network activated and single site installs
  • Loading branch information
afragen committed Aug 5, 2016
1 parent a805910 commit 13572c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* fixed PHP errors in Settings page
* fixed saving issues with checkboxes
* added one day dismissal of admin notices using [persist-admin-notices-dismissal library](https://github.com/collizo4sky/persist-admin-notices-dismissal), well my PR of it ;-)
* refactored function to update settings to work for both single/multisite

#### 5.5.0
* better internationalization for changing plugin _View details_ link
Expand Down
2 changes: 1 addition & 1 deletion github-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Plugin Name: GitHub Updater
* Plugin URI: https://github.com/afragen/github-updater
* Description: A plugin to automatically update GitHub, Bitbucket, or GitLab hosted plugins and themes. It also allows for remote installation of plugins or themes into WordPress.
* Version: 5.5.0.14
* Version: 5.5.0.15
* Author: Andy Fragen
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
32 changes: 12 additions & 20 deletions src/GitHub_Updater/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct() {
$this->ensure_api_key_is_set();

add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( &$this, 'add_plugin_page' ) );
add_action( 'network_admin_edit_github-updater', array( &$this, 'update_network_setting' ) );
add_action( 'network_admin_edit_github-updater', array( &$this, 'update_settings' ) );
add_action( 'admin_init', array( &$this, 'page_init' ) );
add_action( 'admin_init', array( &$this, 'remote_management_page_init' ) );

Expand Down Expand Up @@ -355,10 +355,7 @@ public function page_init() {
);
}

if ( isset( $_POST['github_updater'] ) && ! is_multisite() ) {
update_site_option( 'github_updater', self::sanitize( $_POST['github_updater'] ) );
}
$this->redirect_on_save();
$this->update_settings();
}

/**
Expand Down Expand Up @@ -524,13 +521,7 @@ public function remote_management_page_init() {
);
}

if ( isset( $_POST['option_page'] ) &&
'github_updater_remote_management' === $_POST['option_page'] &&
! is_multisite()
) {
update_site_option( 'github_updater_remote_management', (array) self::sanitize( $_POST['github_updater_remote_management'] ) );
$this->redirect_on_save();
}
$this->update_settings();
}

/**
Expand Down Expand Up @@ -669,18 +660,19 @@ public function token_callback_checkbox_remote( $args ) {
}

/**
* Update network settings.
* Used when plugin is network activated to save settings.
* Update settings when single site or network activated.
*
* @link http://wordpress.stackexchange.com/questions/64968/settings-api-in-multisite-missing-update-message
* @link http://benohead.com/wordpress-network-wide-plugin-settings/
*/
public function update_network_setting() {
if ( 'github_updater' === $_POST['option_page'] ) {
update_site_option( 'github_updater', self::sanitize( $_POST['github_updater'] ) );
}
if ( 'github_updater_remote_management' === $_POST['option_page'] ) {
update_site_option( 'github_updater_remote_management', (array) self::sanitize( $_POST['github_updater_remote_management'] ) );
public function update_settings() {
if ( isset( $_POST['option_page'] ) ) {
if ( 'github_updater' === $_POST['option_page'] ) {
update_site_option( 'github_updater', self::sanitize( $_POST['github_updater'] ) );
}
if ( 'github_updater_remote_management' === $_POST['option_page'] ) {
update_site_option( 'github_updater_remote_management', (array) self::sanitize( $_POST['github_updater_remote_management'] ) );
}
}
$this->redirect_on_save();
}
Expand Down

0 comments on commit 13572c3

Please sign in to comment.