function yinstagram_access_token($code) { $data = yinstagram_get_options('settings'); // Get cURL resource $curl = curl_init(); // Set some options - we are passing in a useragent too here curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => 'https://api.instagram.com/oauth/access_token', CURLOPT_USERAGENT => 'Yakadanda Instagram Access Token Request', CURLOPT_POST => 1, CURLOPT_POSTFIELDS => array('client_id' => $data['client_id'], 'client_secret' => $data['client_secret'], 'grant_type' => 'authorization_code', 'redirect_uri' => admin_url('admin.php?page=yinstagram/settings.php'), 'code' => $code))); // Send the request & save response to $resp $resp = curl_exec($curl); // Close request to clear up some resources curl_close($curl); return $resp; }
public function form($instance) { $auth = yinstagram_get_options('token'); $title = isset($instance['title']) ? $instance['title'] : __(null, 'text_domain'); $type = isset($instance['type']) ? $instance['type'] : 'images'; $display_images = isset($instance['display_images']) ? $instance['display_images'] : 'recent'; $username_of_user_id = isset($instance['username_of_user_id']) ? $instance['username_of_user_id'] : null; $hashtags = isset($instance['hashtags']) ? $instance['hashtags'] : null; $size = isset($instance['size']) ? $instance['size'] : 'thumbnail'; $custom_size = isset($instance['custom_size']) ? $instance['custom_size'] : null; $limit = isset($instance['limit']) ? $instance['limit'] : 6; $order = isset($instance['order']) ? $instance['order'] : 'default'; ?> <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> <p> <label for="<?php echo $this->get_field_id('type'); ?> "><?php _e('Type:'); ?> </label><br> <select id="<?php echo $this->get_field_id('type'); ?> " name="<?php echo $this->get_field_name('type'); ?> " class="yinstagram-type"> <option value="images" <?php echo $type == 'images' ? 'selected="selected"' : null; ?> >Images </option> <option value="profile" <?php echo $type == 'profile' ? 'selected="selected"' : null; ?> >Profile </option> </select> </p> <p> <label for="<?php echo $this->get_field_id('display_images'); ?> "><?php _e('Display Images:'); ?> </label><br> <select id="<?php echo $this->get_field_id('display_images'); ?> " name="<?php echo $this->get_field_name('display_images'); ?> " class="yinstagram-display-images"> <option value="recent" <?php echo $display_images == 'recent' ? 'selected="selected"' : null; ?> >Recent </option> <option value="feed" <?php echo $display_images == 'feed' ? 'selected="selected"' : null; ?> >Feed </option> <option value="liked" <?php echo $display_images == 'liked' ? 'selected="selected"' : null; ?> >Liked </option> <option value="tags" <?php echo $display_images == 'tags' ? 'selected="selected"' : null; ?> >Tags </option> </select> </p> <p id="<?php echo $this->get_field_id('recent-container'); ?> " <?php echo $display_images != 'recent' ? 'style="display: none;"' : null; ?> > <label for="<?php echo $this->get_field_id('username_of_user_id'); ?> "><?php _e('Username:'******'username_of_user_id'); ?> " name="<?php echo $this->get_field_name('username_of_user_id'); ?> " type="text" value="<?php echo esc_attr($username_of_user_id); ?> " placeholder="<?php echo isset($auth['user']->username) ? $auth['user']->username : null; ?> "/> </p> <p id="<?php echo $this->get_field_id('hashtags-container'); ?> " <?php echo $display_images != 'tags' ? 'style="display: none;"' : null; ?> > <label for="<?php echo $this->get_field_id('hashtags'); ?> "><?php _e('Hashtags (separated by comma):'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('hashtags'); ?> " name="<?php echo $this->get_field_name('hashtags'); ?> " type="text" value="<?php echo esc_attr($hashtags); ?> " placeholder="e.g. #art, #buildings, #graffiti etc."/> </p> <p class="<?php echo $this->get_field_id('type-container'); ?> " <?php echo $type == 'profile' ? 'style="display: none;"' : null; ?> > <label for="<?php echo $this->get_field_id('size'); ?> "><?php _e('Image Size:'); ?> </label><br> <select id="<?php echo $this->get_field_id('size'); ?> " name="<?php echo $this->get_field_name('size'); ?> "> <option value="thumbnail" <?php echo $size == 'thumbnail' ? 'selected="selected"' : null; ?> >Thumbnail </option> <option value="low_resolution" <?php echo $size == 'low_resolution' ? 'selected="selected"' : null; ?> >Low Resolution </option> <option value="standard_resolution" <?php echo $size == 'standard_resolution' ? 'selected="selected"' : null; ?> >Standard Resolution </option> </select> </p> <p class="<?php echo $this->get_field_id('type-container'); ?> " <?php echo $type == 'profile' ? 'style="display: none;"' : null; ?> > <label for="<?php echo $this->get_field_id('custom_size'); ?> "><?php _e('Custom Image Size (pixel):'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('custom_size'); ?> " name="<?php echo $this->get_field_name('custom_size'); ?> " type="text" value="<?php echo esc_attr($custom_size); ?> " /> </p> <p class="<?php echo $this->get_field_id('type-container'); ?> " <?php echo $type == 'profile' ? 'style="display: none;"' : null; ?> > <label for="<?php echo $this->get_field_id('limit'); ?> "><?php _e('Limit (max 33):'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('limit'); ?> " name="<?php echo $this->get_field_name('limit'); ?> " type="text" value="<?php echo esc_attr($limit); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('order'); ?> "><?php _e('Order:'); ?> </label><br> <select id="<?php echo $this->get_field_id('order'); ?> " name="<?php echo $this->get_field_name('order'); ?> "> <option value="default" <?php echo $order == 'default' ? 'selected="selected"' : null; ?> >Default </option> <option value="shuffle" <?php echo $order == 'shuffle' ? 'selected="selected"' : null; ?> >Shuffle </option> </select> </p> <?php }