GC_Customize_Manager::add_dynamic_settings()
最后更新于:2021-11-27 00:42:53
GC_Customize_Manager::add_dynamic_settings( array$setting_ids)Register any dynamically-created settings, such as those from $_POST[‘customized’] that have no corresponding setting created.
参数
- $setting_ids
-
(array) (Required) The setting IDs to add.
响应
(array) The GC_Customize_Setting objects added.
源文件
文件: gc-includes/class-gc-customize-manager.php
public function add_dynamic_settings( $setting_ids ) {
$new_settings = array();
foreach ( $setting_ids as $setting_id ) {
// Skip settings already created.
if ( $this->get_setting( $setting_id ) ) {
continue;
}
$setting_args = false;
$setting_class = 'GC_Customize_Setting';
/**
* Filters a dynamic setting's constructor args.
*
* For a dynamic setting to be registered, this filter must be employed
* to override the default false value with an array of args to pass to
* the GC_Customize_Setting constructor.
*
* @since 4.2.0
*
* @param false|array $setting_args The arguments to the GC_Customize_Setting constructor.
* @param string $setting_id ID for dynamic setting, usually coming from `$_POST['customized']`.
*/
$setting_args = apply_filters( 'customize_dynamic_setting_args', $setting_args, $setting_id );
if ( false === $setting_args ) {
continue;
}
/**
* Allow non-statically created settings to be constructed with custom GC_Customize_Setting subclass.
*
* @since 4.2.0
*
* @param string $setting_class GC_Customize_Setting or a subclass.
* @param string $setting_id ID for dynamic setting, usually coming from `$_POST['customized']`.
* @param array $setting_args GC_Customize_Setting or a subclass.
*/
$setting_class = apply_filters( 'customize_dynamic_setting_class', $setting_class, $setting_id, $setting_args );
$setting = new $setting_class( $this, $setting_id, $setting_args );
$this->add_setting( $setting );
$new_settings[] = $setting;
}
return $new_settings;
}