Last active
August 29, 2015 14:15
-
-
Save toyflish/e32da25d3dea6d9eb7c5 to your computer and use it in GitHub Desktop.
Consume Selectagram feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WP Selectagram | |
Plugin URI: | |
Description: Selectagram on wp | |
Version: 1.0 | |
Author: Kai Rautenberg | |
Author URI: http://www.selectagram.com | |
License: GPL2 | |
*/ | |
if(!class_exists('WP_Selectagram')) | |
{ | |
class WP_Selectagram | |
{ | |
var $stream_data; | |
/** | |
* Construct the plugin object | |
*/ | |
public function __construct() | |
{ | |
// register actions | |
add_shortcode('selectagram', array($this, 'render_stream')); | |
} // END public function __construct | |
/** | |
* Activate the plugin | |
*/ | |
public static function activate() | |
{ | |
// Do nothing | |
} // END public static function activate | |
/** | |
* Deactivate the plugin | |
*/ | |
public static function deactivate() | |
{ | |
// Do nothing | |
} // END public static function deactivate | |
public function stream($atts){ | |
$atts = shortcode_atts( | |
array( | |
'username' => 'toyflish', | |
'per_page' => 50, | |
'page' => 1), | |
$atts, | |
'selectagram'); | |
if (!$this->stream_data) { | |
$this->stream_data = json_decode(file_get_contents("http://selectagram.com/feed/{$atts['username']}.json?per_page={$atts['per_page']}&page={$atts['page']}")); | |
} | |
return $this->stream_data; | |
} | |
public function render_stream($atts){ | |
$media_list = ""; | |
foreach($this->stream($atts)->entries as $media){ | |
$media_list .= ' | |
<div class="media-wrapper"> | |
<div class="media"> | |
<a href="'.$media->link.'"> | |
<img class="img-responsive" src="'.$media->images_thumbnail_url.'"> | |
</a> | |
</div> | |
</div>'; | |
} | |
$html = '<div class="content-selectagram">'.$media_list.'</div>'; | |
return $html; | |
} | |
} // END class WP_Plugin_Template | |
} // END if(!class_exists('WP_Plugin_Template')) | |
if(class_exists('WP_Selectagram')) | |
{ | |
// Installation and uninstallation hooks | |
register_activation_hook(__FILE__, array('WP_Selectagram', 'activate')); | |
register_deactivation_hook(__FILE__, array('WP_Selectagram', 'deactivate')); | |
// instantiate the plugin class | |
$wp_selectagram = new WP_Selectagram(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
this file should be placed at /wp-content/plugins/selectagram/wp-selectagram.php
now you can use the awesome shortcode:
[selectagram username="shishabrand" per_page="24"]