Skip to content

Commit

Permalink
Fix: prevent PHP 8+ fatal errors when Tributes add-on is enabled (#7572)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva authored Oct 15, 2024
1 parent 1de05ae commit 9bfae6c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions includes/process-donation.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ function give_donation_form_validate_fields() {
/**
* Detect serialized fields.
*
* @unreleased Make sure only string parameters are used with the ltrim() method to prevent PHP 8+ fatal errors
* @since 3.16.4 updated to check all values for serialized fields
* @since 3.16.2 added additional check for stripslashes_deep
* @since 3.14.2 add give-form-title, give_title
Expand All @@ -426,7 +427,7 @@ function give_donation_form_validate_fields() {
function give_donation_form_has_serialized_fields(array $post_data): bool
{
foreach ($post_data as $value) {
if (is_serialized(ltrim($value, '\\'))) {
if (is_string($value) && is_serialized(ltrim($value, '\\'))) {
return true;
}

Expand Down Expand Up @@ -1622,6 +1623,7 @@ function give_validate_required_form_fields( $form_id ) {
*
* @param array $post_data List of post data.
*
* @unreleased Check if "give_title" is set to prevent PHP warnings
* @since 3.16.4 Add additional validation for company name field
* @since 3.16.3 Add additional validations for name title prefix field
* @since 2.1
Expand All @@ -1646,7 +1648,7 @@ function give_donation_form_validate_name_fields( $post_data ) {

$is_alpha_first_name = ( ! is_email( $post_data['give_first'] ) && ! preg_match( '~[0-9]~', $post_data['give_first'] ) );
$is_alpha_last_name = ( ! is_email( $post_data['give_last'] ) && ! preg_match( '~[0-9]~', $post_data['give_last'] ) );
$is_alpha_title = ( ! is_email( $post_data['give_title'] ) && ! preg_match( '~[0-9]~', $post_data['give_title'] ) );
$is_alpha_title = ( isset($post_data['give_title']) && ! is_email( $post_data['give_title'] ) && ! preg_match( '~[0-9]~', $post_data['give_title'] ) );

if (!$is_alpha_first_name || ( ! empty( $post_data['give_last'] ) && ! $is_alpha_last_name) || ( ! empty( $post_data['give_title'] ) && ! $is_alpha_title) ) {
give_set_error( 'invalid_name', esc_html__( 'The First Name and Last Name fields cannot contain an email address or numbers.', 'give' ) );
Expand Down

0 comments on commit 9bfae6c

Please sign in to comment.