Home Fatal error: Class 'Carbon_Fields\Widget' not found
Reply: 0

Fatal error: Class 'Carbon_Fields\Widget' not found

user1182
1#
user1182 Published in May 24, 2018, 11:19 pm

I'm using https://carbonfields.net/ to create custom options for wordpress theme

I tried to copy this code into functions.php:

use Carbon_Fields\Widget;
use Carbon_Fields\Container;





class Banner_Widget extends Widget {
    function __construct() {
        $this->setup( 'banner', __( 'Banner', 'crb' ), __( 'Displays a custom banner.' ), array(
            Field::make( 'attachment', 'image', __( 'Image' ) )
                ->set_required( true ),
            Field::make( 'text', 'link', __( 'Link' ) )
                ->set_required( true ),
        ));
    }

    function front_end( $args, $instance ) {
        echo '<a href="' . esc_url( $instance[ 'link' ] ) . '">';

        echo wp_get_attachment_image( $instance[ 'image' ], 'medium' );

        echo '</a>';
    }
}

add_action( 'widgets_init', 'my_register_custom_widgets' );
function my_register_custom_widgets() {
    register_widget( 'Banner_Widget' );
}

and I ended up with this:

I don't understand this error since use Carbon_Fields\Widget; is already found.

I was using Xampp with PHP 7+

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338421 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO