Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPatrizia Lutz
1,449 PointsSaving widget produces error Warning: Illegal string offset 'title' on on line 152
When trying to save the widget, the title is shortened to the first letter and an error is displayed in the widget form:
Warning: Illegal string offset 'title' in /Users/pea/Sites/wordpress-dev/wp-content/plugins/wp-treehouse-badges/wp-treehouse-badges.php on line 153
Line 153 corresponds to the following in function form()
$title = esc_attr( $instance['title'] );
An error is also displayed on the front-end, where the widget is displayed.
Warning: Illegal string offset 'title' in /Users/pea/Sites/wordpress-dev/wp-content/plugins/wp-treehouse-badges/wp-treehouse-badges.php on line 132
Line 132 corresponds to the following in function widget()
:
$title = apply_filters( 'widget_title', $instance['title'] );
This is the full code:
class Wptreehouse_Badges_Widget extends WP_Widget {
function wptreehouse_badges_widget() {
// Instantiate the parent object
parent::__construct( false, 'Treehouse Badges Widget' );
}
function widget( $args, $instance ) {
// Widget output
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$options = get_option( 'wptreehouse_badges' );
$wptreehouse_profile = $options['wptreehouse_profile'];
require( 'inc/view-front-end.php' );
}
function update( $new_instance, $old_instance ) {
// Save widget options
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
return $instance;
}
function form( $instance ) {
// Output admin widget options form
$title = esc_attr( $instance['title'] );
require( 'inc/view-widget-fields.php' );
}
}
function wptreehouse_register_widget() {
register_widget( 'Wptreehouse_Badges_Widget' );
}
add_action( 'widgets_init', 'wptreehouse_register_widget' );
1 Answer
MS Shohan
Courses Plus Student 305 PointsI am also having the same issue. Did you get any fix?