[wp-trac] [WordPress Trac] #51108: PHP 8: Incorrect wp_localize_script() usage in wp-admin/edit-form-blocks.php
WordPress Trac
noreply at wordpress.org
Sat Aug 22 00:02:24 UTC 2020
#51108: PHP 8: Incorrect wp_localize_script() usage in wp-admin/edit-form-
blocks.php
----------------------------+--------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 5.6
Component: Editor | Version:
Severity: normal | Keywords: php8
Focuses: |
----------------------------+--------------------
Background: #25280, #29722, #48528.
The `$l10n` parameter of `wp_localize_script()` is documented as an array,
however, it's also technically possible to pass a string, with the only
difference that it won't run through `html_entity_decode( ..., ENT_QUOTES,
'UTF-8' )`, as previously noted in comment:9:ticket:29722.
One notable instance in core that does this is in `wp-admin/edit-form-
blocks.php`:
{{{
$meta_box_url = add_query_arg(
array(
'post' => $post->ID,
'action' => 'edit',
'meta-box-loader' => true,
'meta-box-loader-nonce' => wp_create_nonce( 'meta-box-
loader' ),
),
$meta_box_url
);
wp_localize_script( 'wp-editor', '_wpMetaBoxUrl', $meta_box_url );
}}}
This is now causing a warning in PHP 8.0 Beta 2:
> `Warning: Only the first byte will be assigned to the string offset in
wp-includes/class.wp-scripts.php on line 492`
`wp_localize_script()` should probably be updated to better handle scalar
values, as per the tickets linked above.
To solve the immediate issue though, `wp-admin/edit-form-blocks.php`
should use `wp_add_inline_script()` instead, as it already does for other
scripts a few lines earlier. That would also be in line with
comment:45:ticket:25280.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51108>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list