Skip to content

Commit

Permalink
Forms: Fix warning when post author data returns false. (#42115)
Browse files Browse the repository at this point in the history
* Fix 'Attempt to read property on bool' warning.

* Changelog.

* Added a test to cover the failure.

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13633058435

Upstream-Ref: Automattic/jetpack@5964561
  • Loading branch information
zinigor authored and matticbot committed Mar 3, 2025
1 parent 94c759b commit 712fa14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This is an alpha version! The changes listed here are not final.
- Forms: use placeholder attribute in editor instead of value

### Fixed
- Fix warnings when post author is not available.
- Forms: Ensure fields that skip rendering (like empty options fields) do not trigger validation or show value in form submission response.
- Forms: Fix 404 error when a user submits an invalid form with JavaScript disabled.
- Forms: fix field name set as label when trying to empty label
Expand Down
12 changes: 9 additions & 3 deletions src/contact-form/class-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public function __construct( $attributes, $content = null ) {
} elseif ( $post ) {
$attributes['id'] = $post->ID;
$post_author = get_userdata( $post->post_author );
$default_to .= $post_author->user_email;
if ( is_a( $post_author, '\WP_User' ) ) {
$default_to .= $post_author->user_email;
} else {
$default_to .= get_option( 'admin_email' );
}
}

if ( ! empty( self::$forms ) ) {
Expand Down Expand Up @@ -534,7 +538,8 @@ public static function get_compiled_form( $feedback_id, $form ) {
}
} else {
// The feedback content is stored as the first "half" of post_content
$value = is_a( $feedback, '\WP_Post' ) ? $feedback->post_content : '';
$value = ( is_object( $feedback ) && is_a( $feedback, '\WP_Post' ) ) ?
$feedback->post_content : '';
list( $value ) = explode( '<!--more-->', $value );
$value = trim( $value );
}
Expand Down Expand Up @@ -627,7 +632,8 @@ public static function get_compiled_form_for_email( $feedback_id, $form ) {
}
} else {
// The feedback content is stored as the first "half" of post_content
$value = is_a( $feedback, '\WP_Post' ) ? $feedback->post_content : '';
$value = ( is_object( $feedback ) && is_a( $feedback, '\WP_Post' ) ) ?
$feedback->post_content : '';
list( $value ) = explode( '<!--more-->', $value );
$value = trim( $value );
}
Expand Down

0 comments on commit 712fa14

Please sign in to comment.