Plugin Contributor
alexgso
(@alexgso)
Hi timdenty,
To clarify, are you using the SiteOrigin Widgets Bundle framework to create a custom widget or are you creating a completely custom widget?
If the former, can you please send me a copy of your widget so I can check the code?
if the latter, how are you handling saving the widget settings?
Hi Alex – It is a completely custom widget, using the WP_Widget class.
<?php
// Test Custom Widget
class sales_widget extends WP_Widget {
function __construct() {
parent::__construct(
// Base ID of your widget
'sales_widget',
// Widget name will appear in UI
__('Custom Sales Widget', 'sales_widget_domain'),
// Widget description
array( 'description' => __( 'Displays the sales button', 'sales_widget_domain' ), )
);
}
// Create widget front-end
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
// Run the code and display the output
echo '
<div class="box_cta">
<h2>'. get_field('cta_title', 'widget_' . $args['widget_id']) .'</h2>
<p><a href="#" class="cta cta_big">'. get_field('cta_button_text', 'widget_' . $args['widget_id']) .'<i class="fa fa-chevron-right"></i></a></p>
</div>
';
echo $args['after_widget'];
}
// Widget Backend
public function form( $instance ) {
if (isset($instance[ 'title' ])) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'sales_widget_domain' );
}
// Widget admin form
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class sales_widget ends here
// Register and load the widget
function sales_load_widget() {
register_widget( 'sales_widget' );
}
add_action( 'widgets_init', 'sales_load_widget' );
?>
Plugin Contributor
alexgso
(@alexgso)
Hi timdenty,
Thanks. To clarify, are you able to get any output anything on the frontend? As in, if you add some basic dummy text (without any validation or checks), does it output?
No unfortunately, nothing inputted to the custom widget via the layout builder is outputted on the frontend.
The ACF widget fields show ok within the layout builder in wp-admin, but do not save their values. On saving the page, they appear blank again.
I’ve read a few other similar threads on both the SiteOrigin & ACF forums and have yet to find any robust solution.
Perhaps I need to rethink my approach here – integration between these two plugins would be great in the future though.
Plugin Contributor
alexgso
(@alexgso)
Hi Tim,
I’ve looked into ACF compatibility, and I sadly have to agree. You’re best bet, sadly, would be to look into alternative methods of handling the forms. Sorry about this! 🙁