Changeset 1231382
- Timestamp:
- 08/26/2015 05:26:42 PM (11 years ago)
- Location:
- featured-image-caption/trunk
- Files:
-
- 3 added
- 1 deleted
- 10 edited
-
classes/Caption.php (modified) (5 diffs)
-
classes/Hooks.php (modified) (4 diffs)
-
classes/Manage.php (deleted)
-
classes/MetaBox.php (modified) (1 diff)
-
classes/Option.php (modified) (6 diffs)
-
classes/Upgrade.php (added)
-
composer.json (added)
-
composer.lock (added)
-
featured-image-caption.php (modified) (5 diffs)
-
readme.txt (modified) (3 diffs)
-
vendor/autoload.php (modified) (1 diff)
-
vendor/composer/ClassLoader.php (modified) (4 diffs)
-
vendor/composer/autoload_classmap.php (modified) (1 diff)
-
vendor/composer/autoload_real.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
featured-image-caption/trunk/classes/Caption.php
r1187864 r1231382 20 20 public function __construct() { 21 21 // Get plugin options 22 $this->options = get_option( CCFIC_ KEY.'_options' );22 $this->options = get_option( CCFIC_ID . '_options' ); 23 23 } 24 24 … … 31 31 * @return array|null|string If successful, returns the requested result. If unsuccessful, returns null. 32 32 */ 33 public function caption($html = true) 34 { 33 public function caption( $html = true ) { 35 34 // Get the caption data 36 35 global $post; 37 $captiondata = $this->caption_data( $post->ID);36 $captiondata = $this->caption_data( $post->ID ); 38 37 39 38 // If there is no caption data, return empty. 40 if ( empty($captiondata)) {39 if ( empty( $captiondata ) ) { 41 40 return; 42 41 } 43 42 44 43 // If HTML is not desired, return the raw array 45 if ( empty($html)) {44 if ( empty( $html ) ) { 46 45 return $captiondata; 47 46 } 48 47 49 48 // Get the HTML 50 $caption = $this->html( $captiondata);49 $caption = $this->html( $captiondata ); 51 50 52 51 return $caption; … … 60 59 * @return bool|array $caption If successful, the array of caption data. If unsuccessful, return false. 61 60 */ 62 public function caption_data($id) 63 { 61 public function caption_data( $id ) { 64 62 // Get the caption data from the post meta 65 $caption = get_post_meta( $id, '_'.CCFIC_KEY, true);63 $caption = get_post_meta( $id, '_' . CCFIC_KEY, true ); 66 64 67 65 // If caption data is not present, return false 68 if ( empty($caption)) {66 if ( empty( $caption ) ) { 69 67 return false; 70 68 } 71 69 72 70 // Legacy support: if caption is a string, convert it to an array 73 if ( is_string($caption)) {71 if ( is_string( $caption ) ) { 74 72 $string = $caption; 75 73 $caption = array( … … 97 95 * @return string $caption The fully assembled caption HTML. 98 96 */ 99 public function html($captiondata, $atts = array()) 100 { 97 public function html( $captiondata, $atts = array() ) { 101 98 // Initialize the caption HTML 102 99 if (! empty($this->options->container)) { … … 186 183 * @return string $html The updated post thumbnail HTML. 187 184 */ 188 public function post_thumbnail_filter( $html)185 public function post_thumbnail_filter( $html ) 189 186 { 190 187 // If automatic caption append is not enabled or we're not in The Loop, return the HTML unchanged 191 188 if ( empty( $this->options->auto_append ) || ! in_the_loop() ) { 192 189 return $html; 190 } 191 192 // If auto-append is enabled and should only be done on single posts 193 if ( ! empty( $this->options->auto_append ) && ! empty( $this->options->only_single ) ) { 194 // If we're not on a single post 195 if ( ! is_single() ) { 196 return $html; 197 } 193 198 } 194 199 -
featured-image-caption/trunk/classes/Hooks.php
r1184833 r1231382 18 18 // Admin 19 19 if ( is_admin() ) { 20 // Plugin management21 $this-> manage();20 // Plugin upgrades 21 $this->upgrade(); 22 22 23 23 // Post meta box … … 36 36 37 37 /** 38 * Plugin activation, deactivation, and other management tasks.38 * Caption data. 39 39 * 40 40 * @internal … … 42 42 * @since 0.7.0 43 43 */ 44 private function manage() {45 $ manage = new Manage();44 private function caption() { 45 $caption = new Caption(); 46 46 47 // Plugin deactivation48 register_deactivation_hook( CCFIC_PATH, array( $manage, 'deactivate' ) );47 // Hook into post thumbnail 48 add_filter( 'post_thumbnail_html', array( $caption, 'post_thumbnail_filter' ) ); 49 49 } 50 50 … … 101 101 102 102 /** 103 * Caption data.103 * Plugin upgrades. 104 104 * 105 105 * @internal 106 106 * 107 * @since 0. 7.0107 * @since 0.8.2 108 108 */ 109 private function caption() {110 $ caption = new Caption();109 private function upgrade() { 110 $upgrade = new Upgrade(); 111 111 112 // Hook into post thumbnail113 add_filter('post_thumbnail_html', array($caption, 'post_thumbnail_filter'));112 // Run plugin upgrades 113 $upgrade->upgrades(); 114 114 } 115 115 } -
featured-image-caption/trunk/classes/MetaBox.php
r1184833 r1231382 12 12 /** 13 13 * Create the meta box. 14 * 15 * @todo Support for custom post types. 14 16 */ 15 17 public function metabox() -
featured-image-caption/trunk/classes/Option.php
r1184833 r1231382 20 20 public function __construct() { 21 21 // Get plugin options 22 $this->options = get_option( CCFIC_ KEY.'_options' );22 $this->options = get_option( CCFIC_ID . '_options' ); 23 23 } 24 24 … … 44 44 // Register the plugin options call and the sanitation callback 45 45 register_setting( 46 CCFIC_ KEY.'_options_fields', // The namespace for plugin options fields. This must match settings_fields() used when rendering the form.47 CCFIC_ KEY.'_options', // The name of the plugin options entry in the database.46 CCFIC_ID.'_options_fields', // The namespace for plugin options fields. This must match settings_fields() used when rendering the form. 47 CCFIC_ID.'_options', // The name of the plugin options entry in the database. 48 48 array($this, 'options_validate') // The callback method to validate plugin options 49 49 ); … … 65 65 ); 66 66 67 // Automatically add the caption to the featured image 68 add_settings_field( 69 'auto_append', // Field ID 70 'Automatically add the caption to the featured image', // Field title/label, displayed to the user 71 array($this, 'auto_append_callback'), // Callback method to display the option field 72 CCFIC_ID, // Page ID for the options page 73 'display' // Settings section in which to display the field 74 ); 75 76 // Add a container <div> to the caption HTML 77 add_settings_field( 78 'container', // Field ID 79 'Add a container <div> to the caption HTML', // Field title/label, displayed to the user 80 array($this, 'container_callback'), // Callback method to display the option field 81 CCFIC_ID, // Page ID for the options page 82 'display' // Settings section in which to display the field 83 ); 67 // Settings fields 68 $this->settings_fields(); 84 69 } 85 70 … … 123 108 public function auto_append_callback() 124 109 { 125 $checked = ( ! empty($this->options->auto_append)) ? ' checked' : null;126 127 echo '<input id="' .CCFIC_KEY.'_options[auto_append]" name="'.CCFIC_KEY.'_options[auto_append]" type="checkbox"'.$checked.'>';110 $checked = ( ! empty( $this->options->auto_append ) ) ? ' checked' : null; 111 112 echo '<input id="' . CCFIC_ID . '_options_auto_append" name="' . CCFIC_ID . '_options[auto_append]" type="checkbox"' . $checked . '>'; 128 113 echo '<p class="description"><strong>Recommended.</strong> Automatically display the caption data you set for the featured image wherever the featured image is displayed. You do not have to make any modifications to your theme files. If you don\'t know what this means or why you wouldn\'t want this enabled, leave it checked.</p>'; 129 114 } 130 115 131 116 /** 117 * Callback for the 'only on single posts' option. 118 * 119 * @since 0.8.2 120 */ 121 public function only_single_callback() { 122 // Determine whether the checkbox should be checked 123 $checked = ( ! empty( $this->options->only_single ) ? ' checked' : null ); 124 125 // Display the checkbox and additional option information 126 echo '<input id="' . CCFIC_ID . '_options_only_single" name="' . CCFIC_ID . '_options[only_single]" type="checkbox"' . $checked . '>'; 127 echo '<p class="description">If, when auto appending is enabled, you only want the caption to be appended when viewing a single post, enable this option.</p>'; 128 } 129 130 /** 132 131 * Callback for container div. 133 132 */ 134 133 public function container_callback() 135 134 { 136 $checked = ( ! empty($this->options->container)) ? ' checked' : null;137 138 echo '<input id="' .CCFIC_KEY.'_options[container]" name="'.CCFIC_KEY.'_options[container]" type="checkbox"'.$checked.'>';135 $checked = ( ! empty( $this->options->container ) ) ? ' checked' : null; 136 137 echo '<input id="' . CCFIC_ID . '_options_container" name="' . CCFIC_ID . '_options[container]" type="checkbox"' . $checked . '>'; 139 138 echo '<p class="description"><strong>Recommended.</strong> Put the entire HTML output of the caption information inside a <div> tag, to give you more control over styling the caption. If you do not know what this means, leave it checked.</p>'; 140 139 } … … 158 157 <form action="options.php" method="post"> 159 158 <?php 160 settings_fields(CCFIC_ KEY.'_options_fields');159 settings_fields(CCFIC_ID.'_options_fields'); 161 160 do_settings_sections(CCFIC_ID); 162 161 submit_button(); … … 184 183 185 184 $options = $options_obj; 186 187 // If the version number is missing, add it188 if ( empty( $options->version ) ) {189 $options->version = CCFIC_VERSION;190 }191 185 } 192 186 193 187 // Set the values to store in the database for each of the options 194 $options->auto_append = (! empty($input['auto_append'])) ? true : false; 195 $options->container = (! empty($input['container'])) ? true : false; 188 $options->auto_append = ( ! empty( $input['auto_append'] ) ) ? true : false; 189 $options->only_single = ( ! empty( $input['only_single'] ) ) ? true : false; 190 $options->container = ( ! empty( $input['container'] ) ) ? true : false; 196 191 197 192 return $options; 198 193 } 194 195 /** 196 * Settings fields. 197 * 198 * Add settings fields to the options page. 199 * 200 * @since 0.8.2 201 */ 202 private function settings_fields() { 203 // Automatically add the caption to the featured image 204 add_settings_field( 205 'auto_append', 206 'Automatically add the caption to the featured image', 207 array($this, 'auto_append_callback'), 208 CCFIC_ID, 209 'display' 210 ); 211 212 // Only show the caption when viewing a single post 213 add_settings_field( 214 'only_single', 215 'Only automatically append on single posts', 216 array( $this, 'only_single_callback' ), 217 CCFIC_ID, 218 'display' 219 ); 220 221 // Add a container <div> to the caption HTML 222 add_settings_field( 223 'container', 224 'Add a container <div> to the caption HTML', 225 array($this, 'container_callback'), 226 CCFIC_ID, 227 'display' 228 ); 229 } 199 230 } -
featured-image-caption/trunk/featured-image-caption.php
r1187864 r1231382 1 1 <?php 2 3 2 /* 4 * Plugin Name: Featured Image Caption 5 * Plugin URI: https://christiaanconover.com/code/wp-featured-image-caption?utm_source=wp-featured-image-caption 6 * Description: Set a caption for the featured image of a post that can be displayed on your site. 7 * Version: 0.8.1 8 * Author: Christiaan Conover 9 * Author URI: https://christiaanconover.com?utm_source=wp-featured-image-caption-author 10 * License: GPLv2. 11 */ 3 Plugin Name: Featured Image Caption 4 Plugin URI: https://christiaanconover.com/code/wp-featured-image-caption?utm_source=wp-featured-image-caption 5 Description: Set a caption for the featured image of a post that can be displayed on your site. 6 Version: 0.8.2 7 Author: Christiaan Conover 8 Author URI: https://christiaanconover.com?utm_source=wp-featured-image-caption-author 9 License: GPLv2. 10 Text Domain: cc-featured-image-caption 11 */ 12 12 13 13 // Prevent direct access … … 16 16 } 17 17 18 /* Define plugin constants */ 19 define( 'CCFIC_ID', 'ccfic' ); // Plugin ID 20 define( 'CCFIC_NAME', 'Featured Image Caption' ); // Plugin name 21 define( 'CCFIC_VERSION', '0.8.2' ); // Plugin version 22 define( 'CCFIC_WPVER', '3.5' ); // Minimum required version of WordPress 23 define( 'CCFIC_KEY', 'cc_featured_image_caption' ); // Database key (legacy support, ID now used) 24 define( 'CCFIC_PATH', __FILE__ ) ; // Path to the primary plugin file 25 18 26 // Check that the version of PHP is sufficient 19 if (version_compare(phpversion(), '5.3', '<')) { 20 trigger_error('PHP version '.phpversion().' is unsupported, must be version 5.3 or newer', E_USER_ERROR); 21 22 return; 27 if ( version_compare( phpversion(), '5.3', '<' ) ) { 28 deactivate_plugins( plugin_basename( CCFIC_PATH ) ); 29 wp_die( 'PHP version '.phpversion().' is unsupported by ' . CCFIC_NAME . ', must be version 5.3 or newer.' ); 23 30 } 24 31 25 /* Define plugin constants */ 26 define('CCFIC_ID', 'cc-featured-image-caption'); // Plugin ID 27 define('CCFIC_NAME', 'Featured Image Caption'); // Plugin name 28 define('CCFIC_VERSION', '0.8.1'); // Plugin version 29 define('CCFIC_WPVER', '3.5'); // Minimum required version of WordPress 30 define('CCFIC_KEY', 'cc_featured_image_caption'); // Database key 31 define('CCFIC_PATH', __FILE__); // Path to the primary plugin file 32 33 if (is_admin()) { 32 if ( is_admin() ) { 34 33 // Plugin activation 35 register_activation_hook( __FILE__, 'ccfic_activate');34 register_activation_hook( __FILE__, 'ccfic_activate' ); 36 35 } 37 36 … … 47 46 new \cconover\FeaturedImageCaption\Bootstrap(); 48 47 } 49 add_action( 'plugins_loaded', 'cc_featured_image_caption_loader');48 add_action( 'plugins_loaded', 'cc_featured_image_caption_loader' ); 50 49 51 50 /** … … 61 60 * @return string The formatted caption. 62 61 */ 63 function cc_featured_image_caption( $echo = true, $html = true)62 function cc_featured_image_caption( $echo = true, $html = true ) 64 63 { 65 64 // Call the caption data using the shortcode 66 65 $format = $html ? '' : ' format="plaintext"'; 67 $caption = do_shortcode( '[ccfic'.$format.']');66 $caption = do_shortcode( '[ccfic' . $format . ']' ); 68 67 69 68 // If the result should be printed to the screen. 70 if ( $echo) {69 if ( $echo ) { 71 70 echo $caption; 72 71 } else { … … 98 97 { 99 98 // Check to make sure the version of WordPress being used is compatible with the plugin 100 if (version_compare(get_bloginfo('version'), CCFIC_WPVER, '<')) { 101 wp_die('Your version of WordPress is too old to use this plugin. Please upgrade to the latest version of WordPress.'); 99 if ( version_compare( get_bloginfo( 'version' ), CCFIC_WPVER, '<' ) ) { 100 deactivate_plugins( plugin_basename( CCFIC_PATH ) ); 101 wp_die( 'Your version of WordPress is too old to use this plugin. Please upgrade to the latest version of WordPress.' ); 102 102 } 103 104 // Plugin environment data 105 $env = new \stdClass(); 106 $env->version = CCFIC_VERSION; 107 108 // Add environment data to the database 109 add_option( CCFIC_ID . '_env', $env ); 103 110 104 111 // Default plugin options 105 112 $options = new \stdClass(); 106 $options->version = CCFIC_VERSION; // Current plugin version107 113 $options->auto_append = true; // Automatically append caption to featured image 114 $options->only_single = false; // Restrict automatic caption appending to single posts 108 115 $options->container = true; // Wrap the caption HTML in a container div 109 116 110 117 // Add options to database 111 $result = add_option(CCFIC_KEY.'_options', $options); 112 113 return $result; 118 add_option( CCFIC_ID . '_options', $options ); 114 119 } -
featured-image-caption/trunk/readme.txt
r1221650 r1231382 5 5 Requires at least: 3.5 6 6 Tested up to: 4.3 7 Stable tag: 0.8. 17 Stable tag: 0.8.2 8 8 License: GPLv2 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 33 33 34 34 == Upgrade Notice == 35 36 = 0.8.2 = 37 When automatic caption appending is enabled, the plugin can optionally only append the caption when viewing a single post. 35 38 36 39 = 0.8.0 = … … 89 92 90 93 == Changelog == 94 95 = 0.8.2 = 96 * When automatic caption appending is enabled, the plugin can optionally only append the caption when viewing a single post. 97 * Improved validation of supported PHP version. If PHP is too old, the plugin is deactivated and a warning is displayed. 98 * Bug fixes and improvements. 91 99 92 100 = 0.8.1 = -
featured-image-caption/trunk/vendor/autoload.php
r1187864 r1231382 5 5 require_once __DIR__ . '/composer' . '/autoload_real.php'; 6 6 7 return ComposerAutoloaderInit c91643edaea3771dd8e0cc942282d3a4::getLoader();7 return ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f::getLoader(); -
featured-image-caption/trunk/vendor/composer/ClassLoader.php
r1183383 r1231382 352 352 if (0 === strpos($class, $prefix)) { 353 353 foreach ($this->prefixDirsPsr4[$prefix] as $dir) { 354 if ( is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {354 if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { 355 355 return $file; 356 356 } … … 362 362 // PSR-4 fallback dirs 363 363 foreach ($this->fallbackDirsPsr4 as $dir) { 364 if ( is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {364 if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { 365 365 return $file; 366 366 } … … 381 381 if (0 === strpos($class, $prefix)) { 382 382 foreach ($dirs as $dir) { 383 if ( is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {383 if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 384 384 return $file; 385 385 } … … 391 391 // PSR-0 fallback dirs 392 392 foreach ($this->fallbackDirsPsr0 as $dir) { 393 if ( is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {393 if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { 394 394 return $file; 395 395 } -
featured-image-caption/trunk/vendor/composer/autoload_classmap.php
r1184833 r1231382 67 67 'cconover\\FeaturedImageCaption\\Caption' => $baseDir . '/classes/Caption.php', 68 68 'cconover\\FeaturedImageCaption\\Hooks' => $baseDir . '/classes/Hooks.php', 69 'cconover\\FeaturedImageCaption\\Manage' => $baseDir . '/classes/Manage.php',70 69 'cconover\\FeaturedImageCaption\\MetaBox' => $baseDir . '/classes/MetaBox.php', 71 70 'cconover\\FeaturedImageCaption\\Option' => $baseDir . '/classes/Option.php', 72 71 'cconover\\FeaturedImageCaption\\Shortcode' => $baseDir . '/classes/Shortcode.php', 72 'cconover\\FeaturedImageCaption\\Upgrade' => $baseDir . '/classes/Upgrade.php', 73 73 ); -
featured-image-caption/trunk/vendor/composer/autoload_real.php
r1187864 r1231382 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit c91643edaea3771dd8e0cc942282d3a45 class ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f 6 6 { 7 7 private static $loader; … … 20 20 } 21 21 22 spl_autoload_register(array('ComposerAutoloaderInit c91643edaea3771dd8e0cc942282d3a4', 'loadClassLoader'), true, true);22 spl_autoload_register(array('ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f', 'loadClassLoader'), true, true); 23 23 self::$loader = $loader = new \Composer\Autoload\ClassLoader(); 24 spl_autoload_unregister(array('ComposerAutoloaderInit c91643edaea3771dd8e0cc942282d3a4', 'loadClassLoader'));24 spl_autoload_unregister(array('ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f', 'loadClassLoader')); 25 25 26 26 $map = require __DIR__ . '/autoload_namespaces.php'; … … 45 45 } 46 46 47 function composerRequire c91643edaea3771dd8e0cc942282d3a4($file)47 function composerRequire5682686e4d0f389e4e54424212d26e8f($file) 48 48 { 49 49 require $file;
Note: See TracChangeset
for help on using the changeset viewer.