'Displays Page Ratings into a neat slider.', ); parent::__construct( 'fbr_ratings_slider_widget', 'FB Ratings Slider', $widget_ops ); } /** * Outputs the options form on admin * * @param array $instance The widget options */ public function form( $instance ) { // outputs the options form on admin } /** * Processing widget options on save * * @param array $new_instance The new options * @param array $old_instance The previous options * * @return array */ public function update( $new_instance, $old_instance ) { // processes widget options to be saved $instance = []; $fbr_opts = get_option( 'fbr_opts' ); extract( $fbr_opts ); $fbr_opts['fbr_ratings'] = array(); $fb = new Facebook\Facebook([ 'app_id' => $fbr_app_id, 'app_secret' => $fbr_app_secret, 'default_graph_version' => 'v2.2', ]); try { // Get the \Facebook\GraphNodes\GraphUser object for the current user. // If you provided a 'default_access_token', the '{access-token}' is optional. $response = $fb->get('/'. $fbr_page_id .'/ratings?fields=reviewer,has_rating,has_review,review_text,rating,created_time', $fbr_page_access_token); } catch(\Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(\Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } $graphEdge = $response->getGraphEdge(); foreach( $graphEdge as $graphNode ) { if( $graphNode->getField( 'has_rating' ) && $graphNode->getField('has_review') && $graphNode->getField('rating') > 3 ){ array_push($fbr_opts['fbr_ratings'], $graphNode->asArray()); } } error_log(print_r($fbr_opts['fbr_ratings'], true)); update_option( 'fbr_opts', $fbr_opts ); return $instance; } /** * Outputs the content of the widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { // outputs the content of the widget extract( $args ); // extract( $instance ); $fbr_opts = get_option( 'fbr_opts' ); extract( $fbr_opts ); echo $before_widget; ?>
$i ) { $html .= '' . jouvanceau_get_svg( array( 'icon' => 'star-plain', 'id' => '', 'class' => '' ) ) . ''; } else { $html .= '' . jouvanceau_get_svg( array( 'icon' => 'star-empty', 'id' => '', 'class' => '' ) ) . ''; } } echo $html; }