htmlburger / carbon-fields

WordPress Custom Fields Library ✨
https://carbonfields.net/
Other
1.4k stars 246 forks source link

Widget issue after update to 3.3.0 #984

Closed dy-git-hub closed 3 years ago

dy-git-hub commented 3 years ago

Version

Actual Behavior

Pages and posts edit page in WP admin throw this error message in the console:

Could not find DOM element for container "carbon_fields_container_carbon_fields_widget_podcasts-2".

A blank page is loaded, and the WordPress editor is not accessible.

Container definition

class ThemeWidgetExample extends Widget {
    // Register widget function. Must have the same name as the class
    function __construct() {
        $this->setup( 'widget_podcasts', 'Widget Podcasts', 'Widget Podcasts', array(
            Field::make( 'text', 'widget_podcasts_title', 'Widget Title' ),
            Field::make( 'complex', 'podcasts', 'Podcasts' )
                ->add_fields( array(
                    Field::make('text', 'link', 'Podcast Link'),
                    Field::make('image', 'image_id', 'Podcast Link Image')
                ) )
        ) );
    }
    // Called when rendering the widget in the front-end
    function front_end( $args, $instance ) {
        echo $args['before_title'] . $instance['widget_podcasts_title'] . $args['after_title'];

        $html = '<ul class="podcasts">';
        foreach ($instance['podcasts'] as $key => $podcast) {
            $html .= '<li class="podcast">';
                $html .= '<a href="' . $podcast['link'] . '" rel="noopener nofollow" target="_blank">';
                    $html .= '<figure class="podcast__image">';
                        $html .= wp_get_attachment_image($podcast['image_id'], 'medium');
                    $html .= '</figure> <!-- ./podcast__image -->';
                $html .= '</a>                        ';
            $html .= '</li> <!-- ./podcast -->';
        }   
        $html .= '</ul>';

        echo $html;
    }
}
function load_widgets() {
    register_widget( 'ThemeWidgetExample' );
}
add_action( 'widgets_init', 'load_widgets' );

Steps to Reproduce the Problem

  1. Update htmlburger/carbon-fields to v3.3.0
  2. Register the widget with the given definition above.
  3. Add the new widget to a custom wordpress sidebar in the admin panel. The sidebar is registered as it follows:
          register_sidebar(array(
            'name'          => 'Podcast Sidebar',
            'id'            => 'podcast',
            'class'         => 'widgets',
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget'  => '</li>',
            'before_title'  => '<h2 class="widget__title">',
            'after_title'   => '</h2>',
        ));
    1. Go to Pages or Posts and try to edit a post.
daniloalvess commented 3 years ago

I've got the same problem after upgrade to 3.3 version...

jorostoyanov commented 3 years ago

Fixed in v3.3.1 :)