Title: How to reduce plugin-notification load on every page
Last modified: August 19, 2024

---

# How to reduce plugin-notification load on every page

 *  Resolved [veppa](https://wordpress.org/support/users/veppa/)
 * (@veppa)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/reduce-3/)
 * Hello. Nice plugin and great features.
 * I have a question.
 * Is there a way to reduce plugin-notification load to once every day.
 * [https://groundho.gg/wp-json/wp/v2/plugin-notification/](https://groundho.gg/wp-json/wp/v2/plugin-notification/)
 * In order to optimize wp, I disabled external requests. And now it tries to load
   it on every page when I am logged in.
 * It was trying to load it twice per page.
 * 1st — in ‘admin_print_styles’.
 * 2nd — in do_action(‘wp_after_admin_bar_render’)
 * I managed to remove 2nd by removing groundhogg from admin bar. In settings — 
   misc tab. (Thanks for having that option)
 * Here is how 1st one called.
 *     ```wp-block-code
       "Groundhogg\\Notices->count_unread",      "Groundhogg\\maybe_print_menu_styles",      "WP_Hook->apply_filters",      "WP_Hook->do_action",      "do_action('admin_print_styles')",      "require_once('wp-admin/admin-header.php')",      "require_once('wp-admin/admin.php')"
       ```
   
 * Is there a way to reduce number of checks to 1 per day even if it was not successfully
   loaded for couple days or weeks?
 * ps: other plugins also load latest news/notifications from ther website. But 
   they are not trying it too hard to load it on every page when last try failed.
 * Suggestion: it might be better to load notification inside cronjob, ajax or internal
   rest api. (In order to not slow down page generation of wordpress admin interface).
   Best solution I think once per day cron job.
 * Thank you.
    -  This topic was modified 1 year, 7 months ago by [veppa](https://wordpress.org/support/users/veppa/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Adrian Tobey](https://wordpress.org/support/users/trainingbusinesspros/)
 * (@trainingbusinesspros)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/reduce-3/#post-17963159)
 * Hi, thanks for reaching out.
 * As a matter of fact, we do only try to check at most once per day, certainly 
   not on every page load!
 * Our code looks as follows:
 *     ```wp-block-code
       $ids = get_transient( 'gh_notification_ids' );if ( empty( $ids ) || ! is_array( $ids ) ) {	$ids = wp_parse_id_list( wp_list_pluck( $this->fetch_remote_notices(), 'id' ) );	set_transient( 'gh_notification_ids', $ids, DAY_IN_SECONDS );}return count( array_diff( $ids, array_values( Notices::$read_notices ) ) );
       ```
   
 * Basically, we store the notification IDs in a transient which is saved for 1 
   day.
 * If you are seeing the request on every page load it might be a result of transients
   not working on your site, which would affect more that Groundhogg.
 *  Thread Starter [veppa](https://wordpress.org/support/users/veppa/)
 * (@veppa)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/reduce-3/#post-17968937)
 * Ok. In above code what happens when $ids emty because of network error or blog
   blocking external requests.
 * It will store empty ids. Then on next page will request ids from remote server
   again. And this will be repeated on every page.
 * Issue can be reproduced following these steps:
    - You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true
      in your wp-config.php file. Ref [https://developer.wordpress.org/reference/classes/wp_http/block_request/](https://developer.wordpress.org/reference/classes/wp_http/block_request/)
    - wait 1 day until transient expires or delete it.
    - navigate in admin with “query monitor” to view api calls as you visit pages.
 * Regards.
 *  Plugin Author [Adrian Tobey](https://wordpress.org/support/users/trainingbusinesspros/)
 * (@trainingbusinesspros)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/reduce-3/#post-17973561)
 * In your example, shouldn’t the act of setting WP_HTTP_BLOCK_EXTERNAL to true 
   prevent the remote network request though?
 *  Plugin Author [Adrian Tobey](https://wordpress.org/support/users/trainingbusinesspros/)
 * (@trainingbusinesspros)
 * [1 year, 7 months ago](https://wordpress.org/support/topic/reduce-3/#post-17976308)
 * Regardless, our next version changes the following.
 *     ```wp-block-code
       function count_unread() {	$ids = get_transient( 'gh_notification_ids' );        // expired, fetch from remote	if ( $ids === false ) {		$ids = wp_parse_id_list( wp_list_pluck( $this->fetch_remote_notices(), 'id' ) );		set_transient( 'gh_notification_ids', $ids, DAY_IN_SECONDS );	}	return count( array_diff( $ids, array_values( Notices::$read_notices ) ) );}
       ```
   
 * If the remote network request fails, an empty array will be stored in the transient.
   Only when the transient is **explicitly **false will Groundhogg attempt to retrieve
   notices from the remote network.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How to reduce plugin-notification load on every page’ is closed to new
replies.

 * ![](https://ps.w.org/groundhogg/assets/icon-256x256.png?rev=2692093)
 * [Groundhogg — CRM, Newsletters, and Marketing Automation](https://wordpress.org/plugins/groundhogg/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/groundhogg/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/groundhogg/)
 * [Active Topics](https://wordpress.org/support/plugin/groundhogg/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/groundhogg/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/groundhogg/reviews/)

## Tags

 * [performance](https://wordpress.org/support/topic-tag/performance/)

 * 4 replies
 * 2 participants
 * Last reply from: [Adrian Tobey](https://wordpress.org/support/users/trainingbusinesspros/)
 * Last activity: [1 year, 7 months ago](https://wordpress.org/support/topic/reduce-3/#post-17976308)
 * Status: resolved