Skip to content

Commit

Permalink
Use admin_head hook instead of admin_init to load subscriptions notes.
Browse files Browse the repository at this point in the history
Since `get_current_screen` function can not be called within `admin-init` hook it is not possible to determine if the subscriptions are being loaded via WC related page or not.
  • Loading branch information
thilinah committed Jun 2, 2023
1 parent 6bea718 commit 5575593
Showing 1 changed file with 6 additions and 10 deletions.
Expand Up @@ -36,7 +36,7 @@ private function get_bump_thresholds() {
* Hook all the things.
*/
public function __construct() {
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_head', array( $this, 'admin_head' ) );
add_action( 'update_option_woocommerce_helper_data', array( $this, 'update_option_woocommerce_helper_data' ), 10, 2 );
}

Expand Down Expand Up @@ -75,17 +75,13 @@ public function update_option_woocommerce_helper_data( $old_value, $value ) {
}

/**
* Things to do on admin_init.
* Things to do on admin_head.
*/
public function admin_init() {
if ( ! isset( $_GET['page'] ) ) {
// If the page parameter is not set, then the request is not initiated from the wc admin dashboard.
return;
}

if ( 'wc-addons' !== $_GET['page'] && 'wc-admin' !== $_GET['page'] ) {
public function admin_head() {
if ( ! \Automattic\WooCommerce\Admin\PageController::is_admin_or_embed_page() ) {
// To avoid unnecessarily calling Helper API, we only want to refresh subscription notes,
// if the request is initiated from the wc admin dashboard.
// if the request is initiated from the wc admin dashboard or a WC related page which includes
// the Activity button in WC header.
return;
}

Expand Down

0 comments on commit 5575593

Please sign in to comment.