[Solved! Thanks ChatGPT] Logging in via Patreon oAuth causes error “There has been a critical error on this website.”

I tried to submit a support ticket on codebard.com but all my line breaks got deleted, making it very hard to read.

Here’s the error get when I try to login using oAuth.


2023/01/29 10:27:57 [error] 27317#27317: *123 FastCGI sent in stderr: “PHP message: PHP Fatal error: Uncaught TypeError: Unsupported operand types: string * int in /var/www/sensei.richpav.xyz/htdocs/wp-content/plugins/patron-plugin-pro/plugin/plugin.php:4201
Stack trace:
#0 /var/www/sensei.richpav.xyz/htdocs/wp-content/plugins/patron-plugin-pro/index.php(309): cb_p6_a1_plugin->hook_into_patreon_user_creation_and_login_process_p()
#1 /var/www/sensei.richpav.xyz/htdocs/wp-includes/class-wp-hook.php(308): cb_p6_a1_core->__call()
#2 /var/www/sensei.richpav.xyz/htdocs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#3 /var/www/sensei.richpav.xyz/htdocs/wp-includes/plugin.php(517): WP_Hook->do_action()
#4 /var/www/sensei.richpav.xyz/htdocs/wp-content/plugins/patron-plugin-pro/plugin/lib/patreon-connect/classes/patreon_login.php(216): do_action()
#5 /var/www/sensei.richpav.xyz/htdocs/wp-content/plugins/patron-plugin-pro/plugin/lib/patreon-connect/classes/patreon_routing.php(590): Patreon_Login::createOrLogInUserFromPatreon()
#6 /var/www/sensei.richpav.xyz/htdo” while reading response header from upstream, client: 126.130.127.86, server: sensei.richpav.xyz, request: “GET /patreon-authorization/?code=9l1K7P3EaDJyeLrJryCgQ8AHNbjgTj&state=eyJmaW5hbF9yZWRpcmVjdF91cmkiOiJodHRwczpcL1wvc2Vuc2VpLnJpY2hwYXYueHl6In0%3D HTTP/2.0”, upstream: “fastcgi://unix:/var/run/php/php81-two-fpm.sock:”, host: “sensei.richpav.xyz”, referrer: “https://www.patreon.com/


The error “Uncaught TypeError: Unsupported operand types: string * int” is caused by a a string is being multiplied by an integer, probably here:

if($user_patronage opt['content_locking']['only_patrons_with_amount']*100)

var_dump() shows string(0) ""

Does that mean it’s expecting that variable to be an integer but it’s being passed as a string AND it’s an empty string?

I’m not the best programmer. I’m learning as I go here. I’m hoping you can help me out.

Plugin info:

WP 6.1.1 with PHP 8.1.14
Patreon WordPress 1.8.5 with API v2
Patron Plugin Pro 1.5.3
Patreon Button, Widgets and Plugin 2.1.6

I figured out the problem. I had this field blank instead of set to 0.

Changing line 442 of /patron_plugin_pro/plugin/includes/setting_sections/content_locking.php to this might avoid the problem:

$<input type="text" size="4" name="opt[<?php echo $this->internal['prefix'].$tab; ?>][only_patrons_with_amount]" value="<?php echo (!empty($this->opt[$tab]['only_patrons_with_amount'])) ? $this->opt[$tab]['only_patrons_with_amount'] : 0; ?>">

Works for me. It uses a ternary operator to check if the value of $this->opt[$tab]['only_patrons_with_amount'] is not empty. If it is not empty, it will use the value of $this->opt[$tab]['only_patrons_with_amount'], otherwise it will use 0 as the value. It will then set this value as the input field’s value.

This fix was brought to you by ChatGPT. I never would have figured this out otherwise.

Yes, adding a default value to enforce numbers there may be a good idea.