Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#55894 closed defect (bug) (invalid)

Where is the "wp_update_user_counts" action defined?

Reported by: tmatsuur's profile tmatsuur Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.0
Component: Users Keywords:
Focuses: Cc:

Description

Checking when the number of users is updated, we found the following statement

/wp-includes/default-filters.php : 108

add_action( 'wp_update_user_counts', 'wp_schedule_update_user_counts', 10, 0 );

The "wp_update_user_counts" function never calls the do_action function, and I do not know where the above callback function is called.

It is possible that some of the action names are defined using variables, but I could not find any description of this as far as I searched the source code.

I think you forgot to include the do_action function in the wp_update_user_counts function.

Change History (6)

#1 @knutsp
2 years ago

Related: #55890

#2 in reply to: ↑ description @SergeyBiryukov
2 years ago

Hi there, thanks for the ticket!

Replying to tmatsuur:

add_action( 'wp_update_user_counts', 'wp_schedule_update_user_counts', 10, 0 );

The "wp_update_user_counts" function never calls the do_action function, and I do not know where the above callback function is called.

It looks like the wp_update_user_counts action is scheduled via wp_schedule_event() in wp_schedule_update_user_counts() and then executed via call_user_func() in _wp_cron().

As far as I can tell, this is consistent with how other cron tasks run, e.g. wp_scheduled_auto_draft_delete, and does not require a do_action() call.

#3 @tmatsuur
2 years ago

Thanks @SergeyBiryukov

I was inadvertent.

The "wp_update_user_counts" specified in the wp_schedule_event function was the action name, not the function name.

Then the wp_schedule_update_user_counts function will call itself once every two days.

I don't think the wp_update_user_counts function is called, how is the number of users recalculated?

#4 @johnbillion
2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

It's a bit convoluted but the counts are regenerated via the wp_update_network_counts() function, which is attached to the twice-daily update_network_counts cron event, which is registered on admin_init.

https://github.com/WordPress/wordpress-develop/blob/c59af567e55de40b6f2f0a85aef73aff3944cca9/src/wp-includes/ms-functions.php#L2495-L2497

#5 @knutsp
2 years ago

From wp-settings.php line 337:

// Load multisite-specific files.
if ( is_multisite() ) {
        require ABSPATH . WPINC . '/ms-functions.php';

So this only work on multisite.

#6 @tmatsuur
2 years ago

Thanks @johnbillion @knutsp

It is clear that I am mistaken about the title, so I have no problem closing this thread.

As for the issue of the user count not being updated, I will look forward to another thread (#55890).

Thank you all very much.

Note: See TracTickets for help on using tickets.