WP_Customize_Manager::get_nonces PHP Method

get_nonces() public method

Get nonces for the Customizer.
Since: 4.5.0
public get_nonces ( ) : array
return array Nonces.
    public function get_nonces()
    {
        $nonces = array('save' => wp_create_nonce('save-customize_' . $this->get_stylesheet()), 'preview' => wp_create_nonce('preview-customize_' . $this->get_stylesheet()));
        /**
         * Filters nonces for Customizer.
         *
         * @since 4.2.0
         *
         * @param array                $nonces Array of refreshed nonces for save and
         *                                     preview actions.
         * @param WP_Customize_Manager $this   WP_Customize_Manager instance.
         */
        $nonces = apply_filters('customize_refresh_nonces', $nonces, $this);
        return $nonces;
    }

Usage Example

Exemplo n.º 1
0
	/**
	 * Test get_nonces() method.
	 *
	 * @see WP_Customize_Manager::get_nonces()
	 */
	function test_nonces() {
		$nonces = $this->manager->get_nonces();
		$this->assertInternalType( 'array', $nonces );
		$this->assertArrayHasKey( 'save', $nonces );
		$this->assertArrayHasKey( 'preview', $nonces );

		add_filter( 'customize_refresh_nonces', array( $this, 'filter_customize_refresh_nonces' ), 10, 2 );
		$nonces = $this->manager->get_nonces();
		$this->assertArrayHasKey( 'foo', $nonces );
		$this->assertEquals( wp_create_nonce( 'foo' ), $nonces['foo'] );
	}
WP_Customize_Manager