#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)
#2
@
13 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 What steps did you take to produce the notice, and can you confirm any out of the ordinary circumstances when you published that post?
#3
@
13 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.)
Isn't the real bug that somehow you managed to get a post with an empty
post_status
? According to the phpdoc forget_post_statuses()
, posts have a limited set of valid status values (and empty isn't one of them).