admin管理员组

文章数量:1323225

When I am trying to edit or add a post/page using block editor, it shows me some weird warnings then they act like they disappear, but when I inspect the page, I see that they are still there. The warnings appear just when I am using my theme.

Note 1: Most of the warnings are eather in the wp-admin or wp-includes folder, which I haven't touched at all.

Note 2: I've installed classic editor and it works just fine.

Warnings:

1- Warning: array_values() expects parameter 1 to be array, null given in E:\Coding\WordPress\blog\app\public\wp-includes\theme.php on line 3995

2- Warning: array_merge(): Expected parameter 2 to be an array, null given in E:\Coding\WordPress\blog\app\public\wp-includes\theme.php on line 3996

3- Warning: Cannot modify header information - headers already sent by (output started at E:\Coding\WordPress\blog\app\public\wp-includes\theme.php:3995) in E:\Coding\WordPress\blog\app\public\wp-admin\admin-header.php on line 9

4- Warning: Cannot modify header information - headers already sent by (output started at E:\Coding\WordPress\blog\app\public\wp-includes\theme.php:3995) in E:\Coding\WordPress\blog\app\public\wp-includes\option.php on line 1050

5- Warning: Cannot modify header information - headers already sent by (output started at E:\Coding\WordPress\blog\app\public\wp-includes\theme.php:3995) in E:\Coding\WordPress\blog\app\public\wp-includes\option.php on line 1051

When I am trying to edit or add a post/page using block editor, it shows me some weird warnings then they act like they disappear, but when I inspect the page, I see that they are still there. The warnings appear just when I am using my theme.

Note 1: Most of the warnings are eather in the wp-admin or wp-includes folder, which I haven't touched at all.

Note 2: I've installed classic editor and it works just fine.

Warnings:

1- Warning: array_values() expects parameter 1 to be array, null given in E:\Coding\WordPress\blog\app\public\wp-includes\theme.php on line 3995

2- Warning: array_merge(): Expected parameter 2 to be an array, null given in E:\Coding\WordPress\blog\app\public\wp-includes\theme.php on line 3996

3- Warning: Cannot modify header information - headers already sent by (output started at E:\Coding\WordPress\blog\app\public\wp-includes\theme.php:3995) in E:\Coding\WordPress\blog\app\public\wp-admin\admin-header.php on line 9

4- Warning: Cannot modify header information - headers already sent by (output started at E:\Coding\WordPress\blog\app\public\wp-includes\theme.php:3995) in E:\Coding\WordPress\blog\app\public\wp-includes\option.php on line 1050

5- Warning: Cannot modify header information - headers already sent by (output started at E:\Coding\WordPress\blog\app\public\wp-includes\theme.php:3995) in E:\Coding\WordPress\blog\app\public\wp-includes\option.php on line 1051

Share Improve this question asked Oct 8, 2020 at 12:41 kuroyzakuroyza 12310 bronze badges 5
  • Most of those warnings are caused by the 1st warning being printed, this will be because of an issue in the theme. I'm assuming you haven't modified WP core files in any way? If so, that line looks like it's related to post format registration and callbacks, specifically the code that makes sure the standard post format is always shown in the REST API. Does your theme do anything related to post formats? Are you modifying the REST API responses? – Tom J Nowell Commented Oct 8, 2020 at 13:07
  • Yeah these errors are more than likely related to theme or plugin causing core to throw those warnings. What version of WordPress are you using, and one thing you can try is to switch to default theme, and disable plugins one by one until the error goes away – sMyles Commented Oct 8, 2020 at 16:12
  • I have solved the problem as you said @TomJNowell the problem was related to post format registration, Thank you so much! – kuroyza Commented Oct 8, 2020 at 16:16
  • @kuroyza can you post the solution as an answer below for anybody else who has this problem? – Tom J Nowell Commented Oct 8, 2020 at 16:59
  • @TomJNowell Yes of course! – kuroyza Commented Oct 8, 2020 at 18:22
Add a comment  | 

1 Answer 1

Reset to default 2

I've made a page where the user can check the supported post formats, and the problem was that in case the user haven't checked any post format it returns false, and instead of returning an array that contains 'standard' like the following return ['standard'], I used only the keyword return to stop the function from running.

Here is what I am talking about:

function get_supported_post_formats(){
    $options = get_option('post-supports-handler');

    if (empty($options)) {
        return ['standard'];
    }

    $formats = [
        'standard',
        'aside',
        'gallery',
        'link',
        'image',
        'quote',
        'video',
        'status',
        'audio',
        'chat',
    ];

    $output = [];

    foreach ($formats as $format) {
        $output[] = (@$options[$format] == '1' ? $format : '');
    }

    return $output;
}


$output = get_supported_post_formats();


add_theme_support('post-formats', $output);

本文标签: postsBlock editors annoying warnings