WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 21 months ago

#20793 closed defect (bug) (fixed)

Illegal string offset 'public' in wpmu_create_blog()

Reported by: duck_ Owned by: SergeyBiryukov
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.0
Component: Multisite Keywords: has-patch
Focuses: Cc:

Description

If $meta is not passed and left as default empty string then:

update_option( 'blog_public', (int)$meta['public'] );

will throw a notice.

Attachments (5)

20793.diff (1.1 KB) - added by duck_ 3 years ago.
20793.2.diff (1.2 KB) - added by jeremyfelt 21 months ago.
20793.3.diff (1.6 KB) - added by SergeyBiryukov 21 months ago.
20793.4.diff (1.6 KB) - added by SergeyBiryukov 21 months ago.
20793.5.diff (1.6 KB) - added by SergeyBiryukov 21 months ago.

Download all attachments as: .zip

Change History (11)

@duck_3 years ago

@jeremyfelt21 months ago

comment:1 @jeremyfelt21 months ago

  • Component changed from Warnings/Notices to Multisite
  • Milestone changed from Future Release to 3.7

Just ran into this. wpmu_create_blog() implies that the meta parameter is optional, both in the @param documentation and by setting the default of an empty string. If the array key for public is not set, a notice is thrown.

20793.2.diff is a refresh of @duck_'s patch, which accounts for a missing public key and addresses some code formatting.

@SergeyBiryukov21 months ago

comment:2 @SergeyBiryukov21 months ago

20793.3.diff is a slightly different take:

  • Does not modify $meta.
  • Replaces multiple comparisons with a single in_array() check. The comparisons are probably a tiny bit faster, but I don't think they're for performance reasons here. Introduced in mu:1364.

comment:3 follow-up: @jeremyfelt21 months ago

I like the in_array() check. Does it matter that $meta will be passed unmodified to an action further down?

@SergeyBiryukov21 months ago

comment:4 in reply to: ↑ 3 @SergeyBiryukov21 months ago

Replying to jeremyfelt:

Does it matter that $meta will be passed unmodified to an action further down?

For some reason it seemed better to me at the moment. On second thought, I agree with changing $meta, would just like it to be explicitly declared as an array: 20793.4.diff. I think it may throw a notice otherwise, however a quick test showed that it's not the case, so I may be wrong.

@SergeyBiryukov21 months ago

comment:5 @SergeyBiryukov21 months ago

20793.5.diff uses wp_parse_args() to make sure $meta is always an array, and $meta['public'] is always set.

In IRC discussion, nacin suggested that the default value for $meta should also be an array. Created #25149 for that.

Last edited 21 months ago by SergeyBiryukov (previous) (diff)

comment:6 @SergeyBiryukov21 months ago

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

In 25127:

Avoid a PHP notice in wpmu_create_blog() if $meta is not passed. props duck_, jeremyfelt, SergeyBiryukov. fixes #20793.

Note: See TracTickets for help on using tickets.