[wp-trac] [WordPress Trac] #34596: WP_Customize_Manager::add_*() methods should return the added instance
WordPress Trac
noreply at wordpress.org
Thu Nov 5 23:53:35 UTC 2015
#34596: WP_Customize_Manager::add_*() methods should return the added instance
-------------------------+-------------------------------------------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Customize | Version: 3.4
Severity: normal | Keywords: good-first-bug needs-patch needs-
Focuses: | unit-tests
-------------------------+-------------------------------------------------
A common pattern for adding a panel/section/control/setting to the
Customizer and then to access the instance of the thing that was added is:
{{{#!php
<?php
$wp_customize->add_control( 'foo', array( /* ... */ ) );
$control = $wp_customize->get_control( 'foo' );
/* Now do what is needed with $control... */
}}}
Or sometimes
{{{#!php
<?php
$control = new WP_Customize_Control( $wp_customize, 'foo', array( /* ...
*/ ) );
$control = $wp_customize->add_control( $control );
/* Now do what is needed with $control... */
}}}
But it would be ideal if this could be condensed down to:
{{{#!php
<?php
$control = $wp_customize->add_control( 'foo', array( /* ... */ ) );
/* Now do what is needed with $control... */
}}}
So `WP_Customize_Manager::add_control()` should return the
`WP_Customize_Control` instead of `void`.
This same pattern should be done for:
* `WP_Customize_Manager::add_section()`
* `WP_Customize_Manager::add_control()`
* `WP_Customize_Manager::add_setting()`
* `WP_Customize_Manager::add_panel()`
Unit tests should be added for each of these methods to ensure that the
expected instance is returned in the two patterns of calling the methods,
e.g.:
* `WP_Customize_Manager::add_control( $control_id, $args )`
* `WP_Customize_Manager::add_control( $control_instance )`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34596>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list