WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 8 months ago

Last modified 8 months ago

#19706 closed defect (bug) (invalid)

NOTICE: wp-admin/includes/post.php:834 - Illegal member variable name

Reported by: markjaquith Owned by:
Milestone: Priority: low
Severity: normal Version: 3.3
Component: Warnings/Notices Keywords:
Focuses: Cc:

Description

Received this notice:

NOTICE: wp-admin/includes/post.php:834 - Illegal member variable name

Traced it to this in wp_count_posts():

	$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );

	$stats = array();
	foreach ( get_post_stati() as $state )
		$stats[$state] = 0;

	foreach ( (array) $count as $row )
		$stats[$row['post_status']] = $row['num_posts'];

	$stats = (object) $stats;

Apparently I have a post with a post status of a blank string. So that gets set to an array key, and then is cast to an object. WP doesn't like that.

Proposed:

	foreach ( (array) $count as $row ) {
		if ( !empty( $row['post_status'] ) )
			$stats[$row['post_status']] = $row['num_posts'];
	}

Just discard empty post_status rows.

Change History (5)

comment:1 solarissmoke2 years ago

Isn't the real bug that somehow you managed to get a post with an empty post_status? According to the phpdoc for get_post_statuses(), posts have a limited set of valid status values (and empty isn't one of them).

comment:2 mp3j3rk2 years ago

  • Cc mp3j3rk added

This should be aimed at the code that saves a post to the DB then, and why it would have placed an empty value in wp_posts.post_status without having thrown an error.

I need a pet project, I think I'll give this one a look-see.

@markjaquith can you confirm any out of the ordinary circumstances when you published that post?

Version 0, edited 2 years ago by mp3j3rk (next)

comment:3 nacin2 years ago

  • Keywords close added
  • Milestone changed from 3.4 to Awaiting Review

wp_insert_post() sets the post_status to 'draft' if it is empty. I don't think this was caused by core and is probably not something we should "fix" as it points to a developer issue. (Additionally, I doubt this is the only area in core that breaks due to this, whether or not it throws a notice.)

comment:4 c3mdigital8 months ago

  • Resolution set to invalid
  • Status changed from new to closed

No discussion in 16 months. Closing based on comments above.

comment:5 SergeyBiryukov8 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.