Title: WP_Customize_Manager::prepare_controls
Published: April 25, 2014
Last modified: May 20, 2026

---

# WP_Customize_Manager::prepare_controls()

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#wp--skip-link--target)

Prepares panels, sections, and controls.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#description)󠁿

For each, check if required related components exist, whether the user has the necessary
capabilities, and sort by priority.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#source)󠁿

    ```php
    public function prepare_controls() {

    	$controls       = array();
    	$this->controls = wp_list_sort(
    		$this->controls,
    		array(
    			'priority'        => 'ASC',
    			'instance_number' => 'ASC',
    		),
    		'ASC',
    		true
    	);

    	foreach ( $this->controls as $id => $control ) {
    		if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) {
    			continue;
    		}

    		$this->sections[ $control->section ]->controls[] = $control;
    		$controls[ $id ]                                 = $control;
    	}
    	$this->controls = $controls;

    	// Prepare sections.
    	$this->sections = wp_list_sort(
    		$this->sections,
    		array(
    			'priority'        => 'ASC',
    			'instance_number' => 'ASC',
    		),
    		'ASC',
    		true
    	);
    	$sections       = array();

    	foreach ( $this->sections as $section ) {
    		if ( ! $section->check_capabilities() ) {
    			continue;
    		}

    		$section->controls = wp_list_sort(
    			$section->controls,
    			array(
    				'priority'        => 'ASC',
    				'instance_number' => 'ASC',
    			)
    		);

    		if ( ! $section->panel ) {
    			// Top-level section.
    			$sections[ $section->id ] = $section;
    		} else {
    			// This section belongs to a panel.
    			if ( isset( $this->panels [ $section->panel ] ) ) {
    				$this->panels[ $section->panel ]->sections[ $section->id ] = $section;
    			}
    		}
    	}
    	$this->sections = $sections;

    	// Prepare panels.
    	$this->panels = wp_list_sort(
    		$this->panels,
    		array(
    			'priority'        => 'ASC',
    			'instance_number' => 'ASC',
    		),
    		'ASC',
    		true
    	);
    	$panels       = array();

    	foreach ( $this->panels as $panel ) {
    		if ( ! $panel->check_capabilities() ) {
    			continue;
    		}

    		$panel->sections      = wp_list_sort(
    			$panel->sections,
    			array(
    				'priority'        => 'ASC',
    				'instance_number' => 'ASC',
    			),
    			'ASC',
    			true
    		);
    		$panels[ $panel->id ] = $panel;
    	}
    	$this->panels = $panels;

    	// Sort panels and top-level sections together.
    	$this->containers = array_merge( $this->panels, $this->sections );
    	$this->containers = wp_list_sort(
    		$this->containers,
    		array(
    			'priority'        => 'ASC',
    			'instance_number' => 'ASC',
    		),
    		'ASC',
    		true
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-customize-manager.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-customize-manager.php#L4444)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-customize-manager.php#L4444-L4545)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_list_sort()](https://developer.wordpress.org/reference/functions/wp_list_sort/)`wp-includes/functions.php` |

Sorts an array of objects or arrays based on one or more orderby arguments.

  |

| Used by | Description | 
| [WP_Customize_Manager::customize_preview_init()](https://developer.wordpress.org/reference/classes/wp_customize_manager/customize_preview_init/)`wp-includes/class-wp-customize-manager.php` |

Prints JavaScript settings.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_customize_manager/prepare_controls/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.4.0](https://developer.wordpress.org/reference/since/3.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_customize_manager%2Fprepare_controls%2F)
before being able to contribute a note or feedback.