SOLVED: Bricks Settings page fatal error "Allowed memory size exhausted" if many Users in DB

Browser: Chrome 123 / Brave 1.64
OS: Windows 10 / Debian Linux
WP: 6.5, 6.4
PHP: 7.4, 8.2
Bricks: 1.9.7.1
Video: Jam

When updating a Bricks site to 1.9.7.1, the Bricks → Settings page would not load for me (white screen). I cloned the site to a local env to debug. By disabling all plugins I could get the Settings page to partially load, however tabs navigation was broken and the Save button missing entirely. Using debug I found the page load was triggering a fatal error: Allowed memory size exhausted. There are almost 5000 users on this website, and it looked to me like a Users query could be the cause of the issue. By commenting out one section of code in the includes/admin/admin-screen-settings.php file I was able to get the settings page to load.

  • admin-screen-settings.php
    (commented out lines 2040-2046 to get the settings page working, but I have no idea if this will negatively impact the code review, I’ll hold off on updating this site until I find out more)
foreach ( get_users() as $user ) {
	$user_can = array_keys( $user->caps );

	if ( in_array( Capabilities::EXECUTE_CODE, $user_can ) ) {
		$users_with_execute_code_cap[] = $user;
	}
}

I hope this helps,
Andrew B Miller

Hi Andrew,
Welcome to the forum, and thanks so much for your report!

What value is your WP memory limit currently set to? You can see the value (and possibly a hint on how to increase the memory limit) in Bricks » System Information.

Increasing the memory limit should actually solve the problem. As stated in the Bricks settings, the recommended limit is 64mb upwards.

Best regards,
timmse

Hi @timmse - thanks for reply. The WP memory limit on my production installation is already 256MB:

Hm… that’s odd.

Would you be so kind as to send temporary login credentials and a link to this thread to help@bricksbuilder.io using the email address you used during the purchase?

Client owns the theme license, and I’m not comfortable with sharing admin access to a client production website, albeit temporary. I could spin up a stripped down clone for you on a public dev domain, if that helps?

If the problem also occurs there: yes!

OK – I’ll get that clone setup today / tonight. Do I send it to help@bricksbuilder.io as previously instructed?

Yes, please. And please add a link to this thread :v:

Came here to report this same thing, so just confirming I’m seeing the same issue as well.

Also confirmed that it’s originating with the get_users() query - there are just too many users in the DB to run this query. (Tried upping the memory all the way to 512M and still exceeded it).

46,000 users for reference.

If I make the query just search admins and editors, it runs without any issue

foreach ( get_users(['role' => ['admin','editor']]) as $user ) {

I’m guessing the approach will need to be to store an inclusive list of users separately, rather than querying every user to determine the “Individual users with code execution capabilities”. Or at least exclude users who don’t have builder access in the first place from the query.

Thanks team!

Hi @SweaterVest & @chrism ,

Thanks for reporting the issue.
This has been reported via email by another user and we already got a fix in the next release.
Meanwhile, if you want to use Bricks 1.9.7.1, you can change the code manually in the Bricks theme.

includes/admin/admin-screen-settings.php line 2041 - 2049 replace with these

$users_with_execute_code_cap = get_users(
    [
        'role' => Capabilities::EXECUTE_CODE,
    ]
);

The final code should look like this.

Regards,
Jenn

2 Likes

Hi guys,

We’ve fixed this issue in Bricks 1.9.8 beta, now available as a manual download in your account (see changelog).

Please let us know if you are still experiencing issues.

As with any beta release, please do not use it on a production or live website. It is only meant for testing in a local or staging environment.