Make WordPress Core

Opened 11 years ago

Closed 10 years ago

#27315 closed enhancement (fixed)

Easier adding of custom class variables when extending WP_Customize_Section

Reported by: rhurling's profile rhurling Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.4
Component: Customize Keywords: has-patch commit
Focuses: administration Cc:

Description (last modified by westonruter)

WP_Customize_Section uses $keys = array_keys( get_class_vars( __CLASS__ ) ); to set class variables, but WP_Customize_Control uses $keys = array_keys( get_object_vars( $this ) ); to set class variables.

The difference is that if you extend WP_Customize_Control you can add new class variables by setting them in the extended class and passing them to the args array in the constructor.
In WP_Customize_Section one has to override the constructor to do the same.

changing

$keys = array_keys( get_class_vars( __CLASS__ ) );

to

$keys = array_keys( get_object_vars( $this ) );

in WP_Customize_Section would solve the problem (or use the static keyword which would raise the requirements to PHP 5.3)

Attachments (1)

27315.diff (1.2 KB) - added by rhurling 10 years ago.
replace get_class_vars with get_object_vars

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
11 years ago

  • Component changed from Administration to Appearance
  • Focuses ui removed

#2 @westonruter
10 years ago

  • Description modified (diff)
  • Keywords good-first-bug needs-patch added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 3.8.1 to 3.4

Agreed. get_class_vars( __CLASS__ ) should be replaced with get_object_vars( $this ). This would actually bring WP_Customize_Section in line WP_Customize_Control which initially did use get_class_vars() but in [20319] was changed to use get_object_vars().

#3 @westonruter
10 years ago

Also, WP_Customize_Setting currently uses get_class_vars( __CLASS__ ) like WP_Customize_Section. It should be updated to use get_object_vars( $this ) as well.

#4 @rhurling
10 years ago

okay, i'll try to make a patch today

@rhurling
10 years ago

replace get_class_vars with get_object_vars

#5 @rhurling
10 years ago

  • Keywords has-patch added; needs-patch removed

#6 @westonruter
10 years ago

  • Keywords commit added; good-first-bug removed
  • Milestone changed from Future Release to 4.0

#7 @SergeyBiryukov
10 years ago

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

In 28827:

Allow for easier adding of custom class variables when extending WP_Customize_Section or WP_Customize_Setting.

props rhurling.
fixes #27315.

Note: See TracTickets for help on using tickets.