Automattic\WooCommerce\Internal\Admin\Notes

WooSubscriptionsNotes::admin_head()publicWC 1.0

Runs on admin_head Checks the connection and refreshes subscription notes on relevant pages.

Метод класса: WooSubscriptionsNotes{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WooSubscriptionsNotes = new WooSubscriptionsNotes();
$WooSubscriptionsNotes->admin_head();

Код WooSubscriptionsNotes::admin_head() WC 8.7.0

public function admin_head() {
	if ( ! 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 or a WC related page which includes
		// the Activity button in WC header.
		return;
	}

	$this->check_connection();

	if ( $this->is_connected() ) {
		$refresh_notes = false;

		// Did the user just do something on the helper page?.
		if ( isset( $_GET['wc-helper-status'] ) ) { // @codingStandardsIgnoreLine.
			$refresh_notes = true;
		}

		// Has it been more than a day since we last checked?
		// Note: We do it this way and not wp_scheduled_task since WC_Helper_Options is not loaded for cron.
		$time_now_gmt = current_time( 'timestamp', 0 );
		$last_refresh = intval( get_option( self::LAST_REFRESH_OPTION_KEY, 0 ) );
		if ( $last_refresh + DAY_IN_SECONDS <= $time_now_gmt ) {
			update_option( self::LAST_REFRESH_OPTION_KEY, $time_now_gmt );
			$refresh_notes = true;
		}

		if ( $refresh_notes ) {
			$this->refresh_subscription_notes();
		}
	}
}