Skip to content

Commit

Permalink
only load Install and Remote Management from settings pages
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Aug 22, 2018
1 parent 50a6b75 commit 6b4e1b7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* add `override` query arg for RESTful updates to specific tags
* refactor to remove redundancy between rollback and branch switch
* fixed incorrect update notification after update
* fixed to only load `Settings` on appropriate pages

#### 8.2.1 / 2018-07-22
* fixed setting of `Requires PHP` header in `API::set_readme_info()`
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, GitLab, or Gitea hosted plugins, themes, and language packs. It also allows for remote installation of plugins or themes into WordPress.
* Version: 8.2.1.5
* Version: 8.2.1.6
* Author: Andy Fragen
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down
13 changes: 9 additions & 4 deletions src/GitHub_Updater/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ public function run() {
$this->load_hooks();

// Need to ensure these classes are activated here for hooks to fire.
Singleton::get_instance( 'Install', $this )->run();
Singleton::get_instance( 'Remote_Management', $this );
if ( $this->is_current_page( [ 'options-general.php', 'settings.php' ] ) ) {
Singleton::get_instance( 'Install', $this )->run();
Singleton::get_instance( 'Remote_Management', $this );
}
}

/**
Expand All @@ -87,15 +89,18 @@ public function run() {
protected function load_hooks() {
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', [ $this, 'add_plugin_page' ] );
add_action( 'network_admin_edit_github-updater', [ $this, 'update_settings' ] );
add_action( 'admin_init', [ $this, 'update_settings' ] );
add_action( 'admin_init', [ $this, 'page_init' ] );

add_filter(
is_multisite()
? 'network_admin_plugin_action_links_' . $this->ghu_plugin_name
: 'plugin_action_links_' . $this->ghu_plugin_name,
[ $this, 'plugin_action_links' ]
);

if ( $this->is_current_page( [ 'options.php', 'options-general.php', 'settings.php' ] ) ) {
add_action( 'admin_init', [ $this, 'update_settings' ] );
add_action( 'admin_init', [ $this, 'page_init' ] );
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/GitHub_Updater/Traits/GHU_Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ public function load_options() {
$base::$options = get_site_option( 'github_updater', [] );
}

/**
* Check current page.
*
* @param array $pages
* @return bool
*/
public function is_current_page( array $pages ) {
global $pagenow;
return in_array( $pagenow, $pages );
}

/**
* Returns repo cached data.
*
Expand Down

1 comment on commit 6b4e1b7

@afragen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #711

Please sign in to comment.