Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#20793 closed defect (bug) (fixed)

Illegal string offset 'public' in wpmu_create_blog()

Reported by: duck_'s profile duck_ Owned by: sergeybiryukov's profile 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_ 12 years ago.
20793.2.diff (1.2 KB) - added by jeremyfelt 11 years ago.
20793.3.diff (1.6 KB) - added by SergeyBiryukov 11 years ago.
20793.4.diff (1.6 KB) - added by SergeyBiryukov 11 years ago.
20793.5.diff (1.6 KB) - added by SergeyBiryukov 11 years ago.

Download all attachments as: .zip

Change History (11)

@duck_
12 years ago

@jeremyfelt
11 years ago

#1 @jeremyfelt
11 years 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.

#2 @SergeyBiryukov
11 years 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.

#3 follow-up: @jeremyfelt
11 years ago

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

#4 in reply to: ↑ 3 @SergeyBiryukov
11 years 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.

#5 @SergeyBiryukov
11 years 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 11 years ago by SergeyBiryukov (previous) (diff)

#6 @SergeyBiryukov
11 years 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.