WP_Customize_Setting::json PHP Method

json() public method

Retrieves the data to export to the client via JSON.
Since: 4.6.0
public json ( ) : array
return array Array of parameters passed to JavaScript.
    public function json()
    {
        return array('value' => $this->js_value(), 'transport' => $this->transport, 'dirty' => $this->dirty, 'type' => $this->type);
    }

Usage Example

 /**
  * Test js_value and json methods.
  *
  * @see WP_Customize_Setting::js_value()
  * @see WP_Customize_Setting::json()
  */
 public function test_js_value()
 {
     $default = "";
     $args = array('type' => 'binary', 'default' => $default, 'transport' => 'postMessage', 'dirty' => true, 'sanitize_js_callback' => create_function('$value', 'return base64_encode( $value );'));
     $setting = new WP_Customize_Setting($this->manager, 'name', $args);
     $this->assertEquals($default, $setting->value());
     $this->assertEquals(base64_encode($default), $setting->js_value());
     $exported = $setting->json();
     $this->assertArrayHasKey('type', $exported);
     $this->assertArrayHasKey('value', $exported);
     $this->assertArrayHasKey('transport', $exported);
     $this->assertArrayHasKey('dirty', $exported);
     $this->assertEquals($setting->js_value(), $exported['value']);
     $this->assertEquals($args['type'], $setting->type);
     $this->assertEquals($args['transport'], $setting->transport);
     $this->assertEquals($args['dirty'], $setting->dirty);
 }