WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 9 months ago

Last modified 8 months ago

#46670 closed defect (bug) (fixed)

Compact throws notice on PHP7.3 at ajax-actions.php

Reported by: pilou69 Owned by: SergeyBiryukov
Milestone: 5.2 Priority: normal
Severity: normal Version: 5.1
Component: Taxonomy Keywords:
Focuses: administration Cc:
PR Number:

Description

There is no $noparents variable if the taxonomy is not hierarchical, so the compact used for the taxonomy supplemental throws a notice.

function wp_ajax_add_tag
line 1039

Before:

<?php
        $level = 0;
        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
                $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
                ob_start();
                $wp_list_table->single_row( $tag, $level );
                $noparents = ob_get_clean();
        }

        ob_start();
        $wp_list_table->single_row( $tag );
        $parents = ob_get_clean();

        $x->add(
                array(
                        'what'         => 'taxonomy',
                        'supplemental' => compact( 'parents', 'noparents' ),
                )
        );

Proposed fix:

<?php
        $level = 0;
        $taxonomy_supplemental = [];
        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
                $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
                ob_start();
                $wp_list_table->single_row( $tag, $level );
                $taxonomy_supplemental['noparents'] = ob_get_clean();
        }

        ob_start();
        $wp_list_table->single_row( $tag );
        $taxonomy_supplemental['parents'] = ob_get_clean();

        $x->add(
                array(
                        'what'         => 'taxonomy',
                        'supplemental' => $taxonomy_supplemental,
                )
        );

Change History (4)

#1 @SergeyBiryukov
9 months ago

  • Component changed from General to Taxonomy
  • Focuses administration added
  • Milestone changed from Awaiting Review to 5.2

#2 @SergeyBiryukov
9 months ago

Appears to be missed in #44416.

#3 @SergeyBiryukov
9 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 45034:

Taxonomy: Initialize $noparents variable in wp_ajax_add_tag() to avoid a notice with compact() in PHP 7.3.

Props pilou69.
Fixes #46670.

#4 @pilou69
8 months ago

I should mention that the result of your fix https://core.trac.wordpress.org/changeset/45034 is not exactly what PHP7.2 did.

You see, in PHP7.2 if the variable for compact didn't exists the resulting array won't have the key with the variable name.

With Your change the 'noparents' key will be always there. I don't know if it's a mistake or You were intended to do that.

Note: See TracTickets for help on using tickets.