to_json example

    public $context;              // Unused.     public $extensions = array(); // Unused.
    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since 3.4.0 * * @uses WP_Customize_Media_Control::to_json() */
    public function to_json() {
        parent::to_json();

        $value = $this->value();
        if ( $value ) {
            // Get the attachment model for the existing file.             $attachment_id = attachment_url_to_postid( $value );
            if ( $attachment_id ) {
                $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
            }
        }
    }
}

    }

    /** * Get the data to export to the client via JSON. * * @since 4.1.0 * * @return array Array of parameters passed to the JavaScript. */
    public function json() {
        $this->to_json();
        return $this->json;
    }

    /** * Checks if the user can use this control. * * Returns false if the user cannot manipulate one of the associated settings, * or if one of the associated settings does not exist. Also returns false if * the associated section does not exist or if its capability check returns * false. * * @since 3.4.0 * * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true. */


    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since 3.4.0 * @since 4.2.0 Moved from WP_Customize_Upload_Control. * * @see WP_Customize_Control::to_json() */
    public function to_json() {
        parent::to_json();
        $this->json['label']         = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) );
        $this->json['mime_type']     = $this->mime_type;
        $this->json['button_labels'] = $this->button_labels;
        $this->json['canUpload']     = current_user_can( 'upload_files' );

        $value = $this->value();

        if ( is_object( $this->setting ) ) {
            if ( $this->setting->default ) {
                /* * Fake an attachment model - needs all fields used by template. * Note that the default value must be a URL, NOT an attachment ID. */

    public $location_id = '';

    /** * Refresh the parameters passed to JavaScript via JSON. * * @since 4.3.0 * * @see WP_Customize_Control::to_json() */
    public function to_json() {
        parent::to_json();
        $this->json['locationId'] = $this->location_id;
    }

    /** * Render content just like a normal select control. * * @since 4.3.0 * @since 4.9.0 Added a button to create menus. */
    public function render_content() {
        if ( empty( $this->choices ) ) {
            
/** * Gather control params for exporting to JavaScript. * * @since 3.9.0 * * @global array $wp_registered_widgets */
    public function to_json() {
        global $wp_registered_widgets;

        parent::to_json();
        $exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
        foreach ( $exported_properties as $key ) {
            $this->json[ $key ] = $this->$key;
        }

        // Get the widget_control and widget_content.         require_once ABSPATH . 'wp-admin/includes/widgets.php';

        $widget = $wp_registered_widgets[ $this->widget_id ];
        if ( ! isset( $widget['params'][0] ) ) {
            $widget['params'][0] = array();
        }
/** * Refresh the parameters passed to the JavaScript via JSON. * * @since Twenty Twenty-One 1.0 * * @uses WP_Customize_Control::to_json() * * @return void */
    public function to_json() {
        parent::to_json();
        $this->json['palette'] = $this->palette;
    }
}

    public $sidebar_id;

    /** * Refreshes the parameters passed to the JavaScript via JSON. * * @since 3.9.0 */
    public function to_json() {
        parent::to_json();
        $exported_properties = array( 'sidebar_id' );
        foreach ( $exported_properties as $key ) {
            $this->json[ $key ] = $this->$key;
        }
    }

    /** * Renders the control's content. * * @since 3.9.0 */
    

    public $theme;

    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since 4.2.0 * * @see WP_Customize_Control::to_json() */
    public function to_json() {
        parent::to_json();
        $this->json['theme'] = $this->theme;
    }

    /** * Don't render the control content from PHP, as it's rendered via JS on load. * * @since 4.2.0 */
    public function render_content() {}

    /** * Render a JS template for theme display. * * @since 4.2.0 */
parent::enqueue();
    }

    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since 4.3.0 * * @see WP_Customize_Control::to_json() */
    public function to_json() {
        parent::to_json();

        $this->json['width']       = absint( $this->width );
        $this->json['height']      = absint( $this->height );
        $this->json['flex_width']  = absint( $this->flex_width );
        $this->json['flex_height'] = absint( $this->flex_height );
    }

}
wp_enqueue_script( 'wp-color-picker' );
        wp_enqueue_style( 'wp-color-picker' );
    }

    /** * Refresh the parameters passed to the JavaScript via JSON. * * @since 3.4.0 * @uses WP_Customize_Control::to_json() */
    public function to_json() {
        parent::to_json();
        $this->json['statuses']     = $this->statuses;
        $this->json['defaultValue'] = $this->setting->default;
        $this->json['mode']         = $this->mode;
    }

    /** * Don't render the control content from PHP, as it's rendered via JS on load. * * @since 3.4.0 */
    public function render_content() {}

    
Home | Imprint | This part of the site doesn't use cookies.