which has count_user_posts call which is uncached and hits DB every time.

I have worked on few WordPress VIP projects for same reasons I configured My editor ( Netbeans ) to check for WP coding Standards it gives me warning about count_users_posts and asked me to use wpcom_vip_count_user_posts instead because count_users_posts uncached.

So I have to make it’s result cached somehow,

Firstly I Google ( don’t judge me everybody does it. 😀 ) for some solution but found nothing even on 4th search page thats deep web for me .

finally after some debugging, I decided to replace permission_callback for wp/v2/users/{id} route with cached function with custom code as follows.

The Cached permission callback is similar function as core with only one twist different callback for user post count 😀

The cached_count_users_posts function is clone of WordPress VIP function wpcom_vip_count_user_posts

This will offload your DB hits, it’s will very helpful while handling heavy weight WordPress sites, until that core ticket is answered and closed, I will try to contribute on that core ticket and that should be our the long term plan.