WordPress.org

Make WordPress Core

Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#44727 closed defect (bug) (invalid)

WP 4.9.8 creates fatal on filter list_pages

Reported by: BackuPs Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9.8
Component: Menus Keywords:
Focuses: Cc:
PR Number:

Description

Hi

I have this function

	function start_el(&$output, $page, $depth = 0, $args = array(), $current_object_id = 0) {
		$pad = str_repeat(' ', $depth * 3);
		
		$output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
		if(is_array($args['selected'])){
			if ( in_array($page->ID, $args['selected']) ){
				$output .= ' selected="selected"';
			}
		}else{
			if ( $page->ID == $args['selected'] ){
				$output .= ' selected="selected"';
			}
		}
		$output .= '>';
		$title = apply_filters( 'list_pages', $page->post_title );
		$output .= $pad . esc_html( $title );
		$output .= "</option>\n";
	}

The line

$title = apply_filters( 'list_pages', $page->post_title );

Creates a error in wp 4.9.8

<b>Fatal error</b>:  Uncaught ArgumentCountError: Too few arguments to function _wp_privacy_settings_filter_draft_page_titles(), 1 passed in /home/mydomain/public_html/wp-includes/class-wp-hook.php on line 286 and exactly 2 expected in /home/mydomain/public_html/wp-admin/includes/misc.php:1239
Stack trace:
#0 /home/mydomain/public_html/wp-includes/class-wp-hook.php(286): _wp_privacy_settings_filter_draft_page_titles('About')
#1 /home/mydomain/public_html/wp-includes/plugin.php(203): WP_Hook-&gt;apply_filters('About', Array)
#2 /home/mydomain/public_html/wp-content/themes/champion/framework/helpers/baseOptionsGenerator.php(1209): apply_filters('list_pages', 'About')
#3 /home/mydomain/public_html/wp-includes/class-wp-walker.php(145): Walker_PageMultiSelect-&gt;start_el('\t&lt;option class=...', Object(WP_Post), 0, Array)
#4 /home/mydomain/public_html/wp-includes/class-wp-walker.php(243): Walker-&gt;display_element(Object(WP_Post), Array, '0', 0, Array, '\t&lt;option class=...')
#5 /home/mydomain/public_html/wp-content/themes/champion/framework/he in <b>/home/mydomain/public_html/wp-admin/includes/misc.php</b> on line <b>1239</b><br />

How to fix this?

}}}

Change History (3)

#1 @swissspidy
16 months ago

  • Component changed from General to Menus
  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

In \Walker_PageDropdown::start_el(), WordPress uses the list_pages filter as follows:

/**
 * Filters the page title when creating an HTML drop-down list of pages.
 *
 * @since 3.1.0
 *
 * @param string $title Page title.
 * @param object $page  Page data object.
 */
$title = apply_filters( 'list_pages', $title, $page );

In your code you are only passing the post title, but not the post object. That's why there's a fatal error:

Any function hooked to the list_pages filter (in this case _wp_privacy_settings_filter_draft_page_titles) expects two variables, but you're only passing one.

You should use apply_filters( 'list_pages', $page->post_title, $page ); instead.

Since this is not a bug in core but really a support question, I kindly refer you to open a thread on https://wordpress.org/support for future questions in that regard.

#2 @BackuPs
16 months ago

Hi

Thank you that fixed it.

#3 @SergeyBiryukov
16 months ago

  • Summary changed from WP 4.98 creates fatal on filet list_pages to WP 4.9.8 creates fatal on filter list_pages
Note: See TracTickets for help on using tickets.