• Resolved veppa

    (@veppa)


    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/

    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.

    "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 3 months ago by veppa.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Adrian Tobey

    (@trainingbusinesspros)

    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:

    $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

    (@veppa)

    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:

    Regards.

    Plugin Author Adrian Tobey

    (@trainingbusinesspros)

    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

    (@trainingbusinesspros)

    Regardless, our next version changes the following.

    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)
  • You must be logged in to reply to this topic.