Plugin Directory

Changeset 2981849


Ignore:
Timestamp:
10/20/2023 06:45:27 PM (2 years ago)
Author:
ryanhellyer
Message:

Update to latest WP coding standards and fixed rounding bug in the plugin review class

Location:
unique-headers
Files:
25 added
10 edited

Legend:

Unmodified
Added
Removed
  • unique-headers/trunk/composer.json

    r2966945 r2981849  
    33    "description": "WordPress plugin which adds the ability to use unique custom header images on individual pages, posts or categories or tags.",
    44    "type": "wordpress-plugin",
    5     "license": "GPL-2.0",
     5    "license": "GPL-2.0-only",
    66    "authors": [
    77        {
    88            "name": "ryanhellyer"
    99        }
    10     ],
    11     "require": {}
     10    ]
    1211}
  • unique-headers/trunk/inc/class-custom-image-meta-box.php

    r2798946 r2981849  
    11<?php
     2/**
     3 * Custom Image Meta Box
     4 *
     5 * This file contains the class definition for adding a custom image meta box in WordPress.
     6 *
     7 * @package   YourPackageName
     8 * @author    Ryan Hellyer <ryanhellyer@gmail.com>
     9 * @copyright Copyright (c) Ryan Hellyer
     10 * @license   http://www.gnu.org/licenses/gpl.html GPL
     11 * @version   1.3
     12 */
    213
    314/**
     
    1526     *
    1627     * @since 1.3
    17      * @access   private
    18      * @var      string    $name
     28     * @access private
     29     * @var string $name
    1930     */
    2031    private $name;
     
    2536     *
    2637     * @since 1.3
    27      * @access   private
    28      * @var      string    $name_underscores
     38     * @access private
     39     * @var string $name_underscores
    2940     */
    3041    private $name_underscores;
     
    3445     *
    3546     * @since 1.3
    36      * @access   private
    37      * @var      string    $dir_uri
     47     * @access private
     48     * @var string $dir_uri
    3849     */
    3950    private $dir_uri;
    4051
    4152    /**
    42      * The title of the meta box
    43      *
    44      * @since 1.3
    45      * @access   private
    46      * @var      string    $title
     53     * The title of the meta box.
     54     *
     55     * @since 1.3
     56     * @access private
     57     * @var string $title
    4758     */
    4859    private $title;
    4960
    5061    /**
    51      * The set custom image text
    52      *
    53      * @since 1.3
    54      * @access   private
    55      * @var      string    $set_custom_image
     62     * The set custom image text.
     63     *
     64     * @since 1.3
     65     * @access private
     66     * @var string $set_custom_image
    5667     */
    5768    private $set_custom_image;
     
    6172     *
    6273     * @since 1.3
    63      * @access   private
    64      * @var      string    $remove_custom_image
     74     * @access private
     75     * @var string $remove_custom_image
    6576     */
    6677    private $remove_custom_image;
    6778
    6879    /**
    69      * The current version of the class
    70      *
    71      * @since 1.3
    72      * @access   private
    73      * @var      string    $version
     80     * The current version of the class.
     81     *
     82     * @since 1.3
     83     * @access private
     84     * @var string $version
    7485     */
    7586    private $version = '1.3';
    7687
    7788    /**
    78      * The post types to add meta boxes to
    79      *
    80      * @since 1.3
    81      * @access   private
    82      * @var      string    $post_types
     89     * The post types to add meta boxes to.
     90     *
     91     * @since 1.3
     92     * @access private
     93     * @var string $post_types
    8394     */
    8495    private $post_types;
    8596
    8697    /**
    87      * Class constructor
    88      * Adds methods to appropriate hooks
    89      *
     98     * Class constructor.
     99     * Adds methods to appropriate hooks.
     100     *
     101     * @param array $args Arguments.
    90102     * @since 1.3
    91103     */
     
    100112        $this->post_types          = $args['post_types'];
    101113
    102         // Add meta box
     114        // Add meta box.
    103115        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
    104116        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
    105         add_action( 'add_meta_boxes',        array( $this, 'add_meta_box' ) );
    106         add_action( 'save_post',             array( $this, 'save_post' ) );
    107 
    108     }
    109 
    110     /*
    111      * Get the attachment ID from the post ID
    112      *
    113      * @since 1.3
    114      * @access   static     This method is static so that front-end scripts can access the attachment ID
    115      * @param    int        $post_id         The post ID
    116      * @return   int        $attachment_id   The attachment ID
    117      */
    118     static function get_attachment_id( $post_id, $name ) {
     117        add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
     118        add_action( 'save_post', array( $this, 'save_post' ) );
     119
     120    }
     121
     122    /**
     123     * Get the attachment ID from the post ID.
     124     *
     125     * @since 1.3
     126     * @access static This method is static so that front-end scripts can access the attachment ID
     127     * @param  int    $post_id The post ID.
     128     * @param string $name The attachment name.
     129     * @return int $attachment_id The attachment ID
     130     */
     131    public static function get_attachment_id( $post_id, $name ) {
    119132
    120133        $attachment_id = get_post_meta( $post_id, '_' . $name . '_id', true );
    121134
    122         // Check for fallback images
     135        // Check for fallback images.
    123136        if ( ! $attachment_id ) {
    124137            $attachment_id = apply_filters( 'unique_header_fallback_images', $post_id );
     
    128141    }
    129142
    130     /*
    131      * Get the attachment URL from the attachment ID
    132      *
    133      * @since 1.3
    134      * @access   static    This method is static so that front-end scripts can access the attachments SRC
    135      * @param    int        $attachment_id   The attachment ID
    136      * @return   string
    137      */
    138     static function get_attachment_src( $attachment_id ) {
     143    /**
     144     * Get the attachment URL from the attachment ID.
     145     *
     146     * @since 1.3
     147     * @access static This method is static so that front-end scripts can access the attachments SRC
     148     * @param int $attachment_id The attachment ID.
     149     * @return string
     150     */
     151    public static function get_attachment_src( $attachment_id ) {
    139152        $url = '';
    140153
    141         // Grab URL from WordPress
     154        // Grab URL from WordPress.
    142155        $src = wp_get_attachment_image_src( $attachment_id, 'full' );
    143156        if ( isset( $src[0] ) ) {
     
    148161    }
    149162
    150     /*
    151      * Get the attachment URL from the attachment ID
    152      *
    153      * @since 1.3
    154      * @access   static     This method is static so that front-end scripts can access the attachments SRC
    155      * @param    int        $attachment_id   The attachment ID
    156      * @return   int
    157      */
    158     static function get_attachment_dimensions( $attachment_id, $dimension = 'width' ) {
    159 
    160         // Grab URL from WordPress
     163    /**
     164     * Get the attachment URL from the attachment ID.
     165     *
     166     * @since 1.3
     167     * @access static This method is static so that front-end scripts can access the attachments SRC
     168     * @param int    $attachment_id The attachment ID.
     169     * @param string $dimension The dimension type.
     170     * @return int
     171     */
     172    public static function get_attachment_dimensions( $attachment_id, $dimension = 'width' ) {
     173
     174        // Grab URL from WordPress.
    161175        $data = wp_get_attachment_image_src( $attachment_id, 'full' );
    162176
    163         if ( 'width' == $dimension && isset( $data[1] ) ) {
     177        if ( 'width' === $dimension && isset( $data[1] ) ) {
    164178            return $data[1];
    165         } else if ( 'height' == $dimension && isset( $data[2] ) ) {
     179        } elseif ( 'height' === $dimension && isset( $data[2] ) ) {
    166180            return $data[2];
    167181        }
     
    173187     *
    174188     * @since 1.3
    175      * @access   static  This method is static so that front-end scripts can access the attachments title
    176      * @param    int      $attachment_id   The attachment ID
    177      * @return   string   $title          The attachment title
    178      */
    179     static function get_attachment_title( $attachment_id ) {
    180 
    181         // Get title (trip and strip_tags method was adapted from WordPress core)
    182         $title = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
     189     * @access static This method is static so that front-end scripts can access the attachments title
     190     * @param int $attachment_id The attachment ID.
     191     * @return string $title The attachment title
     192     */
     193    public static function get_attachment_title( $attachment_id ) {
     194
     195        // Get title (trip and strip_tags method was adapted from WordPress core).
     196        $title = trim( wp_strip_all_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
    183197
    184198        return $title;
     
    228242
    229243    /**
    230      * Registers the stylesheets for handling the meta box
     244     * Registers the stylesheets for handling the meta box.
    231245     *
    232246     * @since 1.3
     
    237251            $this->name,
    238252            $this->dir_uri . '/admin.css',
    239             array()
     253            array(),
     254            $this->version
    240255        );
    241256
     
    245260     * Sanitized and saves the post featured footer image meta data specific with this post.
    246261     *
    247      * @since    1.3
    248      * @param    int    $post_id    The ID of the post with which we're currently working.
    249      * @return   int    $post_id    The ID of the post with which we're currently working.
     262     * @since 1.3
     263     * @param int $post_id The ID of the post with which we're currently working.
     264     * @return int $post_id The ID of the post with which we're currently working.
    250265     */
    251266    public function save_post( $post_id ) {
    252267
    253         // Bail out now if POST vars not set
    254         if ( ! isset( $_POST[$this->name . '-nonce'] ) || ! isset( $_POST[$this->name . '-id'] ) ) {
     268        // Bail out now if POST vars not set.
     269        if ( ! isset( $_POST[ $this->name . '-nonce' ] ) || ! isset( $_POST[ $this->name . '-id' ] ) ) {
    255270            return $post_id;
    256271        }
    257272
    258         // Bail out now if nonce doesn't verify
    259         if ( ! wp_verify_nonce( $_POST[$this->name . '-nonce'], $this->name ) ) {
     273        // Bail out now if nonce doesn't verify.
     274        $nonce = sanitize_text_field( wp_unslash( $_POST[ $this->name . '-nonce' ] ) );
     275        if ( ! wp_verify_nonce( $nonce, $this->name ) ) {
    260276            return $post_id;
    261277        }
    262278
    263         // Sanitize the attachment ID
    264         $attachment_id = sanitize_text_field( $_POST[$this->name . '-id'] );
    265 
    266         // Save the attachment ID in the database
     279        // Sanitize the attachment ID.
     280        $attachment_id = sanitize_text_field( wp_unslash( $_POST[ $this->name . '-id' ] ) );
     281
     282        // Save the attachment ID in the database.
    267283        update_post_meta( $post_id, '_' . $this->name_underscores . '_id', $attachment_id );
    268284
    269         // Return the post ID
     285        // Return the post ID.
    270286        return $post_id;
    271287    }
    272288
    273289    /**
    274      * Renders the view that displays the contents for the meta box that for triggering
     290     * Renders the view that displays the contents for the meta box that for triggering.
    275291     * the meta box.
    276292     *
    277      * @param    WP_Post    $post    The post object
    278      * @since    1.3
     293     * @param WP_Post $post The post object.
     294     * @since 1.3
    279295     */
    280296    public function display_custom_meta_image( $post ) {
    281297
    282         // Get required values
     298        // Get required values.
    283299        $attachment_id = $this->get_attachment_id( $post->ID, $this->name_underscores );
    284         $url = $this->get_attachment_src( $attachment_id );
    285         $title = $this->get_attachment_title( $attachment_id );
     300        $url           = $this->get_attachment_src( $attachment_id );
     301        $title         = $this->get_attachment_title( $attachment_id );
    286302
    287303        wp_nonce_field( $this->name, $this->name . '-nonce' );
     
    302318        <p id="<?php echo esc_attr( $this->name . '-info' ); ?>" class="custom-meta-image-info">
    303319            <input type="hidden" id="<?php echo esc_attr( $this->name . '-id' ); ?>" class="custom-meta-image-id" name="<?php echo esc_attr( $this->name . '-id' ); ?>" value="<?php echo esc_attr( $attachment_id ); ?>" />
    304         </p><!-- #<?php echo esc_attr( $this->name . '-image-info' ); ?> --><?php
     320        </p><!-- #<?php echo esc_attr( $this->name . '-image-info' ); ?> -->
     321        <?php
    305322
    306323        return $post;
  • unique-headers/trunk/inc/class-dotorg-plugin-review.php

    r2512906 r2981849  
    11<?php
     2/**
     3 * DotOrg_Plugin_Review Class File
     4 *
     5 * This file contains a class that prompts users to review a WordPress plugin
     6 * on WordPress.org after a specified period of usage.
     7 *
     8 * @package    Unique Headers
     9 * @version    1.0
     10 * @author     Ryan Hellyer <ryanhellyer@gmail.com>
     11 * @copyright  Copyright (c), Ryan Hellyer
     12 * @license    http://www.gnu.org/licenses/gpl.html GPL
     13 */
     14
     15// Bail out now if the class doesn't exist.
     16if ( class_exists( 'DotOrg_Plugin_Review' ) ) {
     17    return;
     18}
    219
    320/**
     
    1229 * @author Ryan Hellyer <ryanhellyer@gmail.com>
    1330 */
    14 if ( ! class_exists( 'DotOrg_Plugin_Review' ) ) :
    1531class DotOrg_Plugin_Review {
    1632
    1733    /**
    18      * Private variables.
    19      *
    20      * These should be customised for each project.
    21      */
    22     private $slug;        // The plugin slug
    23     private $name;        // The plugin name
    24     private $time_limit;  // The time limit at which notice is shown
    25 
    26     /**
    27      * Variables.
     34     * The plugin slug.
     35     *
     36     * @var string
     37     */
     38    private $slug;
     39
     40    /**
     41     * The plugin name.
     42     *
     43     * @var string
     44     */
     45    private $name;
     46
     47    /**
     48     * The time limit at which notice is shown.
     49     *
     50     * @var int
     51     */
     52    private $time_limit;
     53
     54    /**
     55     * No debug option.
     56     *
     57     * @var string
    2858     */
    2959    public $nobug_option;
     
    3161    /**
    3262     * Fire the constructor up :)
     63     *
     64     * @param array $args The arguments.
    3365     */
    3466    public function __construct( $args ) {
    3567
    36         $this->slug        = $args['slug'];
    37         $this->name        = $args['name'];
     68        $this->slug = $args['slug'];
     69        $this->name = $args['name'];
    3870        if ( isset( $args['time_limit'] ) ) {
    39             $this->time_limit  = $args['time_limit'];
     71            $this->time_limit = $args['time_limit'];
    4072        } else {
    4173            $this->time_limit = WEEK_IN_SECONDS;
     
    4476        $this->nobug_option = $this->slug . '-no-bug';
    4577
    46         // Loading main functionality
     78        // Loading main functionality.
    4779        add_action( 'admin_init', array( $this, 'check_installation_date' ) );
    4880        add_action( 'admin_init', array( $this, 'set_no_bug' ), 5 );
     
    5183    /**
    5284     * Seconds to words.
     85     *
     86     * @param int $seconds The number of seconds.
    5387     */
    5488    public function seconds_to_words( $seconds ) {
    5589
    56         // Get the years
    57         $years = ( intval( $seconds ) / YEAR_IN_SECONDS ) % 100;
     90        // Get the years.
     91        $years = round( $seconds / YEAR_IN_SECONDS ) % 100;
    5892        if ( $years > 1 ) {
     93            // translators: %s: Number of years.
    5994            return sprintf( __( '%s years', $this->slug ), $years );
    60         } elseif ( $years > 0) {
     95        } elseif ( $years > 0 ) {
    6196            return __( 'a year', $this->slug );
    6297        }
    6398
    64         // Get the weeks
    65         $weeks = ( intval( $seconds ) / WEEK_IN_SECONDS ) % 52;
     99        // Get the weeks.
     100        $weeks = round( $seconds / WEEK_IN_SECONDS ) % 52;
    66101        if ( $weeks > 1 ) {
     102            // translators: %s: Number of weeks.
    67103            return sprintf( __( '%s weeks', $this->slug ), $weeks );
    68         } elseif ( $weeks > 0) {
     104        } elseif ( $weeks > 0 ) {
    69105            return __( 'a week', $this->slug );
    70106        }
    71107
    72         // Get the days
    73         $days = ( intval( $seconds ) / DAY_IN_SECONDS ) % 7;
     108        // Get the days.
     109        $days = round( $seconds / DAY_IN_SECONDS ) % 7;
    74110        if ( $days > 1 ) {
     111            // translators: %s: Number of days.
    75112            return sprintf( __( '%s days', $this->slug ), $days );
    76         } elseif ( $days > 0) {
     113        } elseif ( $days > 0 ) {
    77114            return __( 'a day', $this->slug );
    78115        }
    79116
    80         // Get the hours
    81         $hours = ( intval( $seconds ) / HOUR_IN_SECONDS ) % 24;
     117        // Get the hours.
     118        $hours = round( $seconds / HOUR_IN_SECONDS ) % 24;
    82119        if ( $hours > 1 ) {
     120            // translators: %s: Number of hours.
    83121            return sprintf( __( '%s hours', $this->slug ), $hours );
    84         } elseif ( $hours > 0) {
     122        } elseif ( $hours > 0 ) {
    85123            return __( 'an hour', $this->slug );
    86124        }
    87125
    88         // Get the minutes
    89         $minutes = ( intval( $seconds ) / MINUTE_IN_SECONDS ) % 60;
     126        // Get the minutes.
     127        $minutes = round( $seconds / MINUTE_IN_SECONDS ) % 60;
    90128        if ( $minutes > 1 ) {
     129            // translators: %s: Number of minutes.
    91130            return sprintf( __( '%s minutes', $this->slug ), $minutes );
    92         } elseif ( $minutes > 0) {
     131        } elseif ( $minutes > 0 ) {
    93132            return __( 'a minute', $this->slug );
    94133        }
    95134
    96         // Get the seconds
    97         $seconds = intval( $seconds ) % 60;
     135        // Get the seconds.
     136        $seconds = round( $seconds ) % 60;
    98137        if ( $seconds > 1 ) {
     138            // translators: %s: Number of seconds.
    99139            return sprintf( __( '%s seconds', $this->slug ), $seconds );
    100         } elseif ( $seconds > 0) {
     140        } elseif ( $seconds > 0 ) {
    101141            return __( 'a second', $this->slug );
    102142        }
    103143
    104         return;
    105144    }
    106145
     
    110149    public function check_installation_date() {
    111150
    112         if ( true != get_site_option( $this->nobug_option ) ) {
    113 
    114             // If not installation date set, then add it
     151        if ( true !== get_site_option( $this->nobug_option ) ) {
     152
     153            // If not installation date set, then add it.
    115154            $install_date = get_site_option( $this->slug . '-activation-date' );
    116             if ( '' == $install_date ) {
     155            if ( '' === $install_date ) {
    117156                add_site_option( $this->slug . '-activation-date', time() );
    118157            }
    119158
    120             // If difference between install date and now is greater than time limit, then display notice
    121             if ( ( time() - $install_date ) >  $this->time_limit  ) {
     159            // If difference between install date and now is greater than time limit, then display notice.
     160            $gap = time() - $install_date;
     161            if ( $gap > $this->time_limit ) {
    122162                add_action( 'admin_notices', array( $this, 'display_admin_notice' ) );
    123163            }
    124 
    125164        }
    126165
     
    132171    public function display_admin_notice() {
    133172
    134         $screen = get_current_screen(); 
    135         if ( isset( $screen->base ) && 'plugins' == $screen->base ) {
     173        $screen = get_current_screen();
     174        if ( isset( $screen->base ) && 'plugins' === $screen->base ) {
    136175
    137176            $no_bug_url = wp_nonce_url( admin_url( '?' . $this->nobug_option . '=true' ), 'review-nonce' );
    138             $time = $this->seconds_to_words( time() - get_site_option( $this->slug . '-activation-date' ) );
     177            $time       = $this->seconds_to_words( time() - get_site_option( $this->slug . '-activation-date' ) );
    139178
    140179            echo '
    141             <div class="updated">
    142                 <p>' . sprintf( __( 'You have been using the %s plugin for %s now, do you like it? If so, please leave us a review with your feedback!', 'spam-destroyer' ), $this->name, $time ) . '
    143                     <br /><br />
    144                     <a onclick="location.href=\'' . esc_url( $no_bug_url ) . '\';" class="button button-primary" href="' . esc_url( 'https://wordpress.org/support/view/plugin-reviews/' . $this->slug . '#postform' ) . '" target="_blank">' . __( 'Leave A Review', 'spam-destroyer' ) . '</a>
    145                        
    146                     <a href="' . esc_url( $no_bug_url ) . '">' . __( 'No thanks.', 'spam-destroyer' ) . '</a>
    147                 </p>
    148             </div>';
     180        <div class="updated">
     181            <p>' .
     182            sprintf(
     183                /* translators: 1: Plugin name, 2: Time duration */
     184                esc_html__( 'You have been using the %1$s plugin for %2$s now, do you like it? If so, please leave us a review with your feedback!', 'spam-destroyer' ),
     185                esc_html( $this->name ),
     186                esc_html( $time )
     187            ) .
     188            '<br /><br />
     189            <a onclick="location.href=\'' . esc_url( $no_bug_url ) . '\';" class="button button-primary" href="' . esc_url( 'https://wordpress.org/support/view/plugin-reviews/' . $this->slug . '#postform' ) . '" target="_blank">' . esc_html__( 'Leave A Review', 'spam-destroyer' ) . '</a>
     190            <a href="' . esc_url( $no_bug_url ) . '">' . esc_html__( 'No thanks.', 'spam-destroyer' ) . '</a>
     191            </p>
     192        </div>';
    149193
    150194        }
     
    157201    public function set_no_bug() {
    158202
    159         // Bail out if not on correct page
     203        // Bail out if not on correct page.
    160204        if (
    161             ! isset( $_GET['_wpnonce'] )
     205        ! isset( $_GET['_wpnonce'] )
     206        ||
     207        (
     208            ! wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), 'review-nonce' )
    162209            ||
    163             (
    164                 ! wp_verify_nonce( $_GET['_wpnonce'], 'review-nonce' )
    165                 ||
    166                 ! is_admin()
    167                 ||
    168                 ! isset( $_GET[$this->nobug_option] )
    169                 ||
    170                 ! current_user_can( 'manage_options' )
    171             )
     210            ! is_admin()
     211            ||
     212            ! isset( $_GET[ $this->nobug_option ] )
     213            ||
     214            ! current_user_can( 'manage_options' )
     215        )
    172216        ) {
    173217            return;
     
    179223
    180224}
    181 endif;
  • unique-headers/trunk/inc/class-unique-headers-core.php

    r2512906 r2981849  
    11<?php
     2/**
     3 * Core class for Unique Headers extension.
     4 *
     5 * This class provides the core functionality for the Unique Headers extension,
     6 * including methods for filtering header image srcset values.
     7 *
     8 * @package    Unique_Headers
     9 * @subpackage Core
     10 * @author     Ryan Hellyer <ryanhellyer@gmail.com>
     11 * @copyright  Copyright (c), Ryan Hellyer
     12 * @license    http://www.gnu.org/licenses/gpl.html GPL
     13 * @version    1.7.3
     14 */
    215
    316/**
     
    1023 */
    1124class Unique_Headers_Core {
    12 
    13     /*
     25    /**
    1426     * Filter for modifying the srcset values.
    1527     * This is required for when the srcset attribute is used within the header.
     
    1729     * @since 1.7
    1830     *
    19      * @param    string     $srcset        The new array of URLs
    20      * @param    array      $size_array    Array of width and height values in pixels (in that order).
    21      * @param    string    $image_src     The 'src' of the image.
    22      * @param    array      $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
    23      * @param    int        $attachment_id Optional. The image attachment ID to pass to the filter. Default 0.
     31     * @param string $srcset        The new array of URLs.
     32     * @param array  $size_array    Array of width and height values in pixels (in that order).
     33     * @param string $image_src     The 'src' of the image.
     34     * @param array  $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
     35     * @param int    $attachment_id Optional. The image attachment ID to pass to the filter. Default 0.
    2436     *
    25      * @return   string    $srcset    The new array of URLs
     37     * @return string $srcset    The new array of URLs
    2638     */
    2739    public function header_srcset_filter( $srcset, $size_array, $image_src, $image_meta, $attachment_id = 0 ) {
    2840
    29         // Bail out if not on header ID
     41        // Bail out if not on header ID.
    3042        if (
    3143            ! isset( get_custom_header()->attachment_id )
    3244            ||
    33             $attachment_id != get_custom_header()->attachment_id
     45            get_custom_header()->attachment_id !== $attachment_id
    3446        ) {
    3547            return $srcset;
    3648        }
    3749
    38         // Changing each URL within the set
     50        // Changing each URL within the set.
    3951        if ( is_array( $srcset ) ) {
    40             foreach( $srcset as $size => $set ) {
     52            foreach ( $srcset as $size => $set ) {
    4153                $srcset[ $size ]['url'] = $this->header_image_filter( $srcset[ $size ]['url'] );
    4254            }
  • unique-headers/trunk/inc/class-unique-headers-display.php

    r2512906 r2981849  
    11<?php
     2/**
     3 * Custom Image Meta Box Display Class.
     4 *
     5 * This class extends the Unique_Headers_Core class and provides methods
     6 * for displaying and modifying custom header images on single posts, pages,
     7 * and the blog homepage.
     8 *
     9 * @package    Unique_Headers
     10 * @subpackage Display
     11 * @author     Ryan Hellyer <ryanhellyer@gmail.com>
     12 * @copyright  Copyright (c), Ryan Hellyer
     13 * @license    http://www.gnu.org/licenses/gpl.html GPL
     14 * @version    1.3
     15 */
    216
    317/**
     
    3347     * Class constructor
    3448     * Adds methods to appropriate hooks
    35      *
     49     *
     50     * @param array $args The arguments.
    3651     * @since 1.3
    3752     */
    3853    public function __construct( $args ) {
    3954
    40         $this->name_underscores    = str_replace( '-', '_', $args['name'] );
     55        $this->name_underscores = str_replace( '-', '_', $args['name'] );
    4156
    42         // Add filter for post header image (uses increased priority to ensure that single post thumbnails aren't overridden by category images)
    43         add_filter( 'theme_mod_header_image',      array( $this, 'header_image_filter' ), 20 );
    44         add_filter( 'wp_calculate_image_srcset',   array( $this, 'header_srcset_filter' ), 20, 5 );
    45         add_filter( 'theme_mod_header_image_data', array( $this, 'modify_header_image_data' ) );   
     57        // Add filter for post header image (uses increased priority to ensure that single post thumbnails aren't overridden by category images).
     58        add_filter( 'theme_mod_header_image', array( $this, 'header_image_filter' ), 20 );
     59        add_filter( 'wp_calculate_image_srcset', array( $this, 'header_srcset_filter' ), 20, 5 );
     60        add_filter( 'theme_mod_header_image_data', array( $this, 'modify_header_image_data' ) );
    4661
    4762    }
    4863
    49     /*
     64    /**
    5065     * Filter for modifying the output of get_header()
    5166     *
    5267     * @since 1.3
    53      * @param    string     $url         The header image URL
    54      * @return   string     $custom_url The new custom header image URL
     68     * @param string $url The header image URL.
     69     * @return string $custom_url The new custom header image URL
    5570     */
    5671    public function header_image_filter( $url ) {
    5772
    58         // Bail out now if not in post (is_single or is_page) or blog (is_home)
     73        // Bail out now if not in post (is_single or is_page) or blog (is_home).
    5974        if ( ! is_single() && ! is_page() && ! is_home() ) {
    6075            return $url;
    6176        }
    6277
    63         // Get current post ID (if on blog, then checks current posts page for it's ID)
     78        // Get current post ID (if on blog, then checks current posts page for it's ID).
    6479        if ( is_home() ) {
    6580            $post_id = get_option( 'page_for_posts' );
     
    6883        }
    6984
    70         // Get attachment ID
     85        // Get attachment ID.
    7186        $attachment_id = Custom_Image_Meta_Box::get_attachment_id( $post_id, $this->name_underscores );
    7287
    73         // Generate new URL
     88        // Generate new URL.
    7489        if ( is_numeric( $attachment_id ) ) {
    7590            $url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
     
    8499     * This is a replica of the method in Unique_Headers_Taxonomy_Header_Images().
    85100     *
    86      * @param   array   $data   The data
    87      * @return  array  The modified data with new attachment ID
     101     * @param array $data The data.
     102     * @return array The modified data with new attachment ID
    88103     */
    89104    public function modify_header_image_data( $data ) {
    90105
    91         // Bail out now if not in post (is_single or is_page) or blog (is_home)
     106        // Bail out now if not in post (is_single or is_page) or blog (is_home).
    92107        if ( ! is_single() && ! is_page() && ! is_home() ) {
    93108            return $data;
    94109        }
    95110
    96         // Get current post ID (if on blog, then checks current posts page for it's ID)
     111        // Get current post ID (if on blog, then checks current posts page for it's ID).
    97112        if ( is_home() ) {
    98113            $post_id = get_option( 'page_for_posts' );
     
    101116        }
    102117
    103         // Get attachment ID
     118        // Get attachment ID.
    104119        $attachment_id = Custom_Image_Meta_Box::get_attachment_id( $post_id, $this->name_underscores );
    105120
    106         // Set new data based on new header image attachment ID
     121        // Set new data based on new header image attachment ID.
    107122        if ( is_numeric( $attachment_id ) ) {
    108123
    109             // Create object
    110             if ( null == $data ) {
     124            // Create object.
     125            if ( null === $data ) {
    111126                $data = (object) null;
    112127            }
     
    114129            if ( is_object( $data ) ) {
    115130                $data->attachment_id = $attachment_id;
    116                 $data->width = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'width' );
    117                 $data->height = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'height' );
     131                $data->width         = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'width' );
     132                $data->height        = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'height' );
    118133            }
     134        }
    119135
    120         }
    121    
    122136        return $data;
    123137    }
  • unique-headers/trunk/inc/class-unique-headers-instantiate.php

    r2512906 r2981849  
    11<?php
     2/**
     3 * Unique Headers Instantiation Class.
     4 *
     5 * This class is responsible for instantiating other classes and setting up hooks.
     6 * It handles the localization, includes necessary files, and initializes other classes
     7 * based on the context (admin or front-end).
     8 *
     9 * @package    Unique_Headers
     10 * @subpackage Instantiate
     11 * @author     Ryan Hellyer <ryanhellyer@gmail.com>
     12 * @copyright  Copyright (c), Ryan Hellyer
     13 * @license    http://www.gnu.org/licenses/gpl.html GPL
     14 * @version    1.3.10
     15 */
    216
    317/**
     
    1428     * Class constructor
    1529     * Adds methods to appropriate hooks
    16      * 
     30     *
    1731     * @since 1.3.10
    1832     */
    1933    public function __construct() {
    2034
    21         // Load classes
    22         require( 'class-custom-image-meta-box.php' );
    23         require( 'legacy.php' );
     35        // Load classes.
     36        require 'class-custom-image-meta-box.php';
     37        require 'legacy.php';
    2438
    25         // Loading dotorg plugin review code
     39        // Loading dotorg plugin review code.
    2640        if ( is_admin() ) {
    27             require( 'class-dotorg-plugin-review.php' );
     41            require 'class-dotorg-plugin-review.php';
    2842            new DotOrg_Plugin_Review(
    2943                array(
    30                     'slug'        => 'unique-headers', // The plugin slug
    31                     'name'        => 'Unique Headers', // The plugin name
    32                     'time_limit'  => WEEK_IN_SECONDS,  // The time limit at which notice is shown
     44                    'slug'       => 'unique-headers', // The plugin slug.
     45                    'name'       => 'Unique Headers', // The plugin name.
     46                    'time_limit' => WEEK_IN_SECONDS,  // The time limit at which notice is shown.
    3347                )
    3448            );
    3549        }
    3650
    37         // Add hooks
     51        // Add hooks.
    3852        add_action( 'plugins_loaded', array( $this, 'localization' ), 5 );
    3953        add_action( 'init', array( $this, 'instantiate_classes' ), 20 );
     
    4256    /**
    4357     * Instantiate classes
    44      * 
     58     *
    4559     * @since 1.3
    4660     */
    4761    public function instantiate_classes() {
    4862
    49         $name = 'custom-header-image'; // This says "custom-header" instead of "unique-header" to ensure compatibilty with Justin Tadlock's Custom Header Extended plugin which originally used a different post meta key value than the Unique Headers plugin
     63        $name = 'custom-header-image'; // This says "custom-header" instead of "unique-header" to ensure compatibilty with Justin Tadlock's Custom Header Extended plugin which originally used a different post meta key value than the Unique Headers plugin.
    5064        $args = array(
    5165            'name'                => $name,
     
    5771        );
    5872
    59         // Add support for post-types
     73        // Add support for post-types.
    6074        if ( is_admin() ) {
    6175            new Custom_Image_Meta_Box( $args );
     
    6478        }
    6579
    66         // Add support for taxonomies (this conditional can be removed after the release of WordPress 4.4 - plus the taxonmies argument above can be moved into the main array then)
     80        // Add support for taxonomies (this conditional can be removed after the release of WordPress 4.4 - plus the taxonmies argument above can be moved into the main array then).
    6781        if ( function_exists( 'get_term_meta' ) ) {
    6882
    69             // Add support for publicly available taxonomies - this can be moved into the main arguments array above after the release of WordPress 4.4
    70             $args['taxonomies'] = get_taxonomies( array( 'public'=>true ) );
     83            // Add support for publicly available taxonomies - this can be moved into the main arguments array above after the release of WordPress 4.4.
     84            $args['taxonomies'] = get_taxonomies( array( 'public' => true ) );
    7185
    72             // Add upload text
     86            // Add upload text.
    7387            $args['upload_header_image'] = __( 'Upload header image', 'unique-headers' );
    7488
     
    7892    }
    7993
    80     /*
     94    /**
    8195     * Setup localization for translations
    8296     *
     
    8599    public function localization() {
    86100
    87         // Localization
     101        // Localization.
    88102        load_plugin_textdomain(
    89             'unique-headers', // Unique identifier
    90             false, // Deprecated abs path
    91             dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Languages folder
     103            'unique-headers', // Unique identifier.
     104            '', // Deprecated abs path.
     105            dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Languages folder.
    92106        );
    93107
  • unique-headers/trunk/inc/class-unique-headers-taxonomy-header-images.php

    r2512906 r2981849  
    11<?php
     2/**
     3 * Unique_Headers_Taxonomy_Header_Images Class File
     4 *
     5 * This class provides methods for adding and managing custom header images
     6 * for different taxonomies.
     7 *
     8 * @package    UniqueHeaders
     9 * @subpackage TaxonomyHeaderImages
     10 * @copyright  Copyright (c), Ryan Hellyer
     11 * @license    http://www.gnu.org/licenses/gpl.html GPL
     12 * @author     Ryan Hellyer <ryanhellyer@gmail.com>
     13 * @since      1.0
     14 */
    215
    316/**
     
    1528     *
    1629     * @since 1.3
    17      * @access   private
    18      * @var      string    $name
     30     * @access private
     31     * @var string $name
    1932     */
    2033    private $name;
     
    2538     *
    2639     * @since 1.3
    27      * @access   private
    28      * @var      string    $name_underscores
     40     * @access private
     41     * @var string $name_underscores
    2942     */
    3043    private $name_underscores;
     
    3447     *
    3548     * @since 1.3
    36      * @access   private
    37      * @var      string    $title
     49     * @access private
     50     * @var string $title
    3851     */
    3952    private $title;
     
    4356     *
    4457     * @since 1.3
    45      * @access   private
    46      * @var      string    $set_custom_image
     58     * @access private
     59     * @var string $set_custom_image
    4760     */
    4861    private $set_custom_image;
     
    5265     *
    5366     * @since 1.3
    54      * @access   private
    55      * @var      string    $remove_custom_image
     67     * @access private
     68     * @var string $remove_custom_image
    5669     */
    5770    private $remove_custom_image;
     
    6174     *
    6275     * @since 1.3
    63      * @access   private
    64      * @var      string    $taxonomies
     76     * @access private
     77     * @var string $taxonomies
    6578     */
    6679    private $taxonomies;
     
    7083     *
    7184     * @since 1.3
    72      * @access   private
    73      * @var      string    $upload_header_image
     85     * @access private
     86     * @var string $upload_header_image
    7487     */
    7588    private $upload_header_image;
     
    7790    /**
    7891     * Class constructor
    79      * 
     92     *
    8093     * Adds methods to appropriate hooks
    81      * 
     94     *
    8295     * @author Ryan Hellyer <ryanhellyer@gmail.com>
    8396     * @since 1.0
     97     * @param array $args The arguments.
    8498     */
    8599    public function __construct( $args ) {
     
    93107        $this->upload_header_image = $args['upload_header_image'];
    94108
    95         add_action( 'admin_init',                  array( $this, 'add_fields' ) );
    96         add_filter( 'theme_mod_header_image',      array( $this, 'header_image_filter' ), 5 );
    97         add_filter( 'wp_calculate_image_srcset',   array( $this, 'header_srcset_filter' ), 20, 5 );
    98         add_filter( 'theme_mod_header_image_data', array( $this, 'modify_header_image_data' ) );   
     109        add_action( 'admin_init', array( $this, 'add_fields' ) );
     110        add_filter( 'theme_mod_header_image', array( $this, 'header_image_filter' ), 5 );
     111        add_filter( 'wp_calculate_image_srcset', array( $this, 'header_srcset_filter' ), 20, 5 );
     112        add_filter( 'theme_mod_header_image_data', array( $this, 'modify_header_image_data' ) );
    99113
    100114    }
     
    108122    public function add_fields() {
    109123
    110         // Add actions for administration pages
     124        // Add actions for administration pages.
    111125        if ( is_admin() ) {
    112126
    113             // Add hooks for each taxonomy
    114             foreach( $this->taxonomies as $taxonomy ) {
     127            // Add hooks for each taxonomy.
     128            foreach ( $this->taxonomies as $taxonomy ) {
    115129                add_action( $taxonomy . '_edit_form_fields', array( $this, 'extra_fields' ), 1 );
    116                 add_action( 'edit_' . $taxonomy,             array( $this, 'storing_taxonomy_data' ) );
    117             }
    118 
    119         }
    120 
    121     }
    122 
    123     /*
     130                add_action( 'edit_' . $taxonomy, array( $this, 'storing_taxonomy_data' ) );
     131            }
     132        }
     133
     134    }
     135
     136    /**
    124137     * Filter for modifying the output of get_header()
    125138     *
    126139     * @author Ryan Hellyer <ryanhellyer@gmail.com>
    127140     * @since 1.0
     141     * @param string $url The URL.
    128142     */
    129143    public function header_image_filter( $url ) {
    130 
    131         /* We need to grab the current taxonomy ID
     144        /*
     145         * We need to grab the current taxonomy ID
    132146         * Unfortunately, categories and post tags behave different, so we
    133          * are checking for their presense and processing them slightly 
     147         * are checking for their presense and processing them slightly
    134148         * differently.
    135149         */
    136150        if ( is_category() ) {
    137             $tax_ID = get_query_var( 'cat' );
    138         } elseif( is_tag() || is_tax() ) {
    139 
    140             // Now we can loop through all taxonomies
    141             foreach( $this->taxonomies as $taxonomy ) {
    142 
    143                 // We need to ignore categories since we have already processed them               
    144                 if ( 'category' != $taxonomy ) {
    145 
    146                     // Tags behave oddly, so need to use a different query var accordingly
    147                     if ( 'post_tag' == $taxonomy ) {
     151            $tax_id = get_query_var( 'cat' );
     152        } elseif ( is_tag() || is_tax() ) {
     153
     154            // Now we can loop through all taxonomies.
     155            foreach ( $this->taxonomies as $taxonomy ) {
     156
     157                // We need to ignore categories since we have already processed them.
     158                if ( 'category' !== $taxonomy ) {
     159
     160                    // Tags behave oddly, so need to use a different query var accordingly.
     161                    if ( 'post_tag' === $taxonomy ) {
    148162                        $tax_info = get_query_var( 'tag' );
    149163                    } else {
     
    153167                    $tax = get_term_by( 'slug', $tax_info, $taxonomy );
    154168                    if ( isset( $tax->term_id ) ) {
    155                         $tax_ID = $tax->term_id;
     169                        $tax_id = $tax->term_id;
    156170                    }
    157171                }
     
    159173        }
    160174
    161 
    162         // Bail out now if no term set
    163         if ( ! isset( $tax_ID ) ) {
     175        // Bail out now if no term set.
     176        if ( ! isset( $tax_id ) ) {
    164177            return $url;
    165178        }
    166179
    167         // Grab stored taxonomy header
    168         $attachment_id = get_term_meta( $tax_ID, 'taxonomy-header-image', true );
    169 
    170         // Grab attachment's SRC if we have an ID, otherwise fallback to legacy support for the older URL system from earlier versions of the plugin
     180        // Grab stored taxonomy header.
     181        $attachment_id = get_term_meta( $tax_id, 'taxonomy-header-image', true );
     182
     183        // Grab attachment's SRC if we have an ID, otherwise fallback to legacy support for the older URL system from earlier versions of the plugin.
    171184        if ( is_numeric( $attachment_id ) ) {
    172185            $new_url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
    173186        } else {
    174187
    175             // Falling back to taxonomy meta plugin functionality
    176             $attachment_id = get_metadata( 'taxonomy', $tax_ID, 'taxonomy-header-image', true );
     188            // Falling back to taxonomy meta plugin functionality.
     189            $attachment_id = get_metadata( 'taxonomy', $tax_id, 'taxonomy-header-image', true );
    177190
    178191            if ( is_numeric( $attachment_id ) ) {
    179192                $new_url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
    180193            } else {
    181                 $new_url = $attachment_id; // Defaulting back to really old version of the plugin which used URL's insteaded of attachment ID's
    182             }
    183 
    184         }
    185 
    186         // Only use new URL if it isn't blank ...
    187         if ( '' != $new_url ) {
     194                $new_url = $attachment_id; // Defaulting back to really old version of the plugin which used URL's insteaded of attachment ID's.
     195            }
     196        }
     197
     198        // Only use new URL if it isn't blank ...
     199        if ( '' !== $new_url ) {
    188200            $url = esc_url( $new_url );
    189201        }
    190202
    191         return $url; // Do not escape here, as WordPress sometimes assigns non-URLs for the header image
     203        return $url; // Do not escape here, as WordPress sometimes assigns non-URLs for the header image.
    192204    }
    193205
    194206    /**
    195207     * Storing the taxonomy header image selection
    196      * 
     208     *
    197209     * @author Ryan Hellyer <ryanhellyer@gmail.com>
    198210     * @since 1.0
     
    200212    public function storing_taxonomy_data() {
    201213
    202         // Bail out now if POST vars not set
    203         if ( ! isset( $_POST[$this->name . '-nonce'] ) || ! isset( $_POST[$this->name . '-id'] ) ) {
     214        // Bail out now if POST vars not set.
     215        if ( ! isset( $_POST[ $this->name . '-nonce' ] ) || ! isset( $_POST[ $this->name . '-id' ] ) ) {
    204216            return;
    205217        }
    206218
    207         // Bail out now if nonce doesn't verify
    208         if ( ! wp_verify_nonce( $_POST[$this->name . '-nonce'], $this->name ) ) {
     219        // Bail out now if nonce doesn't verify.
     220        $nonce = sanitize_key( wp_unslash( $_POST[ $this->name . '-nonce' ] ) );
     221        if ( ! wp_verify_nonce( $nonce ) ) {
    209222            return;
    210223        }
    211224
    212         // Sanitize inputs
    213         $tag_ID = absint( $_POST['tag_ID'] );
    214         $attachment_id = $_POST[$this->name . '-id'];
     225        // Sanitize inputs.
     226        if ( ! isset( $_POST['tag_ID'] ) ) {
     227            return;
     228        }
     229        $tag_ID        = absint( wp_unslash( $_POST['tag_ID'] ) );
     230        $attachment_id = absint( wp_unslash( $_POST[ $this->name . '-id' ] ) );
    215231        if ( is_numeric( $attachment_id ) ) {
    216232            $attachment_id = absint( $attachment_id );
     
    218234            $attachment_id = $this->get_attachment_id_from_url( $attachment_id );
    219235
    220             // If still a string, then give up and treat it as a URL
     236            // If still a string, then give up and treat it as a URL.
    221237            if ( ! is_numeric( $attachment_id ) ) {
    222238                $attachment_id = esc_url( $attachment_id );
     
    224240        }
    225241
    226         // Save the term meta data
     242        // Save the term meta data.
    227243        update_term_meta( $tag_ID, 'taxonomy-header-image', $attachment_id );
    228244    }
    229245
    230     /*
     246    /**
    231247     * Legacy method
    232248     * Used to obtain the attachment ID, if a URL is detected
    233      * 
     249     *
    234250     * URL's were used in earlier versions of the plugin. This was upgraded
    235251     * for version 1.3 to utilize attachment ID's instead. These older URL's
     
    240256     * https://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/
    241257     *
    242      * @global   object    $wpdb            The WordPress database object
    243      * @param    string    $url             The URL we are trying to find the attachment ID for
    244      * @return   int       $attachment_id  The attachment ID for the input URL
     258     * @global object $wpdb The WordPress database object.
     259     * @param string $url The URL we are trying to find the attachment ID for.
     260     * @return int $attachment_id The attachment ID for the input URL
    245261     */
    246262    private function get_attachment_id_from_url( $url = '' ) {
     
    248264        $attachment_id = false;
    249265
    250         // If there is no url, return false
    251         if ( '' == $url ) {
     266        // If there is no url, return false.
     267        if ( '' === $url ) {
    252268            return false;
    253269        }
    254270
    255         // Get the upload directory paths
     271        // Get the upload directory paths.
    256272        $upload_dir_paths = wp_upload_dir();
    257273
    258         // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
     274        // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image.
    259275        if ( false !== strpos( $url, $upload_dir_paths['baseurl'] ) ) {
    260276
    261             // If this is the URL of an auto-generated thumbnail, get the URL of the original image
     277            // If this is the URL of an auto-generated thumbnail, get the URL of the original image.
    262278            $url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $url );
    263279
    264             // Remove the upload path base directory from the attachment URL
     280            // Remove the upload path base directory from the attachment URL.
    265281            $url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $url );
    266282
    267             // Finally, run a custom database query to get the attachment ID from the modified attachment URL
    268             $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $url ) );
    269 
    270         }
    271 
    272         if ( false == $attachment_id ) {
     283            // Finally, run a custom database query to get the attachment ID from the modified attachment URL.
     284            $cache_key     = 'unique_header_query_' . md5( $url );
     285            $attachment_id = wp_cache_get( $cache_key );
     286            if ( false === $attachment_id ) {
     287                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
     288                $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = %s AND wposts.post_type = 'attachment'", $url ) );
     289                wp_cache_set( $cache_key, $attachment_id );
     290            }
     291        }
     292
     293        if ( false === $attachment_id ) {
    273294            return $url;
    274295        }
     
    279300    /**
    280301     * Extra fields
    281      * 
     302     *
    282303     * @author Ryan Hellyer <ryanhellyer@gmail.com>
    283304     * @since 1.0
     
    285306    public function extra_fields() {
    286307
    287         $tag_ID = absint( $_GET['tag_ID'] );
     308        $tag_ID        = absint( filter_input( INPUT_GET, 'tag_ID' ) );
    288309        $attachment_id = get_term_meta( $tag_ID, 'taxonomy-header-image', true );
    289310
    290         // We need to cater for legacy URL's as well as the newer attachment ID's
     311        // We need to cater for legacy URL's as well as the newer attachment ID's.
    291312        if ( is_numeric( $attachment_id ) ) {
    292             $url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
     313            $url   = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
    293314            $title = Custom_Image_Meta_Box::get_attachment_title( $attachment_id );
    294315        } else {
    295316
    296             // Falling back to taxonomy meta plugin functionality
     317            // Falling back to taxonomy meta plugin functionality.
    297318            $attachment_id = get_metadata( 'taxonomy', $tag_ID, 'taxonomy-header-image', true );
    298319            if ( is_numeric( $attachment_id ) ) {
    299                 $url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
     320                $url   = Custom_Image_Meta_Box::get_attachment_src( $attachment_id );
    300321                $title = Custom_Image_Meta_Box::get_attachment_title( $attachment_id );
    301322            } elseif ( is_string( $attachment_id ) ) {
    302                 $url = $attachment_id; // The attachment ID is actually the URL
    303                 $title = ''; // We don't know the title since it's an attachment
    304             }
    305 
     323                $url   = $attachment_id; // The attachment ID is actually the URL.
     324                $title = ''; // We don't know the title since it's an attachment.
     325            }
    306326        }
    307327
     
    337357        <?php
    338358
    339 
    340359    }
    341360
     
    345364     * This is similar to the method in Unique_Headers_Display().
    346365     *
    347      * @param   array   $data   The data
    348      * @return  array  The modified data with new attachment ID
     366     * @param array $data The data.
     367     * @return array The modified data with new attachment ID
    349368     */
    350369    public function modify_header_image_data( $data ) {
    351370
    352         // Bail out now if not in taxonomy archive
     371        // Bail out now if not in taxonomy archive.
    353372        if ( ! is_tag() && ! is_tax() && ! is_category() ) {
    354373            return $data;
    355374        }
    356375
    357         // Get current post ID (if on blog, then checks current posts page for it's ID)
     376        // Get current post ID (if on blog, then checks current posts page for it's ID).
    358377        if ( is_home() ) {
    359378            $post_id = get_option( 'page_for_posts' );
     
    362381        }
    363382
    364         // Get attachment ID
     383        // Get attachment ID.
    365384        $attachment_id = Custom_Image_Meta_Box::get_attachment_id( $post_id, $this->name_underscores );
    366385
    367         // Set new data based on new header image attachment ID
     386        // Set new data based on new header image attachment ID.
    368387        if ( is_numeric( $attachment_id ) ) {
    369388
    370             // Create object
    371             if ( null == $data || empty( $data ) ) {
     389            // Create object.
     390            if ( null === $data || empty( $data ) ) {
    372391                $data = (object) null;
    373392            }
    374393
    375             if ( is_object ( $data ) ) {
     394            if ( is_object( $data ) ) {
    376395                $data->attachment_id = $attachment_id;
    377                 $data->width = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'width' );
    378                 $data->height = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'height' );
    379             }
    380 
     396                $data->width         = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'width' );
     397                $data->height        = Custom_Image_Meta_Box::get_attachment_dimensions( $attachment_id, 'height' );
     398            }
    381399        }
    382400
  • unique-headers/trunk/inc/legacy.php

    r2512906 r2981849  
    11<?php
     2/**
     3 * Provides fallbacks and fixes for Unique Headers plugin.
     4 *
     5 * This file contains functions that provide backwards compatibility
     6 * for older versions of the Unique Headers plugin. It also includes
     7 * a quick touchup for the WordPress database object.
     8 *
     9 * @package   Unique_Headers
     10 * @copyright Copyright (c), Ryan Hellyer
     11 * @license   http://www.gnu.org/licenses/gpl.html GPL
     12 * @author    Ryan Hellyer <ryanhellyer@gmail.com>
     13 * @since     1.6.1
     14 */
    215
    316/**
    417 * Do not continue processing since file was called directly
    5  * 
     18 *
    619 * @since 1.6.1
    720 * @author Ryan Hellyer <ryanhellyer@gmail.com>
     
    1124}
    1225
    13 /*
     26/**
    1427 * Legacy fallback for old images
    1528 *
     
    1932 * Future versions of the Unique Headers plugin will phase out this legacy code
    2033 *
    21  * Any old images found, are updated to use the new meta key, to improve performance and avoid 
     34 * Any old images found, are updated to use the new meta key, to improve performance and avoid
    2235 * this function being required in future versions.
    2336 *
    2437 * @since 1.3
    25  * @param   int    $post_id          The current post ID
    26  * @param   int    $attachment_id    The attachment ID
     38 * @param int $post_id The current post ID.
    2739 */
    2840function unique_header_fallback_images( $post_id ) {
    2941    $attachment_id = '';
    3042
    31     // Loop through the legacy meta keys, looking for header images
     43    // Loop through the legacy meta keys, looking for header images.
    3244    $keys = array(
    3345        'post_custom-header_thumbnail_id',
     
    3547        'kd_custom-header_post_id',
    3648        'kd_custom-header_page_id',
    37         '_unique_header_id', // This is due to version 1.3.8 which shouldn't have been released
    38         '_custom_header_image', // temporary
     49        '_unique_header_id', // This is due to version 1.3.8 which shouldn't have been released.
     50        '_custom_header_image', // temporary.
    3951    );
    4052
    41     foreach( $keys as $key ) {
    42         if ( '' == $attachment_id ) {
     53    foreach ( $keys as $key ) {
     54        if ( '' === $attachment_id ) {
    4355            $attachment_id = get_post_meta( $post_id, $key, true );
    44             if ( '' != $attachment_id ) {
    45                 $keys_to_remove[] = $key; // Create list of keys which need deleted
     56            if ( '' !== $attachment_id ) {
     57                $keys_to_remove[] = $key; // Create list of keys which need deleted.
    4658            }
    4759        }
    4860    }
    4961
    50     // If no attachment found, then return false. Otherwise, convert the data to the new format and delete old keys
    51     if ( '' == $attachment_id ) {
     62    // If no attachment found, then return false. Otherwise, convert the data to the new format and delete old keys.
     63    if ( '' === $attachment_id ) {
    5264        return false;
    5365    } else {
    5466
    55         // Update to use new meta key
     67        // Update to use new meta key.
    5668        update_post_meta( $post_id, '_custom_header_image_id', $attachment_id );
    5769
    58         // Delete unused meta keys
    59         foreach( $keys_to_remove as $key ) {
     70        // Delete unused meta keys.
     71        foreach ( $keys_to_remove as $key ) {
    6072            delete_post_meta( $post_id, $key );
    6173        }
     
    6678add_filter( 'unique_header_fallback_images', 'unique_header_fallback_images' );
    6779
    68 /*
     80/**
    6981 * Quick touchup to wpdb.
    7082 * This is a throwback to the taxonomy meta data plugin.
    7183 * Once that plugin has been upgraded and migrated users taxonomy data over, this function will not longer be required.
    7284 *
    73  * @global  object  $wpdb The main WordPress database object
     85 * @global object $wpdb The main WordPress database object
    7486 */
    7587function unique_header_wpdbfix() {
    7688
    77     // Bail out now if Taxonomy Metadata plugin not installed
     89    // Bail out now if Taxonomy Metadata plugin not installed.
    7890    if ( ! class_exists( 'Taxonomy_Metadata' ) ) {
    7991        return;
  • unique-headers/trunk/index.php

    r2967092 r2981849  
    11<?php
    2 /*
     2/**
    33Plugin Name: Unique Headers
    44Plugin URI: https://geek.hellyer.kiwi/plugins/unique-headers/
    55Description: Unique Headers
    6 Version: 1.8.3
     6Version: 1.9
    77Author: Ryan Hellyer
    88Author URI: https://geek.hellyer.kiwi/
     
    2727Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    2828
    29 */
    30 
     29@package unique-headers
     30 */
    3131
    3232/**
    3333 * Do not continue processing since file was called directly
    34  * 
     34 *
    3535 * @since 1.0
    3636 * @author Ryan Hellyer <ryanhellyer@gmail.com>
     
    4545 * Includes the classes, and automatically instantiates them via spl_autoload_register().
    4646 *
    47  * @param  string  $class  The class being instantiated
     47 * @param string $class The class being instantiated.
    4848 */
    4949function autoload_unique_headers( $class ) {
    5050
    51     // Bail out if not loading a Media Manager class
    52     if ( 'Unique_Headers_' != substr( $class, 0, 15 ) ) {
     51    // Bail out if not loading a Media Manager class.
     52    if ( 'Unique_Headers_' !== substr( $class, 0, 15 ) ) {
    5353        return;
    5454    }
    5555
    56     // Convert from the class name, to the classes file name
     56    // Convert from the class name, to the classes file name.
    5757    $file_data = strtolower( $class );
    5858    $file_data = str_replace( '_', '-', $file_data );
    5959    $file_name = 'class-' . $file_data . '.php';
    6060
    61     // Get the classes file path
    62     $dir = dirname( __FILE__ );
     61    // Get the classes file path.
     62    $dir  = dirname( __FILE__ );
    6363    $path = $dir . '/inc/' . $file_name;
    6464
    65     // Include the class (spl_autoload_register will automatically instantiate it for us)
    66     require( $path );
     65    // Include the class (spl_autoload_register will automatically instantiate it for us).
     66    require $path;
    6767}
    6868spl_autoload_register( 'autoload_unique_headers' );
    6969
    70 new Unique_Headers_Instantiate;
     70new Unique_Headers_Instantiate();
  • unique-headers/trunk/readme.txt

    r2967092 r2981849  
    55Requires at least: 4.3
    66Tested up to: 6.4
    7 Stable tag: 1.8.3
     7Stable tag: 1.9
    88
    99
     
    9292
    9393== Changelog ==
     94
     95= 1.9 =
     96* Updated WordPress coding standards support
    9497
    9598= 1.8.3 =
Note: See TracChangeset for help on using the changeset viewer.