Make WordPress Core

Opened 7 weeks ago

Last modified 2 weeks ago

#61144 new defect (bug)

Disabling "Post via email" triggers deprecation notices upon save

Reported by: manbo's profile manbo Owned by:
Milestone: 6.7 Priority: normal
Severity: minor Version: 3.0
Component: Options, Meta APIs Keywords: has-testing-info php81 has-patch needs-testing
Focuses: Cc:

Description

If you disable Post via email on the management screen, an error will occur when you press the save button.

add_filter( 'enable_post_by_email_configuration', '__return_false' );
# PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /wp-includes/formatting.php on line 4958

As a makeshift measure, I suppressed the error using the following method.

add_action( 'update_option', function() {
        if( isset( $_POST['option_page'] ) && $_POST['option_page'] === 'writing' ) {
                if( !isset( $_POST['mailserver_url'] ) ) {
                        $_POST['mailserver_url'] = '';
                }
                if( !isset( $_POST['mailserver_login'] ) ) {
                        $_POST['mailserver_login'] = '';
                }
                if( !isset( $_POST['mailserver_pass'] ) ) {
                        $_POST['mailserver_pass'] = '';
                }
        }
} );

Please improve it so that saving the three items to the database is ignored when email posting is disabled.

Change History (17)

#1 follow-up: @sebastienserre
7 weeks ago

Hello,

Thank you for reporting this issue.
Which PHP verison are you running ? I do not reproduce with PHP8.1.28 and PHP 8.2.18

Last edited 7 weeks ago by sebastienserre (previous) (diff)

#2 @manbo
7 weeks ago

Hello.
Thank you for your reply.

Version
PHP 8.2.18
WordPress 6.5.2

The problem also occurred when I installed WordPress and added the code to functions.php in the standard theme without doing anything.

PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /wp-includes/formatting.php on line 4958
PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /wp-includes/formatting.php on line 4958
PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /wp-includes/formatting.php on line 4958
PHP Deprecated:  explode(): Passing null to parameter #2 ($string) of type string is deprecated in /wp-includes/formatting.php on line 4964
PHP Deprecated:  explode(): Passing null to parameter #2 ($string) of type string is deprecated in /wp-includes/formatting.php on line 4964

#3 in reply to: ↑ 1 @siliconforks
7 weeks ago

Replying to sebastienserre:

Hello,

Thank you for reporting this issue.
Which PHP verison are you running ? I do not reproduce with PHP8.1.28 and PHP 8.2.18

You will probably have to set WP_DEBUG to true in wp-config.php to reproduce this.

#4 @manbo
7 weeks ago

I always enable debug mode to make sure I don't miss any errors.

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', false  );
define( 'WP_DEBUG_LOG', true );

#5 @ironprogrammer
3 weeks ago

  • Component changed from General to Options, Meta APIs
  • Keywords has-testing-info needs-patch added

Reproduction Report

I am able to reproduce this issue with the provided example of disabling enable_post_by_email_configuration.

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 14.5
  • Browser: Safari 17.5
  • Server: nginx/1.27.0
  • PHP: 8.2.19
  • MySQL: 8.0.27
  • WordPress: 6.6-alpha-57778-src
  • Active Plugins:
    • post-via-email (mu plugin with add_filter( 'enable_post_by_email_configuration', '__return_false' );)

Actual Results

  • ✅ With "Post via email" feature disabled on the Writing Settings page (/wp-admin/options-writing.php), clicking Save Changes results in following deprecations in the debug log:
    PHP Deprecated:  strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /Users/brian/Sites/wordpress-develop/src/wp-includes/formatting.php on line 4946
    

#6 @ironprogrammer
3 weeks ago

  • Keywords php81 added
  • Milestone changed from Awaiting Review to 6.7

Welcome back to Trac, and thanks for the report, @manbo!

As the deprecation notice indicates, the issue is nulls passed into `sanitize_option()` here, where mailserver_url, mailserver_login, and mailserver_pass are by default included in the options to update. Even though the fields are suppressed with the hook and aren't present in the $_POST data, options.php sets each included option to `null` and then passes it to update_option().

Perhaps sanitize_option() could be updated to improve processing when these particular [optional] fields are null? Switching to wp_strip_all_tags may be appropriate, since the other options in this case statement shouldn't be negatively affected by the <script> and <style> tag-removing "limitation" of that function.

Tagging with php81, where this deprecation was introduced. I feel we may be too close to 6.6 beta for this to be addressed, but I'm optimistically milestoning for 6.7.

#7 follow-up: @ironprogrammer
3 weeks ago

Another nuance to consider: With the disablement filter in place and changes saved, once the filter is subsequently removed, the mailserver_url, mailserver_login, and mailserver_pass will be empty, as they were unintentionally nulled by update_option() 🙃. Maybe these options should be skipped from processing altogether when the feature is disabled, to preserve the values?

#8 in reply to: ↑ 7 @siliconforks
3 weeks ago

Replying to ironprogrammer:

Maybe these options should be skipped from processing altogether when the feature is disabled, to preserve the values?

I believe the code is attempting to do this already:

https://github.com/WordPress/wordpress-develop/blob/6.5.3/src/wp-admin/options.php#L206-L208

However, there seems to be a bug in the logic, as that code is executed only on multisite (which doesn't really make sense).

This ticket was mentioned in PR #6693 on WordPress/wordpress-develop by @narenin.


3 weeks ago
#9

  • Keywords has-patch added; needs-patch removed

#10 @narenin
3 weeks ago

Hi @manbo

I have created [PR]https://core.trac.wordpress.org/ticket/61144 with patch, can you please check with this.

#11 @ironprogrammer
3 weeks ago

Thanks for the patch, @narenin!

In consideration of avoiding duplicate code, what do you think about moving the filter check outside of the multisite test completely, like where $mail_options is defined? This would mitigate the need for the current else block and show clear intent that updating these fields doesn't depend on single or multisite.

#12 @narenin
3 weeks ago

Thanks @ironprogrammer for the feedback.

The suggestions looks good to me, I have implemented the same.

narendraie commented on PR #6693:


2 weeks ago
#13

Hi @ironprogrammer

Thanks for the feedback, I have implemented the suggestion can you please check.

narendraie commented on PR #6693:


2 weeks ago
#14

Hi @ironprogrammer

Thanks for the feedback, I have implemented the suggestion can you please check.

@narenin commented on PR #6693:


2 weeks ago
#15

Hi @ironprogrammer

Thanks for the feedback, I have implemented the suggestion can you please check.

#16 @ironprogrammer
2 weeks ago

  • Keywords needs-testing added
  • Version changed from 6.5 to 3.0

The patch is looking good! I've added needs-testing to get more eyes/testing on it for eventual 6.7 consideration.

Test Report

Patch tested: https://github.com/WordPress/wordpress-develop/pull/6693

Environment

  • Hardware: MacBook Pro Apple M1 Pro
  • OS: macOS 14.5
  • Browser: Safari 17.5
  • Server: nginx/1.27.0
  • PHP: 8.2.19
  • MySQL: 8.0.27
  • WordPress: 6.6-alpha-57778-src
  • Active Plugins:
    • post-via-email (mu plugin with add_filter( 'enable_post_by_email_configuration', 'return_false' );)

Actual Results

  • ✅ With "Post via email" feature disabled on the Writing Settings page, saving changes no longer triggers the strip_tags() PHP deprecation notice in the debug log.
  • ✅ Values stored for "Post via email" options prior to disabling the feature are retained after the feature has been reenabled, rather than being unintentionally cleared out (see comment:7).

#17 @ironprogrammer
2 weeks ago

  • Summary changed from Disable Post via email to Disabling "Post via email" triggers deprecation notices upon save
Note: See TracTickets for help on using tickets.