* * @link http://looks-awesome.com * @copyright Looks Awesome */ class FlowFlowWPWidget extends WP_Widget{ private $context; public function __construct() { parent::__construct( 'ff_widget', 'Flow-Flow Widget', [ 'description' => 'Place your social stream' ] // Args ); } public function setContext($context){ $this->context = $context; } public function widget( $args, $instance ) { echo $args['before_widget']; if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; } $nst = FlowFlow::get_instance_by_slug('flow-flow'); echo $nst->renderShortCode( [ 'id' => $instance['streamId'] ] ); echo $args['after_widget']; } public function form( $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : 'New title'; //Important! //It will be execute before migrations! //Need to check exist tables and fields! $dbm = LAUtils::dbm($this->context); $streams = []; if (LADDLUtils::existTable($dbm->conn(), $dbm->streams_table_name)) $streams = LADB::streams($dbm->conn(), $dbm->streams_table_name); $value = ''; if (sizeof($streams) > 0){ $streamId = null; foreach ( $streams as $id => $stream ) { if ($streamId == null) $streamId = ! empty( $instance['streamId'] ) ? esc_attr($instance['streamId']) : $id; $streamName = 'Stream #' . $id . ( $stream['name'] ? ' - ' . $stream['name'] : ''); $selected = ($streamId == $id) ? ' selected' : ''; $value .= "\n"; } } ?>