Headers already sent warning in Admin source is media.php 3140

After years of running fine, I am suddenly getting this dreaded message after updating to 5.42. However it only happens in the Admin:

Warning: strpos() expects parameter 1 to be string, array given in Warning/home/content/55/html/example/wp-includes/media.php on line 3141

Warning: Cannot modify header information - headers already sent by (output started at /home/content/55/8933555/html/example/wp-includes/media.php:3141) in /home/content/55/8933555/html/example/wp-includes/functions.php on line 6221

Warning: Cannot modify header information - headers already sent by (output started at /home/content/55/8933555/html/example/wp-includes/media.php:3141) in /home/content/55/8933555/html/example/wp-admin/includes/misc.php on line 1282

Warning: Cannot modify header information - headers already sent by (output started at /home/content/55/8933555/html/example/wp-includes/media.php:3141) in /home/content/55/8933555/html/example/wp-admin/admin-header.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /home/content/55/8933555/html/example/wp-includes/media.php:3141) in /home/content/55/8933555/html/example/wp-includes/option.php on line 961

 Warning: Cannot modify header information - headers already sent by (output started at /home/content/55/8933555/html/example/wp-includes/media.php:3141) in /home/content/55/8933555/html/example/wp-includes/option.php on line 962

The code at line 3140 of media.php is

if (‘attachment’ === $object_type || 0 === strpos( $object_type, ‘attachment:’ ) ) {

It appears that the problem is a custom taxonomy I have. Which is created here in functions().php

function songs_init() {
    // create a new taxonomy
register_taxonomy(
        'songs',
        array(
            'label' => __( 'Songs_Tax' ),
            'sort' => true,
            'args' => array( 'orderby' => 'term_order' ),
)
);
}
add_action( 'init', 'songs_init' );

When I test for the offending $object_type in media.pho and get a var_dump(), it comes back that $object_type is an array:

'orderby' => 'term_order'

I’ve tried looking for white space and stray characters in functions.php but I don’t see anything.

Any ideas on what next to try? Again, this worked fine for almost a decade until 5.42

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Looking at the docs for register_taxonomy, it takes 3 parameters, the 3rd of which is the arguments, and it looks like in your code you have the arguments in the second parameter. Perhaps this is one of those tricky bugs where this was somehow working in previous versions and it officially shouldn’t have been.

If songs is the object, you need to add another parameter for the taxonomy key, e.g.:

    register_taxonomy(
        'songs_tax',
        'songs',
        array(
            'label' => __( 'Songs_Tax' ),
            'sort' => true,
            'args' => array( 'orderby' => 'term_order' ),
        )
    );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x