@andrewshu
Non-logged in users were not tested at all.
The only trace posted in the other thread was with a non logged in user.
At my test site I have reproduced this bug with the user logged in as well.
Error message: 503 Service Unavailable.
WP 6.1.1
UM 2.5.4
User role um_member
First part of my test system stack trace at the action hook posts_selection
2023-03-26 08:46:29 Memory Usage Trace for User ID:2 Allocated:84MB Used:81MB
Current SQL: AND (
wpcb_postmeta.meta_key = 'um_content_restriction'
) AND wpcb_posts.post_type IN ('post', 'page') AND ((wpcb_posts.post_status <> 'trash' AND wpcb_posts.post_status <> 'auto-draft'))wpcb_posts.IDwpcb_posts.post_date DESC INNER JOIN wpcb_postmeta ON ( wpcb_posts.ID = wpcb_postmeta.post_id )
Stack trace:
#0 wp-includes/class-wp-hook.php(308): posts_selection_memory_usage(' AND ( \n wpcb_...')
#1 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#2 wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#3 wp-includes/class-wp-query.php(2921): do_action('posts_selection', ' AND ( \n wpcb_...')
#4 wp-includes/class-wp-query.php(3749): WP_Query->get_posts()
#5 wp-includes/post.php(2415): WP_Query->query(Array)
#6 wp-content/plugins/ultimate-member/includes/core/class-access.php(204): get_posts(Array)
#7 wp-content/plugins/ultimate-member/includes/core/class-access.php(852): um\core\Access->exclude_posts_array(true, Array)
#8 wp-includes/class-wp-hook.php(308): um\core\Access->exclude_posts_comments(Object(WP_Comment_Query))
#9 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#10 wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#11 wp-includes/class-wp-comment-query.php(394): do_action_ref_array('pre_get_comment...', Array)
#12 wp-includes/class-wp-comment-query.php(366): WP_Comment_Query->get_comments()
#13 wp-includes/comment.php(244): WP_Comment_Query->query(Array)
#14 wp-content/themes/twentytwenty/functions.php(866): get_comments(Array)
#15 wp-includes/class-wp-hook.php(308): um_072522_add_comment_count(Array)
#16 wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
#17 wp-content/plugins/ultimate-member/includes/core/class-profile.php(156): apply_filters('um_profile_tabs', Array)
#18 wp-content/plugins/ultimate-member/includes/class-config.php(592): um\core\Profile->tabs()
#19 wp-content/plugins/ultimate-member/includes/class-init.php(1000): um\Config->__construct()
#20 wp-content/plugins/ultimate-member/includes/um-short-functions.php(1285): UM->config()
#21 wp-content/plugins/ultimate-member/includes/core/class-access.php(1874): um_is_core_post(Object(WP_Post), 'login')
#22 wp-content/plugins/ultimate-member/includes/core/class-access.php(2089): um\core\Access->get_post_privacy_settings(Object(WP_Post))
#23 wp-content/plugins/ultimate-member/includes/core/class-access.php(317): um\core\Access->is_restricted(102)
#24 wp-content/plugins/ultimate-member/includes/core/class-access.php(852): um\core\Access->exclude_posts_array(true, Array)
#25 wp-includes/class-wp-hook.php(308): um\core\Access->exclude_posts_comments(Object(WP_Comment_Query))
#26 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#27 wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#28 wp-includes/class-wp-comment-query.php(394): do_action_ref_array('pre_get_comment...', Array)
#29 wp-includes/class-wp-comment-query.php(366): WP_Comment_Query->get_comments()
#30 wp-includes/comment.php(244): WP_Comment_Query->query(Array)
#31 wp-content/themes/twentytwenty/functions.php(866): get_comments(Array)
#32 wp-includes/class-wp-hook.php(308): um_072522_add_comment_count(Array)
#33 wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
#34 wp-content/plugins/ultimate-member/includes/core/class-profile.php(156): apply_filters('um_profile_tabs', Array)
#35 wp-content/plugins/ultimate-member/includes/class-config.php(592): um\core\Profile->tabs()
#36 wp-content/plugins/ultimate-member/includes/class-init.php(1000): um\Config->__construct()
#37 wp-content/plugins/ultimate-member/includes/um-short-functions.php(1285): UM->config()
#38 wp-content/plugins/ultimate-member/includes/core/class-access.php(1874): um_is_core_post(Object(WP_Post), 'login')
#39 wp-content/plugins/ultimate-member/includes/core/class-access.php(2089): um\core\Access->get_post_privacy_settings(Object(WP_Post))
#40 wp-content/plugins/ultimate-member/includes/core/class-access.php(317): um\core\Access->is_restricted(102)
#41 wp-content/plugins/ultimate-member/includes/core/class-access.php(852): um\core\Access->exclude_posts_array(true, Array)
#42 wp-includes/class-wp-hook.php(308): um\core\Access->exclude_posts_comments(Object(WP_Comment_Query))
#43 wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array)
#44 wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#45 wp-includes/class-wp-comment-query.php(394): do_action_ref_array('pre_get_comment...', Array)
#46 wp-includes/class-wp-comment-query.php(366): WP_Comment_Query->get_comments()
#47 wp-includes/comment.php(244): WP_Comment_Query->query(Array)
#48 wp-content/themes/twentytwenty/functions.php(866): get_comments(Array)
#49 wp-includes/class-wp-hook.php(308): um_072522_add_comment_count(Array)
Code snippet used
add_filter( 'um_profile_tabs', 'um_072522_add_comment_count', 10 );
function um_072522_add_comment_count( $tabs ){
if ( isset( $tabs['comments'] ) && is_user_logged_in() && ! isset( $tabs['comments']['notifier'] )) {
$args = array(
'user_id' => um_profile_id(), // Use user_id.
'count' => true // Return only the count.
);
$comments_count = get_comments( $args );
$tabs['comments']['notifier'] = $comments_count;
}
return $tabs;
}
Changing filter hook to um_user_profile_tabs
all works OK.