'widget_instagram', 'description' => 'A widget that show instagram' );
/* Create the widget. */
parent::__construct( 'rst-instagram-widget', 'Agnilla - Instagram', $widget_ops);
}
function widget($args, $instance) {
$html = '';
$html .= $args['before_widget'];
if( !empty($instance['title']) ) {
$html .= $args['before_title'];
$html .= $instance['title'];
$html .= $args['after_title'];
}
$html .= '
';
$my_account = $instance['user_id'];
$count = $instance['count'] ? $instance['count'] : 6;
//Do the deed
if($my_account && $my_account != ''){
$username = strtolower( $my_account );
$username = str_replace( '@', '', $my_account );
$remote = wp_remote_get( 'http://instagram.com/'.trim( $my_account ) );
$shards = explode( 'window._sharedData = ', $remote['body'] );
$insta_json = explode( ';', $shards[1] );
$results_array = json_decode( $insta_json[0], TRUE );
//An example of where to go from there
if($results_array){
$images = $results_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'];
$i = 0;
foreach ($images as $image):
if($count == $i){ break;}
$i++;
$image['thumbnail_src'] = preg_replace( '/^https?\:/i', '', $image['thumbnail_src'] );
$link = 'https://instagram.com/p/' . $image['code'];
$html .= '- ';
$html .= '';
$html .= '
';
$html .= '';
$html .= ' ';
endforeach;
}
}
$html .= '
';
$html .= '';
echo force_balance_tags($html);
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
?>