Plugin Directory

Changeset 1231382


Ignore:
Timestamp:
08/26/2015 05:26:42 PM (11 years ago)
Author:
cconover
Message:

Version 0.8.2

Location:
featured-image-caption/trunk
Files:
3 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • featured-image-caption/trunk/classes/Caption.php

    r1187864 r1231382  
    2020    public function __construct() {
    2121        // Get plugin options
    22         $this->options = get_option( CCFIC_KEY.'_options' );
     22        $this->options = get_option( CCFIC_ID . '_options' );
    2323    }
    2424
     
    3131     * @return array|null|string If successful, returns the requested result. If unsuccessful, returns null.
    3232     */
    33     public function caption($html = true)
    34     {
     33    public function caption( $html = true ) {
    3534        // Get the caption data
    3635        global $post;
    37         $captiondata = $this->caption_data($post->ID);
     36        $captiondata = $this->caption_data( $post->ID );
    3837
    3938        // If there is no caption data, return empty.
    40         if (empty($captiondata)) {
     39        if ( empty( $captiondata ) ) {
    4140            return;
    4241        }
    4342
    4443        // If HTML is not desired, return the raw array
    45         if (empty($html)) {
     44        if ( empty( $html ) ) {
    4645            return $captiondata;
    4746        }
    4847
    4948        // Get the HTML
    50         $caption = $this->html($captiondata);
     49        $caption = $this->html( $captiondata );
    5150
    5251        return $caption;
     
    6059     * @return bool|array $caption If successful, the array of caption data. If unsuccessful, return false.
    6160     */
    62     public function caption_data($id)
    63     {
     61    public function caption_data( $id ) {
    6462        // 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 );
    6664
    6765        // If caption data is not present, return false
    68         if (empty($caption)) {
     66        if ( empty( $caption ) ) {
    6967            return false;
    7068        }
    7169
    7270        // Legacy support: if caption is a string, convert it to an array
    73         if (is_string($caption)) {
     71        if ( is_string( $caption ) ) {
    7472            $string = $caption;
    7573            $caption = array(
     
    9795     * @return string $caption        The fully assembled caption HTML.
    9896     */
    99     public function html($captiondata, $atts = array())
    100     {
     97    public function html( $captiondata, $atts = array() ) {
    10198        // Initialize the caption HTML
    10299        if (! empty($this->options->container)) {
     
    186183     * @return string $html The updated post thumbnail HTML.
    187184     */
    188     public function post_thumbnail_filter($html)
     185    public function post_thumbnail_filter( $html )
    189186    {
    190187        // If automatic caption append is not enabled or we're not in The Loop, return the HTML unchanged
    191188        if ( empty( $this->options->auto_append ) || ! in_the_loop() ) {
    192189            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            }
    193198        }
    194199
  • featured-image-caption/trunk/classes/Hooks.php

    r1184833 r1231382  
    1818        // Admin
    1919        if ( is_admin() ) {
    20             // Plugin management
    21             $this->manage();
     20            // Plugin upgrades
     21            $this->upgrade();
    2222
    2323            // Post meta box
     
    3636
    3737    /**
    38      * Plugin activation, deactivation, and other management tasks.
     38     * Caption data.
    3939     *
    4040     * @internal
     
    4242     * @since 0.7.0
    4343     */
    44     private function manage() {
    45         $manage = new Manage();
     44    private function caption() {
     45        $caption = new Caption();
    4646
    47         // Plugin deactivation
    48         register_deactivation_hook( CCFIC_PATH, array( $manage, 'deactivate' ) );
     47        // Hook into post thumbnail
     48        add_filter( 'post_thumbnail_html', array( $caption, 'post_thumbnail_filter' ) );
    4949    }
    5050
     
    101101
    102102    /**
    103      * Caption data.
     103     * Plugin upgrades.
    104104     *
    105105     * @internal
    106106     *
    107      * @since 0.7.0
     107     * @since 0.8.2
    108108     */
    109     private function caption() {
    110         $caption = new Caption();
     109    private function upgrade() {
     110        $upgrade = new Upgrade();
    111111
    112         // Hook into post thumbnail
    113         add_filter('post_thumbnail_html', array($caption, 'post_thumbnail_filter'));
     112        // Run plugin upgrades
     113        $upgrade->upgrades();
    114114    }
    115115}
  • featured-image-caption/trunk/classes/MetaBox.php

    r1184833 r1231382  
    1212    /**
    1313     * Create the meta box.
     14     *
     15     * @todo Support for custom post types.
    1416     */
    1517    public function metabox()
  • featured-image-caption/trunk/classes/Option.php

    r1184833 r1231382  
    2020    public function __construct() {
    2121        // Get plugin options
    22         $this->options = get_option( CCFIC_KEY.'_options' );
     22        $this->options = get_option( CCFIC_ID . '_options' );
    2323    }
    2424
     
    4444        // Register the plugin options call and the sanitation callback
    4545        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.
    4848            array($this, 'options_validate') // The callback method to validate plugin options
    4949        );
     
    6565        );
    6666
    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 &lt;div&gt; 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();
    8469    }
    8570
     
    123108    public function auto_append_callback()
    124109    {
    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 . '>';
    128113        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>';
    129114    }
    130115
    131116    /**
     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    /**
    132131     * Callback for container div.
    133132     */
    134133    public function container_callback()
    135134    {
    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 . '>';
    139138        echo '<p class="description"><strong>Recommended.</strong> Put the entire HTML output of the caption information inside a &lt;div&gt; tag, to give you more control over styling the caption. If you do not know what this means, leave it checked.</p>';
    140139    }
     
    158157            <form action="options.php" method="post">
    159158                <?php
    160                 settings_fields(CCFIC_KEY.'_options_fields');
     159                settings_fields(CCFIC_ID.'_options_fields');
    161160        do_settings_sections(CCFIC_ID);
    162161        submit_button();
     
    184183
    185184            $options = $options_obj;
    186 
    187             // If the version number is missing, add it
    188             if ( empty( $options->version ) ) {
    189                 $options->version = CCFIC_VERSION;
    190             }
    191185        }
    192186
    193187        // 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;
    196191
    197192        return $options;
    198193    }
     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 &lt;div&gt; to the caption HTML',
     225            array($this, 'container_callback'),
     226            CCFIC_ID,
     227            'display'
     228        );
     229    }
    199230}
  • featured-image-caption/trunk/featured-image-caption.php

    r1187864 r1231382  
    11<?php
    2 
    32/*
    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  */
     3Plugin Name: Featured Image Caption
     4Plugin URI: https://christiaanconover.com/code/wp-featured-image-caption?utm_source=wp-featured-image-caption
     5Description: Set a caption for the featured image of a post that can be displayed on your site.
     6Version: 0.8.2
     7Author: Christiaan Conover
     8Author URI: https://christiaanconover.com?utm_source=wp-featured-image-caption-author
     9License: GPLv2.
     10Text Domain: cc-featured-image-caption
     11*/
    1212
    1313// Prevent direct access
     
    1616}
    1717
     18/* Define plugin constants */
     19define( 'CCFIC_ID', 'ccfic' ); // Plugin ID
     20define( 'CCFIC_NAME', 'Featured Image Caption' ); // Plugin name
     21define( 'CCFIC_VERSION', '0.8.2' ); // Plugin version
     22define( 'CCFIC_WPVER', '3.5' ); // Minimum required version of WordPress
     23define( 'CCFIC_KEY', 'cc_featured_image_caption' ); // Database key (legacy support, ID now used)
     24define( 'CCFIC_PATH', __FILE__ ) ; // Path to the primary plugin file
     25
    1826// 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;
     27if ( 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.' );
    2330}
    2431
    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()) {
     32if ( is_admin() ) {
    3433    // Plugin activation
    35     register_activation_hook(__FILE__, 'ccfic_activate');
     34    register_activation_hook( __FILE__, 'ccfic_activate' );
    3635}
    3736
     
    4746    new \cconover\FeaturedImageCaption\Bootstrap();
    4847}
    49 add_action('plugins_loaded', 'cc_featured_image_caption_loader');
     48add_action( 'plugins_loaded', 'cc_featured_image_caption_loader' );
    5049
    5150/**
     
    6160 * @return string The formatted caption.
    6261 */
    63 function cc_featured_image_caption($echo = true, $html = true)
     62function cc_featured_image_caption( $echo = true, $html = true )
    6463{
    6564    // Call the caption data using the shortcode
    6665    $format = $html ? '' : ' format="plaintext"';
    67     $caption = do_shortcode('[ccfic'.$format.']');
     66    $caption = do_shortcode( '[ccfic' . $format . ']' );
    6867
    6968    // If the result should be printed to the screen.
    70     if ($echo) {
     69    if ( $echo ) {
    7170        echo $caption;
    7271    } else {
     
    9897{
    9998    // 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.' );
    102102    }
     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 );
    103110
    104111    // Default plugin options
    105112    $options = new \stdClass();
    106     $options->version = CCFIC_VERSION; // Current plugin version
    107113    $options->auto_append = true; // Automatically append caption to featured image
     114    $options->only_single = false; // Restrict automatic caption appending to single posts
    108115    $options->container = true; // Wrap the caption HTML in a container div
    109116
    110117    // Add options to database
    111     $result = add_option(CCFIC_KEY.'_options', $options);
    112 
    113     return $result;
     118    add_option( CCFIC_ID . '_options', $options );
    114119}
  • featured-image-caption/trunk/readme.txt

    r1221650 r1231382  
    55Requires at least: 3.5
    66Tested up to: 4.3
    7 Stable tag: 0.8.1
     7Stable tag: 0.8.2
    88License: GPLv2
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3333
    3434== Upgrade Notice ==
     35
     36= 0.8.2 =
     37When automatic caption appending is enabled, the plugin can optionally only append the caption when viewing a single post.
    3538
    3639= 0.8.0 =
     
    8992
    9093== 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.
    9199
    92100= 0.8.1 =
  • featured-image-caption/trunk/vendor/autoload.php

    r1187864 r1231382  
    55require_once __DIR__ . '/composer' . '/autoload_real.php';
    66
    7 return ComposerAutoloaderInitc91643edaea3771dd8e0cc942282d3a4::getLoader();
     7return ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f::getLoader();
  • featured-image-caption/trunk/vendor/composer/ClassLoader.php

    r1183383 r1231382  
    352352                if (0 === strpos($class, $prefix)) {
    353353                    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))) {
    355355                            return $file;
    356356                        }
     
    362362        // PSR-4 fallback dirs
    363363        foreach ($this->fallbackDirsPsr4 as $dir) {
    364             if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
     364            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
    365365                return $file;
    366366            }
     
    381381                if (0 === strpos($class, $prefix)) {
    382382                    foreach ($dirs as $dir) {
    383                         if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
     383                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
    384384                            return $file;
    385385                        }
     
    391391        // PSR-0 fallback dirs
    392392        foreach ($this->fallbackDirsPsr0 as $dir) {
    393             if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
     393            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
    394394                return $file;
    395395            }
  • featured-image-caption/trunk/vendor/composer/autoload_classmap.php

    r1184833 r1231382  
    6767    'cconover\\FeaturedImageCaption\\Caption' => $baseDir . '/classes/Caption.php',
    6868    'cconover\\FeaturedImageCaption\\Hooks' => $baseDir . '/classes/Hooks.php',
    69     'cconover\\FeaturedImageCaption\\Manage' => $baseDir . '/classes/Manage.php',
    7069    'cconover\\FeaturedImageCaption\\MetaBox' => $baseDir . '/classes/MetaBox.php',
    7170    'cconover\\FeaturedImageCaption\\Option' => $baseDir . '/classes/Option.php',
    7271    'cconover\\FeaturedImageCaption\\Shortcode' => $baseDir . '/classes/Shortcode.php',
     72    'cconover\\FeaturedImageCaption\\Upgrade' => $baseDir . '/classes/Upgrade.php',
    7373);
  • featured-image-caption/trunk/vendor/composer/autoload_real.php

    r1187864 r1231382  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitc91643edaea3771dd8e0cc942282d3a4
     5class ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f
    66{
    77    private static $loader;
     
    2020        }
    2121
    22         spl_autoload_register(array('ComposerAutoloaderInitc91643edaea3771dd8e0cc942282d3a4', 'loadClassLoader'), true, true);
     22        spl_autoload_register(array('ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f', 'loadClassLoader'), true, true);
    2323        self::$loader = $loader = new \Composer\Autoload\ClassLoader();
    24         spl_autoload_unregister(array('ComposerAutoloaderInitc91643edaea3771dd8e0cc942282d3a4', 'loadClassLoader'));
     24        spl_autoload_unregister(array('ComposerAutoloaderInit5682686e4d0f389e4e54424212d26e8f', 'loadClassLoader'));
    2525
    2626        $map = require __DIR__ . '/autoload_namespaces.php';
     
    4545}
    4646
    47 function composerRequirec91643edaea3771dd8e0cc942282d3a4($file)
     47function composerRequire5682686e4d0f389e4e54424212d26e8f($file)
    4848{
    4949    require $file;
Note: See TracChangeset for help on using the changeset viewer.