Changeset 2981849
- Timestamp:
- 10/20/2023 06:45:27 PM (2 years ago)
- Location:
- unique-headers
- Files:
-
- 25 added
- 10 edited
-
tags/1.9 (added)
-
tags/1.9/assets (added)
-
tags/1.9/assets/admin.css (added)
-
tags/1.9/assets/admin.js (added)
-
tags/1.9/composer.json (added)
-
tags/1.9/inc (added)
-
tags/1.9/inc/class-custom-image-meta-box.php (added)
-
tags/1.9/inc/class-dotorg-plugin-review.php (added)
-
tags/1.9/inc/class-unique-headers-core.php (added)
-
tags/1.9/inc/class-unique-headers-display.php (added)
-
tags/1.9/inc/class-unique-headers-instantiate.php (added)
-
tags/1.9/inc/class-unique-headers-taxonomy-header-images.php (added)
-
tags/1.9/inc/legacy.php (added)
-
tags/1.9/index.php (added)
-
tags/1.9/languages (added)
-
tags/1.9/languages/unique-headers-de_DE.mo (added)
-
tags/1.9/languages/unique-headers-de_DE.po (added)
-
tags/1.9/languages/unique-headers-es_ES.mo (added)
-
tags/1.9/languages/unique-headers-es_ES.po (added)
-
tags/1.9/languages/unique-headers-fr_FR.mo (added)
-
tags/1.9/languages/unique-headers-fr_FR.po (added)
-
tags/1.9/languages/unique-headers-sv_SE.mo (added)
-
tags/1.9/languages/unique-headers-sv_SE.po (added)
-
tags/1.9/license.txt (added)
-
tags/1.9/readme.txt (added)
-
trunk/composer.json (modified) (1 diff)
-
trunk/inc/class-custom-image-meta-box.php (modified) (13 diffs)
-
trunk/inc/class-dotorg-plugin-review.php (modified) (9 diffs)
-
trunk/inc/class-unique-headers-core.php (modified) (3 diffs)
-
trunk/inc/class-unique-headers-display.php (modified) (6 diffs)
-
trunk/inc/class-unique-headers-instantiate.php (modified) (7 diffs)
-
trunk/inc/class-unique-headers-taxonomy-header-images.php (modified) (23 diffs)
-
trunk/inc/legacy.php (modified) (5 diffs)
-
trunk/index.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
unique-headers/trunk/composer.json
r2966945 r2981849 3 3 "description": "WordPress plugin which adds the ability to use unique custom header images on individual pages, posts or categories or tags.", 4 4 "type": "wordpress-plugin", 5 "license": "GPL-2.0 ",5 "license": "GPL-2.0-only", 6 6 "authors": [ 7 7 { 8 8 "name": "ryanhellyer" 9 9 } 10 ], 11 "require": {} 10 ] 12 11 } -
unique-headers/trunk/inc/class-custom-image-meta-box.php
r2798946 r2981849 1 1 <?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 */ 2 13 3 14 /** … … 15 26 * 16 27 * @since 1.3 17 * @access private18 * @var string$name28 * @access private 29 * @var string $name 19 30 */ 20 31 private $name; … … 25 36 * 26 37 * @since 1.3 27 * @access private28 * @var string$name_underscores38 * @access private 39 * @var string $name_underscores 29 40 */ 30 41 private $name_underscores; … … 34 45 * 35 46 * @since 1.3 36 * @access private37 * @var string$dir_uri47 * @access private 48 * @var string $dir_uri 38 49 */ 39 50 private $dir_uri; 40 51 41 52 /** 42 * The title of the meta box 43 * 44 * @since 1.3 45 * @access private46 * @var string$title53 * The title of the meta box. 54 * 55 * @since 1.3 56 * @access private 57 * @var string $title 47 58 */ 48 59 private $title; 49 60 50 61 /** 51 * The set custom image text 52 * 53 * @since 1.3 54 * @access private55 * @var string$set_custom_image62 * The set custom image text. 63 * 64 * @since 1.3 65 * @access private 66 * @var string $set_custom_image 56 67 */ 57 68 private $set_custom_image; … … 61 72 * 62 73 * @since 1.3 63 * @access private64 * @var string$remove_custom_image74 * @access private 75 * @var string $remove_custom_image 65 76 */ 66 77 private $remove_custom_image; 67 78 68 79 /** 69 * The current version of the class 70 * 71 * @since 1.3 72 * @access private73 * @var string$version80 * The current version of the class. 81 * 82 * @since 1.3 83 * @access private 84 * @var string $version 74 85 */ 75 86 private $version = '1.3'; 76 87 77 88 /** 78 * The post types to add meta boxes to 79 * 80 * @since 1.3 81 * @access private82 * @var string$post_types89 * The post types to add meta boxes to. 90 * 91 * @since 1.3 92 * @access private 93 * @var string $post_types 83 94 */ 84 95 private $post_types; 85 96 86 97 /** 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. 90 102 * @since 1.3 91 103 */ … … 100 112 $this->post_types = $args['post_types']; 101 113 102 // Add meta box 114 // Add meta box. 103 115 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 104 116 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 ) { 119 132 120 133 $attachment_id = get_post_meta( $post_id, '_' . $name . '_id', true ); 121 134 122 // Check for fallback images 135 // Check for fallback images. 123 136 if ( ! $attachment_id ) { 124 137 $attachment_id = apply_filters( 'unique_header_fallback_images', $post_id ); … … 128 141 } 129 142 130 /* 131 * Get the attachment URL from the attachment ID 132 * 133 * @since 1.3 134 * @access staticThis method is static so that front-end scripts can access the attachments SRC135 * @param int $attachment_id The attachment ID136 * @return string137 */ 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 ) { 139 152 $url = ''; 140 153 141 // Grab URL from WordPress 154 // Grab URL from WordPress. 142 155 $src = wp_get_attachment_image_src( $attachment_id, 'full' ); 143 156 if ( isset( $src[0] ) ) { … … 148 161 } 149 162 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. 161 175 $data = wp_get_attachment_image_src( $attachment_id, 'full' ); 162 176 163 if ( 'width' == $dimension && isset( $data[1] ) ) {177 if ( 'width' === $dimension && isset( $data[1] ) ) { 164 178 return $data[1]; 165 } else if ( 'height'== $dimension && isset( $data[2] ) ) {179 } elseif ( 'height' === $dimension && isset( $data[2] ) ) { 166 180 return $data[2]; 167 181 } … … 173 187 * 174 188 * @since 1.3 175 * @access staticThis method is static so that front-end scripts can access the attachments title176 * @param int $attachment_id The attachment ID177 * @return string $titleThe attachment title178 */ 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 ) ) ); 183 197 184 198 return $title; … … 228 242 229 243 /** 230 * Registers the stylesheets for handling the meta box 244 * Registers the stylesheets for handling the meta box. 231 245 * 232 246 * @since 1.3 … … 237 251 $this->name, 238 252 $this->dir_uri . '/admin.css', 239 array() 253 array(), 254 $this->version 240 255 ); 241 256 … … 245 260 * Sanitized and saves the post featured footer image meta data specific with this post. 246 261 * 247 * @since 1.3248 * @param int $post_idThe ID of the post with which we're currently working.249 * @return int $post_idThe 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. 250 265 */ 251 266 public function save_post( $post_id ) { 252 267 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' ] ) ) { 255 270 return $post_id; 256 271 } 257 272 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 ) ) { 260 276 return $post_id; 261 277 } 262 278 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. 267 283 update_post_meta( $post_id, '_' . $this->name_underscores . '_id', $attachment_id ); 268 284 269 // Return the post ID 285 // Return the post ID. 270 286 return $post_id; 271 287 } 272 288 273 289 /** 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. 275 291 * the meta box. 276 292 * 277 * @param WP_Post $post The post object278 * @since 1.3293 * @param WP_Post $post The post object. 294 * @since 1.3 279 295 */ 280 296 public function display_custom_meta_image( $post ) { 281 297 282 // Get required values 298 // Get required values. 283 299 $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 ); 286 302 287 303 wp_nonce_field( $this->name, $this->name . '-nonce' ); … … 302 318 <p id="<?php echo esc_attr( $this->name . '-info' ); ?>" class="custom-meta-image-info"> 303 319 <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 305 322 306 323 return $post; -
unique-headers/trunk/inc/class-dotorg-plugin-review.php
r2512906 r2981849 1 1 <?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. 16 if ( class_exists( 'DotOrg_Plugin_Review' ) ) { 17 return; 18 } 2 19 3 20 /** … … 12 29 * @author Ryan Hellyer <ryanhellyer@gmail.com> 13 30 */ 14 if ( ! class_exists( 'DotOrg_Plugin_Review' ) ) :15 31 class DotOrg_Plugin_Review { 16 32 17 33 /** 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 28 58 */ 29 59 public $nobug_option; … … 31 61 /** 32 62 * Fire the constructor up :) 63 * 64 * @param array $args The arguments. 33 65 */ 34 66 public function __construct( $args ) { 35 67 36 $this->slug = $args['slug'];37 $this->name = $args['name'];68 $this->slug = $args['slug']; 69 $this->name = $args['name']; 38 70 if ( isset( $args['time_limit'] ) ) { 39 $this->time_limit = $args['time_limit'];71 $this->time_limit = $args['time_limit']; 40 72 } else { 41 73 $this->time_limit = WEEK_IN_SECONDS; … … 44 76 $this->nobug_option = $this->slug . '-no-bug'; 45 77 46 // Loading main functionality 78 // Loading main functionality. 47 79 add_action( 'admin_init', array( $this, 'check_installation_date' ) ); 48 80 add_action( 'admin_init', array( $this, 'set_no_bug' ), 5 ); … … 51 83 /** 52 84 * Seconds to words. 85 * 86 * @param int $seconds The number of seconds. 53 87 */ 54 88 public function seconds_to_words( $seconds ) { 55 89 56 // Get the years 57 $years = ( intval( $seconds )/ YEAR_IN_SECONDS ) % 100;90 // Get the years. 91 $years = round( $seconds / YEAR_IN_SECONDS ) % 100; 58 92 if ( $years > 1 ) { 93 // translators: %s: Number of years. 59 94 return sprintf( __( '%s years', $this->slug ), $years ); 60 } elseif ( $years > 0 ) {95 } elseif ( $years > 0 ) { 61 96 return __( 'a year', $this->slug ); 62 97 } 63 98 64 // Get the weeks 65 $weeks = ( intval( $seconds )/ WEEK_IN_SECONDS ) % 52;99 // Get the weeks. 100 $weeks = round( $seconds / WEEK_IN_SECONDS ) % 52; 66 101 if ( $weeks > 1 ) { 102 // translators: %s: Number of weeks. 67 103 return sprintf( __( '%s weeks', $this->slug ), $weeks ); 68 } elseif ( $weeks > 0 ) {104 } elseif ( $weeks > 0 ) { 69 105 return __( 'a week', $this->slug ); 70 106 } 71 107 72 // Get the days 73 $days = ( intval( $seconds )/ DAY_IN_SECONDS ) % 7;108 // Get the days. 109 $days = round( $seconds / DAY_IN_SECONDS ) % 7; 74 110 if ( $days > 1 ) { 111 // translators: %s: Number of days. 75 112 return sprintf( __( '%s days', $this->slug ), $days ); 76 } elseif ( $days > 0 ) {113 } elseif ( $days > 0 ) { 77 114 return __( 'a day', $this->slug ); 78 115 } 79 116 80 // Get the hours 81 $hours = ( intval( $seconds )/ HOUR_IN_SECONDS ) % 24;117 // Get the hours. 118 $hours = round( $seconds / HOUR_IN_SECONDS ) % 24; 82 119 if ( $hours > 1 ) { 120 // translators: %s: Number of hours. 83 121 return sprintf( __( '%s hours', $this->slug ), $hours ); 84 } elseif ( $hours > 0 ) {122 } elseif ( $hours > 0 ) { 85 123 return __( 'an hour', $this->slug ); 86 124 } 87 125 88 // Get the minutes 89 $minutes = ( intval( $seconds )/ MINUTE_IN_SECONDS ) % 60;126 // Get the minutes. 127 $minutes = round( $seconds / MINUTE_IN_SECONDS ) % 60; 90 128 if ( $minutes > 1 ) { 129 // translators: %s: Number of minutes. 91 130 return sprintf( __( '%s minutes', $this->slug ), $minutes ); 92 } elseif ( $minutes > 0 ) {131 } elseif ( $minutes > 0 ) { 93 132 return __( 'a minute', $this->slug ); 94 133 } 95 134 96 // Get the seconds 97 $seconds = intval( $seconds ) % 60;135 // Get the seconds. 136 $seconds = round( $seconds ) % 60; 98 137 if ( $seconds > 1 ) { 138 // translators: %s: Number of seconds. 99 139 return sprintf( __( '%s seconds', $this->slug ), $seconds ); 100 } elseif ( $seconds > 0 ) {140 } elseif ( $seconds > 0 ) { 101 141 return __( 'a second', $this->slug ); 102 142 } 103 143 104 return;105 144 } 106 145 … … 110 149 public function check_installation_date() { 111 150 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. 115 154 $install_date = get_site_option( $this->slug . '-activation-date' ); 116 if ( '' == $install_date ) {155 if ( '' === $install_date ) { 117 156 add_site_option( $this->slug . '-activation-date', time() ); 118 157 } 119 158 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 ) { 122 162 add_action( 'admin_notices', array( $this, 'display_admin_notice' ) ); 123 163 } 124 125 164 } 126 165 … … 132 171 public function display_admin_notice() { 133 172 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 ) { 136 175 137 176 $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' ) ); 139 178 140 179 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>'; 149 193 150 194 } … … 157 201 public function set_no_bug() { 158 202 159 // Bail out if not on correct page 203 // Bail out if not on correct page. 160 204 if ( 161 ! isset( $_GET['_wpnonce'] ) 205 ! isset( $_GET['_wpnonce'] ) 206 || 207 ( 208 ! wp_verify_nonce( filter_input( INPUT_GET, '_wpnonce' ), 'review-nonce' ) 162 209 || 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 ) 172 216 ) { 173 217 return; … … 179 223 180 224 } 181 endif; -
unique-headers/trunk/inc/class-unique-headers-core.php
r2512906 r2981849 1 1 <?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 */ 2 15 3 16 /** … … 10 23 */ 11 24 class Unique_Headers_Core { 12 13 /* 25 /** 14 26 * Filter for modifying the srcset values. 15 27 * This is required for when the srcset attribute is used within the header. … … 17 29 * @since 1.7 18 30 * 19 * @param string $srcset The new array of URLs20 * @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. 24 36 * 25 * @return string$srcset The new array of URLs37 * @return string $srcset The new array of URLs 26 38 */ 27 39 public function header_srcset_filter( $srcset, $size_array, $image_src, $image_meta, $attachment_id = 0 ) { 28 40 29 // Bail out if not on header ID 41 // Bail out if not on header ID. 30 42 if ( 31 43 ! isset( get_custom_header()->attachment_id ) 32 44 || 33 $attachment_id != get_custom_header()->attachment_id45 get_custom_header()->attachment_id !== $attachment_id 34 46 ) { 35 47 return $srcset; 36 48 } 37 49 38 // Changing each URL within the set 50 // Changing each URL within the set. 39 51 if ( is_array( $srcset ) ) { 40 foreach ( $srcset as $size => $set ) {52 foreach ( $srcset as $size => $set ) { 41 53 $srcset[ $size ]['url'] = $this->header_image_filter( $srcset[ $size ]['url'] ); 42 54 } -
unique-headers/trunk/inc/class-unique-headers-display.php
r2512906 r2981849 1 1 <?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 */ 2 16 3 17 /** … … 33 47 * Class constructor 34 48 * Adds methods to appropriate hooks 35 * 49 * 50 * @param array $args The arguments. 36 51 * @since 1.3 37 52 */ 38 53 public function __construct( $args ) { 39 54 40 $this->name_underscores = str_replace( '-', '_', $args['name'] );55 $this->name_underscores = str_replace( '-', '_', $args['name'] ); 41 56 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' ) ); 46 61 47 62 } 48 63 49 /* 64 /** 50 65 * Filter for modifying the output of get_header() 51 66 * 52 67 * @since 1.3 53 * @param string $url The header image URL54 * @return string $custom_urlThe new custom header image URL68 * @param string $url The header image URL. 69 * @return string $custom_url The new custom header image URL 55 70 */ 56 71 public function header_image_filter( $url ) { 57 72 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). 59 74 if ( ! is_single() && ! is_page() && ! is_home() ) { 60 75 return $url; 61 76 } 62 77 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). 64 79 if ( is_home() ) { 65 80 $post_id = get_option( 'page_for_posts' ); … … 68 83 } 69 84 70 // Get attachment ID 85 // Get attachment ID. 71 86 $attachment_id = Custom_Image_Meta_Box::get_attachment_id( $post_id, $this->name_underscores ); 72 87 73 // Generate new URL 88 // Generate new URL. 74 89 if ( is_numeric( $attachment_id ) ) { 75 90 $url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id ); … … 84 99 * This is a replica of the method in Unique_Headers_Taxonomy_Header_Images(). 85 100 * 86 * @param array $data The data87 * @return arrayThe modified data with new attachment ID101 * @param array $data The data. 102 * @return array The modified data with new attachment ID 88 103 */ 89 104 public function modify_header_image_data( $data ) { 90 105 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). 92 107 if ( ! is_single() && ! is_page() && ! is_home() ) { 93 108 return $data; 94 109 } 95 110 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). 97 112 if ( is_home() ) { 98 113 $post_id = get_option( 'page_for_posts' ); … … 101 116 } 102 117 103 // Get attachment ID 118 // Get attachment ID. 104 119 $attachment_id = Custom_Image_Meta_Box::get_attachment_id( $post_id, $this->name_underscores ); 105 120 106 // Set new data based on new header image attachment ID 121 // Set new data based on new header image attachment ID. 107 122 if ( is_numeric( $attachment_id ) ) { 108 123 109 // Create object 110 if ( null == $data ) {124 // Create object. 125 if ( null === $data ) { 111 126 $data = (object) null; 112 127 } … … 114 129 if ( is_object( $data ) ) { 115 130 $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' ); 118 133 } 134 } 119 135 120 }121 122 136 return $data; 123 137 } -
unique-headers/trunk/inc/class-unique-headers-instantiate.php
r2512906 r2981849 1 1 <?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 */ 2 16 3 17 /** … … 14 28 * Class constructor 15 29 * Adds methods to appropriate hooks 16 * 30 * 17 31 * @since 1.3.10 18 32 */ 19 33 public function __construct() { 20 34 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'; 24 38 25 // Loading dotorg plugin review code 39 // Loading dotorg plugin review code. 26 40 if ( is_admin() ) { 27 require ( 'class-dotorg-plugin-review.php' );41 require 'class-dotorg-plugin-review.php'; 28 42 new DotOrg_Plugin_Review( 29 43 array( 30 'slug' => 'unique-headers', // The plugin slug31 'name' => 'Unique Headers', // The plugin name32 'time_limit' => WEEK_IN_SECONDS, // The time limit at which notice is shown44 '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. 33 47 ) 34 48 ); 35 49 } 36 50 37 // Add hooks 51 // Add hooks. 38 52 add_action( 'plugins_loaded', array( $this, 'localization' ), 5 ); 39 53 add_action( 'init', array( $this, 'instantiate_classes' ), 20 ); … … 42 56 /** 43 57 * Instantiate classes 44 * 58 * 45 59 * @since 1.3 46 60 */ 47 61 public function instantiate_classes() { 48 62 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. 50 64 $args = array( 51 65 'name' => $name, … … 57 71 ); 58 72 59 // Add support for post-types 73 // Add support for post-types. 60 74 if ( is_admin() ) { 61 75 new Custom_Image_Meta_Box( $args ); … … 64 78 } 65 79 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). 67 81 if ( function_exists( 'get_term_meta' ) ) { 68 82 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 ) ); 71 85 72 // Add upload text 86 // Add upload text. 73 87 $args['upload_header_image'] = __( 'Upload header image', 'unique-headers' ); 74 88 … … 78 92 } 79 93 80 /* 94 /** 81 95 * Setup localization for translations 82 96 * … … 85 99 public function localization() { 86 100 87 // Localization 101 // Localization. 88 102 load_plugin_textdomain( 89 'unique-headers', // Unique identifier 90 false, // Deprecated abs path91 dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Languages folder 103 'unique-headers', // Unique identifier. 104 '', // Deprecated abs path. 105 dirname( plugin_basename( __FILE__ ) ) . '/languages/' // Languages folder. 92 106 ); 93 107 -
unique-headers/trunk/inc/class-unique-headers-taxonomy-header-images.php
r2512906 r2981849 1 1 <?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 */ 2 15 3 16 /** … … 15 28 * 16 29 * @since 1.3 17 * @access private18 * @var string$name30 * @access private 31 * @var string $name 19 32 */ 20 33 private $name; … … 25 38 * 26 39 * @since 1.3 27 * @access private28 * @var string$name_underscores40 * @access private 41 * @var string $name_underscores 29 42 */ 30 43 private $name_underscores; … … 34 47 * 35 48 * @since 1.3 36 * @access private37 * @var string$title49 * @access private 50 * @var string $title 38 51 */ 39 52 private $title; … … 43 56 * 44 57 * @since 1.3 45 * @access private46 * @var string$set_custom_image58 * @access private 59 * @var string $set_custom_image 47 60 */ 48 61 private $set_custom_image; … … 52 65 * 53 66 * @since 1.3 54 * @access private55 * @var string$remove_custom_image67 * @access private 68 * @var string $remove_custom_image 56 69 */ 57 70 private $remove_custom_image; … … 61 74 * 62 75 * @since 1.3 63 * @access private64 * @var string$taxonomies76 * @access private 77 * @var string $taxonomies 65 78 */ 66 79 private $taxonomies; … … 70 83 * 71 84 * @since 1.3 72 * @access private73 * @var string$upload_header_image85 * @access private 86 * @var string $upload_header_image 74 87 */ 75 88 private $upload_header_image; … … 77 90 /** 78 91 * Class constructor 79 * 92 * 80 93 * Adds methods to appropriate hooks 81 * 94 * 82 95 * @author Ryan Hellyer <ryanhellyer@gmail.com> 83 96 * @since 1.0 97 * @param array $args The arguments. 84 98 */ 85 99 public function __construct( $args ) { … … 93 107 $this->upload_header_image = $args['upload_header_image']; 94 108 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' ) ); 99 113 100 114 } … … 108 122 public function add_fields() { 109 123 110 // Add actions for administration pages 124 // Add actions for administration pages. 111 125 if ( is_admin() ) { 112 126 113 // Add hooks for each taxonomy 114 foreach ( $this->taxonomies as $taxonomy ) {127 // Add hooks for each taxonomy. 128 foreach ( $this->taxonomies as $taxonomy ) { 115 129 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 /** 124 137 * Filter for modifying the output of get_header() 125 138 * 126 139 * @author Ryan Hellyer <ryanhellyer@gmail.com> 127 140 * @since 1.0 141 * @param string $url The URL. 128 142 */ 129 143 public function header_image_filter( $url ) { 130 131 /* We need to grab the current taxonomy ID144 /* 145 * We need to grab the current taxonomy ID 132 146 * 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 134 148 * differently. 135 149 */ 136 150 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 ) { 148 162 $tax_info = get_query_var( 'tag' ); 149 163 } else { … … 153 167 $tax = get_term_by( 'slug', $tax_info, $taxonomy ); 154 168 if ( isset( $tax->term_id ) ) { 155 $tax_ ID= $tax->term_id;169 $tax_id = $tax->term_id; 156 170 } 157 171 } … … 159 173 } 160 174 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 ) ) { 164 177 return $url; 165 178 } 166 179 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. 171 184 if ( is_numeric( $attachment_id ) ) { 172 185 $new_url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id ); 173 186 } else { 174 187 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 ); 177 190 178 191 if ( is_numeric( $attachment_id ) ) { 179 192 $new_url = Custom_Image_Meta_Box::get_attachment_src( $attachment_id ); 180 193 } 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 ) { 188 200 $url = esc_url( $new_url ); 189 201 } 190 202 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. 192 204 } 193 205 194 206 /** 195 207 * Storing the taxonomy header image selection 196 * 208 * 197 209 * @author Ryan Hellyer <ryanhellyer@gmail.com> 198 210 * @since 1.0 … … 200 212 public function storing_taxonomy_data() { 201 213 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' ] ) ) { 204 216 return; 205 217 } 206 218 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 ) ) { 209 222 return; 210 223 } 211 224 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' ] ) ); 215 231 if ( is_numeric( $attachment_id ) ) { 216 232 $attachment_id = absint( $attachment_id ); … … 218 234 $attachment_id = $this->get_attachment_id_from_url( $attachment_id ); 219 235 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. 221 237 if ( ! is_numeric( $attachment_id ) ) { 222 238 $attachment_id = esc_url( $attachment_id ); … … 224 240 } 225 241 226 // Save the term meta data 242 // Save the term meta data. 227 243 update_term_meta( $tag_ID, 'taxonomy-header-image', $attachment_id ); 228 244 } 229 245 230 /* 246 /** 231 247 * Legacy method 232 248 * Used to obtain the attachment ID, if a URL is detected 233 * 249 * 234 250 * URL's were used in earlier versions of the plugin. This was upgraded 235 251 * for version 1.3 to utilize attachment ID's instead. These older URL's … … 240 256 * https://philipnewcomer.net/2012/11/get-the-attachment-id-from-an-image-url-in-wordpress/ 241 257 * 242 * @global object $wpdb The WordPress database object243 * @param string $url The URL we are trying to find the attachment ID for244 * @return int $attachment_idThe attachment ID for the input URL258 * @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 245 261 */ 246 262 private function get_attachment_id_from_url( $url = '' ) { … … 248 264 $attachment_id = false; 249 265 250 // If there is no url, return false 251 if ( '' == $url ) {266 // If there is no url, return false. 267 if ( '' === $url ) { 252 268 return false; 253 269 } 254 270 255 // Get the upload directory paths 271 // Get the upload directory paths. 256 272 $upload_dir_paths = wp_upload_dir(); 257 273 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. 259 275 if ( false !== strpos( $url, $upload_dir_paths['baseurl'] ) ) { 260 276 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. 262 278 $url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $url ); 263 279 264 // Remove the upload path base directory from the attachment URL 280 // Remove the upload path base directory from the attachment URL. 265 281 $url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $url ); 266 282 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 ) { 273 294 return $url; 274 295 } … … 279 300 /** 280 301 * Extra fields 281 * 302 * 282 303 * @author Ryan Hellyer <ryanhellyer@gmail.com> 283 304 * @since 1.0 … … 285 306 public function extra_fields() { 286 307 287 $tag_ID = absint( $_GET['tag_ID']);308 $tag_ID = absint( filter_input( INPUT_GET, 'tag_ID' ) ); 288 309 $attachment_id = get_term_meta( $tag_ID, 'taxonomy-header-image', true ); 289 310 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. 291 312 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 ); 293 314 $title = Custom_Image_Meta_Box::get_attachment_title( $attachment_id ); 294 315 } else { 295 316 296 // Falling back to taxonomy meta plugin functionality 317 // Falling back to taxonomy meta plugin functionality. 297 318 $attachment_id = get_metadata( 'taxonomy', $tag_ID, 'taxonomy-header-image', true ); 298 319 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 ); 300 321 $title = Custom_Image_Meta_Box::get_attachment_title( $attachment_id ); 301 322 } 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 } 306 326 } 307 327 … … 337 357 <?php 338 358 339 340 359 } 341 360 … … 345 364 * This is similar to the method in Unique_Headers_Display(). 346 365 * 347 * @param array $data The data348 * @return arrayThe modified data with new attachment ID366 * @param array $data The data. 367 * @return array The modified data with new attachment ID 349 368 */ 350 369 public function modify_header_image_data( $data ) { 351 370 352 // Bail out now if not in taxonomy archive 371 // Bail out now if not in taxonomy archive. 353 372 if ( ! is_tag() && ! is_tax() && ! is_category() ) { 354 373 return $data; 355 374 } 356 375 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). 358 377 if ( is_home() ) { 359 378 $post_id = get_option( 'page_for_posts' ); … … 362 381 } 363 382 364 // Get attachment ID 383 // Get attachment ID. 365 384 $attachment_id = Custom_Image_Meta_Box::get_attachment_id( $post_id, $this->name_underscores ); 366 385 367 // Set new data based on new header image attachment ID 386 // Set new data based on new header image attachment ID. 368 387 if ( is_numeric( $attachment_id ) ) { 369 388 370 // Create object 371 if ( null == $data || empty( $data ) ) {389 // Create object. 390 if ( null === $data || empty( $data ) ) { 372 391 $data = (object) null; 373 392 } 374 393 375 if ( is_object ( $data ) ) {394 if ( is_object( $data ) ) { 376 395 $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 } 381 399 } 382 400 -
unique-headers/trunk/inc/legacy.php
r2512906 r2981849 1 1 <?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 */ 2 15 3 16 /** 4 17 * Do not continue processing since file was called directly 5 * 18 * 6 19 * @since 1.6.1 7 20 * @author Ryan Hellyer <ryanhellyer@gmail.com> … … 11 24 } 12 25 13 /* 26 /** 14 27 * Legacy fallback for old images 15 28 * … … 19 32 * Future versions of the Unique Headers plugin will phase out this legacy code 20 33 * 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 22 35 * this function being required in future versions. 23 36 * 24 37 * @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. 27 39 */ 28 40 function unique_header_fallback_images( $post_id ) { 29 41 $attachment_id = ''; 30 42 31 // Loop through the legacy meta keys, looking for header images 43 // Loop through the legacy meta keys, looking for header images. 32 44 $keys = array( 33 45 'post_custom-header_thumbnail_id', … … 35 47 'kd_custom-header_post_id', 36 48 '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. 39 51 ); 40 52 41 foreach ( $keys as $key ) {42 if ( '' == $attachment_id ) {53 foreach ( $keys as $key ) { 54 if ( '' === $attachment_id ) { 43 55 $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. 46 58 } 47 59 } 48 60 } 49 61 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 ) { 52 64 return false; 53 65 } else { 54 66 55 // Update to use new meta key 67 // Update to use new meta key. 56 68 update_post_meta( $post_id, '_custom_header_image_id', $attachment_id ); 57 69 58 // Delete unused meta keys 59 foreach ( $keys_to_remove as $key ) {70 // Delete unused meta keys. 71 foreach ( $keys_to_remove as $key ) { 60 72 delete_post_meta( $post_id, $key ); 61 73 } … … 66 78 add_filter( 'unique_header_fallback_images', 'unique_header_fallback_images' ); 67 79 68 /* 80 /** 69 81 * Quick touchup to wpdb. 70 82 * This is a throwback to the taxonomy meta data plugin. 71 83 * Once that plugin has been upgraded and migrated users taxonomy data over, this function will not longer be required. 72 84 * 73 * @global object $wpdbThe main WordPress database object85 * @global object $wpdb The main WordPress database object 74 86 */ 75 87 function unique_header_wpdbfix() { 76 88 77 // Bail out now if Taxonomy Metadata plugin not installed 89 // Bail out now if Taxonomy Metadata plugin not installed. 78 90 if ( ! class_exists( 'Taxonomy_Metadata' ) ) { 79 91 return; -
unique-headers/trunk/index.php
r2967092 r2981849 1 1 <?php 2 /* 2 /** 3 3 Plugin Name: Unique Headers 4 4 Plugin URI: https://geek.hellyer.kiwi/plugins/unique-headers/ 5 5 Description: Unique Headers 6 Version: 1. 8.36 Version: 1.9 7 7 Author: Ryan Hellyer 8 8 Author URI: https://geek.hellyer.kiwi/ … … 27 27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 28 28 29 */ 30 29 @package unique-headers 30 */ 31 31 32 32 /** 33 33 * Do not continue processing since file was called directly 34 * 34 * 35 35 * @since 1.0 36 36 * @author Ryan Hellyer <ryanhellyer@gmail.com> … … 45 45 * Includes the classes, and automatically instantiates them via spl_autoload_register(). 46 46 * 47 * @param string $class The class being instantiated47 * @param string $class The class being instantiated. 48 48 */ 49 49 function autoload_unique_headers( $class ) { 50 50 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 ) ) { 53 53 return; 54 54 } 55 55 56 // Convert from the class name, to the classes file name 56 // Convert from the class name, to the classes file name. 57 57 $file_data = strtolower( $class ); 58 58 $file_data = str_replace( '_', '-', $file_data ); 59 59 $file_name = 'class-' . $file_data . '.php'; 60 60 61 // Get the classes file path 62 $dir = dirname( __FILE__ );61 // Get the classes file path. 62 $dir = dirname( __FILE__ ); 63 63 $path = $dir . '/inc/' . $file_name; 64 64 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; 67 67 } 68 68 spl_autoload_register( 'autoload_unique_headers' ); 69 69 70 new Unique_Headers_Instantiate ;70 new Unique_Headers_Instantiate(); -
unique-headers/trunk/readme.txt
r2967092 r2981849 5 5 Requires at least: 4.3 6 6 Tested up to: 6.4 7 Stable tag: 1. 8.37 Stable tag: 1.9 8 8 9 9 … … 92 92 93 93 == Changelog == 94 95 = 1.9 = 96 * Updated WordPress coding standards support 94 97 95 98 = 1.8.3 =
Note: See TracChangeset
for help on using the changeset viewer.