#61144 closed defect (bug) (fixed)
Disabling "Post via email" triggers deprecation notices upon save
Reported by: | manbo | Owned by: | peterwilsoncc |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | minor | Version: | 3.0 |
Component: | Options, Meta APIs | Keywords: | has-testing-info php81 has-patch commit |
Focuses: | php-compatibility | 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 (20)
#2
@
5 months 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
@
5 months 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
@
5 months 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
@
4 months 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' );
)
- post-via-email (mu plugin with
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
@
4 months 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:
↓ 8
@
4 months 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
@
4 months 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.
4 months ago
#9
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/61144
#10
@
4 months ago
Hi @manbo
I have created [PR]https://core.trac.wordpress.org/ticket/61144 with patch, can you please check with this.
#11
@
4 months 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
@
4 months ago
Thanks @ironprogrammer for the feedback.
The suggestions looks good to me, I have implemented the same.
narendraie commented on PR #6693:
4 months ago
#13
Hi @ironprogrammer
Thanks for the feedback, I have implemented the suggestion can you please check.
narendraie commented on PR #6693:
4 months ago
#14
Hi @ironprogrammer
Thanks for the feedback, I have implemented the suggestion can you please check.
4 months ago
#15
Hi @ironprogrammer
Thanks for the feedback, I have implemented the suggestion can you please check.
#16
@
4 months 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
@
4 months ago
- Summary changed from Disable Post via email to Disabling "Post via email" triggers deprecation notices upon save
#18
@
5 weeks ago
- Focuses php-compatibility added
- Keywords commit added; needs-testing removed
I'm able to reproduce the successful test results above.
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/6693
Environment
- Hardware: MacBook Pro Apple M3 Pro
- OS: macOS 14.6
- Browser: Firefox 129
- Server: nginx/1.18.0
- PHP: 8.1.29
- MySQL: 8.0.36
- WordPress: 6.7-alpha-58576-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).
#19
@
5 weeks ago
- Owner set to peterwilsoncc
- Resolution set to fixed
- Status changed from new to closed
In 58963:
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