WP_Customize_Manager::get_previewable_devices PHP Method

get_previewable_devices() public method

Returns a list of devices to allow previewing.
Since: 4.5.0
public get_previewable_devices ( ) : array
return array List of devices with labels and default setting.
    public function get_previewable_devices()
    {
        $devices = array('desktop' => array('label' => __('Enter desktop preview mode'), 'default' => true), 'tablet' => array('label' => __('Enter tablet preview mode')), 'mobile' => array('label' => __('Enter mobile preview mode')));
        /**
         * Filters the available devices to allow previewing in the Customizer.
         *
         * @since 4.5.0
         *
         * @see WP_Customize_Manager::get_previewable_devices()
         *
         * @param array $devices List of devices with labels and default setting.
         */
        $devices = apply_filters('customize_previewable_devices', $devices);
        return $devices;
    }

Usage Example

Exemplo n.º 1
0
	/**
	 * Testing the return values both with and without filter.
	 *
	 * @ticket 31195
	 */
	function test_get_previewable_devices() {

		// Setup the instance.
		$manager = new WP_Customize_Manager();

		// The default devices list.
		$default_devices = array(
			'desktop' => array(
				'label'   => __( 'Enter desktop preview mode' ),
				'default' => true,
			),
			'tablet'  => array(
				'label' => __( 'Enter tablet preview mode' ),
			),
			'mobile'  => array(
				'label' => __( 'Enter mobile preview mode' ),
			),
		);

		// Control test.
		$devices = $manager->get_previewable_devices();
		$this->assertSame( $default_devices, $devices );

		// Adding the filter.
		add_filter( 'customize_previewable_devices', array( $this, 'filter_customize_previewable_devices' ) );
		$devices = $manager->get_previewable_devices();
		$this->assertSame( $this->filtered_device_list(), $devices );

		// Clean up.
		remove_filter( 'customize_previewable_devices', array( $this, 'filter_customize_previewable_devices' ) );
	}
WP_Customize_Manager