GC_Customize_Manager::add_control()

最后更新于:2021-11-27 00:38:05

GC_Customize_Manager::add_control( GC_Customize_Control|string$id, array$args=array())

Add a customize control.

参数

$id

(GC_Customize_Control|string) (Required) Customize Control object, or ID.

$args

(array) (Optional) Array of properties for the new Control object. See GC_Customize_Control::__construct() for information on accepted arguments.

Default value: array()

响应

(GC_Customize_Control) The instance of the control that was added.

源文件

文件: gc-includes/class-gc-customize-manager.php

	public function add_control( $id, $args = array() ) {
		if ( $id instanceof GC_Customize_Control ) {
			$control = $id;
		} else {
			$control = new GC_Customize_Control( $this, $id, $args );
		}

		$this->controls[ $control->id ] = $control;
		return $control;
	}
function register_customize_sections( $gc_customize ) {

    $gc_customize->add_section( 'example', array(

       'title'=> __( 'Add Your Name', 'TextDomain' ),
       'priority' => 201
    ) );

    $gc_customize->add_setting( 'setting' );
    $gc_customize->add_control( 'setting', array(
        'id'=> 'id',
        'label' => __( 'First Name:', 'TextDomain' ),
        'section' => 'example'
    ) );
}