-
-
Save leepeterson/f3ff01d59ff9970638a1c102597d8839 to your computer and use it in GitHub Desktop.
Revisions
-
carlalexander revised this gist
Jun 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ <?php namespace WPMemeShortcode; /** * The WordPress Meme Shortcode admin page. -
carlalexander revised this gist
Jun 2, 2019 . 1 changed file with 8 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,25 @@ <?php namespace WPMemeShortcode; /** * WordPress Meme Shortcode handler. * * @author Carl Alexander */ class Shortcode { /** * @var Options */ private $options; /** * Register the shortcode class with all the appropriate WordPress hooks. * * @param Options $options */ public static function register(Options $options) { $shortcode = new self($options); @@ -27,9 +29,9 @@ public static function register(WPMemeShortcode_Options $options) /** * Constructor. * * @param Options $options */ public function __construct(Options $options) { $this->options = $options; } -
carlalexander revised this gist
Jun 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -14,4 +14,4 @@ require_once dirname(__FILE__) . '/Plugin.php'; require_once dirname(__FILE__) . '/Shortcode.php'; \WPMemeShortcode\Plugin::load(); -
carlalexander revised this gist
Jun 2, 2019 . 3 changed files with 18 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,25 @@ <?php namespace WPMemeShortcode /** * The WordPress Meme Shortcode admin page. * * @author Carl Alexander */ class AdminPage { /** * @var Options */ private $options; /** * Register the admin page class with all the appropriate WordPress hooks. * * @param Options $options */ public static function register(Options $options) { $page = new self($options); @@ -28,9 +30,9 @@ public static function register(WPMemeShortcode_Options $options) /** * Constructor. * * @param Options $options */ public function __construct(Options $options) { $this->options = $options; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,13 @@ <?php namespace WPMemeShortcode; /** * Manages WordPress Meme Shortcode options. * * @author Carl Alexander */ class Options { /** * @var array @@ -15,7 +17,7 @@ class WPMemeShortcode_Options /** * Load the plugin options from WordPress. * * @return Options */ public static function load() { This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,22 @@ <?php namespace WPMemeShortcode; /** * WordPress Meme Shortcode Plugin. * * @author Carl Alexander */ class Plugin { /** * Loads the plugin into WordPress. */ public static function load() { $options = Options::load(); AdminPage::register($options); Shortcode::register($options); } } -
carlalexander revised this gist
Nov 25, 2016 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <?php /* Plugin Name: WordPress Meme Shortcode Description: Add some memes to your posts using a shortcode! Author: Carl Alexander Author URI: http://www.carlalexander.ca License: GPL3 */ // Load classes require_once dirname(__FILE__) . '/AdminPage.php'; require_once dirname(__FILE__) . '/Options.php'; require_once dirname(__FILE__) . '/Plugin.php'; require_once dirname(__FILE__) . '/Shortcode.php'; WPMemeShortcode_Plugin::load(); -
carlalexander revised this gist
Mar 20, 2014 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class WPMemeShortcode_AdminPage /** * Register the admin page class with all the appropriate WordPress hooks. * * @param WPMemeShortcode_Options $options */ public static function register(WPMemeShortcode_Options $options) { This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class WPMemeShortcode_Shortcode /** * Register the shortcode class with all the appropriate WordPress hooks. * * @param WPMemeShortcode_Options $options */ public static function register(WPMemeShortcode_Options $options) { -
carlalexander revised this gist
Mar 20, 2014 . 4 changed files with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php /** * The WordPress Meme Shortcode admin page. * This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php /** * Manages WordPress Meme Shortcode options. * This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php /** * WordPress Meme Shortcode Plugin. * This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <?php /** * WordPress Meme Shortcode handler. * -
carlalexander created this gist
Mar 20, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,93 @@ /** * The WordPress Meme Shortcode admin page. * * @author Carl Alexander */ class WPMemeShortcode_AdminPage { /** * @var WPMemeShortcode_Options */ private $options; /** * Register the admin page class with all the appropriate WordPress hooks. * * @param array $options */ public static function register(WPMemeShortcode_Options $options) { $page = new self($options); add_action('admin_init', array($page, 'configure')); add_action('admin_menu', array($page, 'addAdminPage')); } /** * Constructor. * * @param WPMemeShortcode_Options $options */ public function __construct(WPMemeShortcode_Options $options) { $this->options = $options; } /** * Adds the admin page to the menu. */ public function addAdminPage() { add_options_page(__('WordPress Meme Shortcode', 'wp_meme_shortcode'), __('Meme Shortcode', 'wp_meme_shortcode'), 'install_plugins', 'wp_meme_shortcode', array($this, 'render')); } /** * Configure the option page using the settings API. */ public function configure() { // Register settings register_setting('wp_meme_shortcode', 'wp_meme_shortcode'); // General Section add_settings_section('wp_meme_shortcode_general', __('General', 'wp_meme_shortcode'), array($this, 'renderGeneralSection'), 'wp_meme_shortcode'); add_settings_field('wp_meme_shortcode_size', __('Default Image Size', 'wp_meme_shortcode'), array($this, 'renderSizeField'), 'wp_meme_shortcode', 'wp_meme_shortcode_general'); } /** * Renders the admin page using the Settings API. */ public function render() { ?> <div class="wrap" id="wp-meme-shortcode-admin"> <h2><?php _e('WordPress Meme Shortcode', 'wp_meme_shortcode'); ?></h2> <form action="options.php" method="POST"> <?php settings_fields('wp_meme_shortcode'); ?> <?php do_settings_sections('wp_meme_shortcode'); ?> <?php submit_button(); ?> </form> </div> <?php } /** * Renders the general section. */ public function renderGeneralSection() { ?> <p><?php _e('Configure WordPress Meme Shortcode.', 'wp_meme_shortcode'); ?></p> <?php } /** * Renders the size field. */ public function renderSizeField() { ?> <input id="wp_meme_shortcode_size" name="wp_meme_shortcode[size]" type="number" value="<?php echo $this->options->get('size', '500'); ?>" /> <?php } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ /** * Manages WordPress Meme Shortcode options. * * @author Carl Alexander */ class WPMemeShortcode_Options { /** * @var array */ private $options; /** * Load the plugin options from WordPress. * * @return WPMemeShortcode_Options */ public static function load() { $options = get_option('wp_meme_shortcode', array()); return new self($options); } /** * Constructor. * * @param array $options */ public function __construct(array $options = array()) { $this->options = $options; } /** * Gets the option for the given name. Returns the default value if the * value does not exist. * * @param string $name * @param mixed $default * * @return mixed */ public function get($name, $default = null) { if (!$this->has($name)) { return $default; } return $this->options[$name]; } /** * Checks if the option exists or not. * * @param string $name * * @return Boolean */ public function has($name) { return isset($this->options[$name]); } /** * Sets an option. Overwrites the existing option if the name is already in use. * * @param string $name * @param mixed $value */ public function set($name, $value) { $this->options[$name] = $value; } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ /** * WordPress Meme Shortcode Plugin. * * @author Carl Alexander */ class WPMemeShortcode_Plugin { /** * Loads the plugin into WordPress. */ public static function load() { $options = WPMemeShortcode_Options::load(); WPMemeShortcode_AdminPage::register($options); WPMemeShortcode_Shortcode::register($options); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ /** * WordPress Meme Shortcode handler. * * @author Carl Alexander */ class WPMemeShortcode_Shortcode { /** * @var WPMemeShortcode_Options */ private $options; /** * Register the shortcode class with all the appropriate WordPress hooks. * * @param array $options */ public static function register(WPMemeShortcode_Options $options) { $shortcode = new self($options); add_shortcode('meme', array($shortcode, 'handle')); } /** * Constructor. * * @param WPMemeShortcode_Options $options */ public function __construct(WPMemeShortcode_Options $options) { $this->options = $options; } /** * Handles the output of the shortcode. * * @param array $attributes * @param string $content */ public function handle(array $attributes, $content = null) { // Do nothing if no ID is given or it is not numeric if (!isset($attributes['id']) || !is_numeric($attributes['id'])) { return $content; } // If no size is given or it is not a numeric value, get default. if (!isset($attributes['size']) || !is_numeric($attributes['size'])) { $attributes['size'] = $this->options->get('size', '500'); } return "<img src=\"http://cdn.memegenerator.net/instances/{$attributes['size']}x/{$attributes['id']}.jpg\" />"; } }