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+