doing_ajax example


    public function register_settings() {
        $widget_setting_ids   = array();
        $incoming_setting_ids = array_keys( $this->manager->unsanitized_post_values() );
        foreach ( $incoming_setting_ids as $setting_id ) {
            if ( ! is_null( $this->get_setting_type( $setting_id ) ) ) {
                $widget_setting_ids[] = $setting_id;
            }
        }
        if ( $this->manager->doing_ajax( 'update-widget' ) && isset( $_REQUEST['widget-id'] ) ) {
            $widget_setting_ids[] = $this->get_setting_id( wp_unslash( $_REQUEST['widget-id'] ) );
        }

        $settings = $this->manager->add_dynamic_settings( array_unique( $widget_setting_ids ) );

        if ( $this->manager->settings_previewed() ) {
            foreach ( $settings as $setting ) {
                $setting->preview();
            }
        }
    }

    
/** * Custom wp_die wrapper. Returns either the standard message for UI * or the Ajax message. * * @since 3.4.0 * * @param string|WP_Error $ajax_message Ajax return. * @param string $message Optional. UI message. */
    protected function wp_die( $ajax_message$message = null ) {
        if ( $this->doing_ajax() ) {
            wp_die( $ajax_message );
        }

        if ( ! $message ) {
            $message = __( 'Something went wrong.' );
        }

        if ( $this->messenger_channel ) {
            ob_start();
            wp_enqueue_scripts();
            wp_print_scripts( array( 'customize-base' ) );

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