Changeset 690895
- Timestamp:
- 04/03/2013 01:34:08 AM (13 years ago)
- Location:
- wp-display-header/trunk
- Files:
-
- 3 edited
- 1 copied
- 1 moved
-
css/wp-display-header.css (moved) (moved from wp-display-header/trunk/css/wp-display-header.dev.css)
-
css/wp-display-header.min.css (copied) (copied from wp-display-header/trunk/css/wp-display-header.css)
-
obenland-wp-plugins.php (modified) (12 diffs)
-
readme.txt (modified) (4 diffs)
-
wp-display-header.php (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-display-header/trunk/obenland-wp-plugins.php
r541580 r690895 2 2 /** obenland-wp-plugins.php 3 3 * 4 * @author Konstantin Obenland5 * @version 2.0.04 * @author Konstantin Obenland 5 * @version 3.0.1 6 6 */ 7 7 8 8 9 class Obenland_Wp_Plugins_v200 { 10 9 class Obenland_Wp_Plugins_v301 { 11 10 12 11 ///////////////////////////////////////////////////////////////////////////// … … 15 14 16 15 /** 17 * The plugins' text domain 18 * 19 * @author Konstantin Obenland20 * @since 1.1 - 03.04.201121 * @access protected22 * 23 * @var string16 * The plugins' text domain. 17 * 18 * @author Konstantin Obenland 19 * @since 1.1 - 03.04.2011 20 * @access protected 21 * 22 * @var string 24 23 */ 25 24 protected $textdomain; … … 27 26 28 27 /** 29 * The name of the calling plugin 30 * 31 * @author Konstantin Obenland32 * @since 1.0 - 23.03.201133 * @access protected34 * 35 * @var string28 * The name of the calling plugin. 29 * 30 * @author Konstantin Obenland 31 * @since 1.0 - 23.03.2011 32 * @access protected 33 * 34 * @var string 36 35 */ 37 36 protected $plugin_name; … … 39 38 40 39 /** 41 * The donate link for the plugin 42 * 43 * @author Konstantin Obenland44 * @since 1.0 - 23.03.201145 * @access protected46 * 47 * @var string40 * The donate link for the plugin. 41 * 42 * @author Konstantin Obenland 43 * @since 1.0 - 23.03.2011 44 * @access protected 45 * 46 * @var string 48 47 */ 49 48 protected $donate_link; … … 51 50 52 51 /** 53 * The path to the plugin folder 52 * The path to the plugin file. 53 * 54 * /path/to/wp-content/plugins/{plugin-name}/{plugin-name}.php 55 * 56 * @author Konstantin Obenland 57 * @since 2.0.0 - 30.05.2012 58 * @access protected 59 * 60 * @var string 61 */ 62 protected $plugin_path; 63 64 65 /** 66 * The path to the plugin directory. 54 67 * 55 68 * /path/to/wp-content/plugins/{plugin-name}/ 56 69 * 57 * @author Konstantin Obenland58 * @since 1.2 - 21.04.201159 * @access protected60 * 61 * @var string62 */ 63 protected $plugin_ path;70 * @author Konstantin Obenland 71 * @since 1.2 - 21.04.2011 72 * @access protected 73 * 74 * @var string 75 */ 76 protected $plugin_dir_path; 64 77 65 78 … … 71 84 * Constructor 72 85 * 73 * @author Konstantin Obenland74 * @since 1.0 - 23.03.201175 * @access public76 * 77 * @param string$plugin_name78 * @param string$donate_link_id79 * 80 * @return Obenland_Wp_Plugins86 * @author Konstantin Obenland 87 * @since 1.0 - 23.03.2011 88 * @access public 89 * 90 * @param string $plugin_name 91 * @param string $donate_link_id 92 * 93 * @return Obenland_Wp_Plugins 81 94 */ 82 95 public function __construct( $args = array() ) { 83 96 84 97 // Set class properties 85 $this->textdomain = $args['textdomain']; 86 $this->plugin_path = plugin_dir_path( $args['plugin_path'] ); 87 $this->plugin_name = plugin_basename( $args['plugin_path'] ); 98 $this->textdomain = $args['textdomain']; 99 $this->plugin_path = $args['plugin_path']; 100 $this->plugin_dir_path = plugin_dir_path( $args['plugin_path'] ); 101 $this->plugin_name = plugin_basename( $args['plugin_path'] ); 102 103 load_plugin_textdomain( 'obenland-wp', false, $this->textdomain . '/lang' ); 88 104 89 105 load_plugin_textdomain( 'obenland-wp' , false, $this->textdomain . '/lang' ); 90 106 91 107 $this->set_donate_link( $args['donate_link_id'] ); 92 108 $this->hook( 'plugins_loaded', 'parent_plugins_loaded' ); 93 109 } 94 95 110 111 96 112 /** 97 113 * Hooks in all the hooks :) 98 114 * 99 * @author Konstantin Obenland100 * @since 2.0.0 - 12.04.2012101 * @access public102 * 103 * @return void115 * @author Konstantin Obenland 116 * @since 2.0.0 - 12.04.2012 117 * @access public 118 * 119 * @return void 104 120 */ 105 121 public function parent_plugins_loaded() { 106 122 $this->hook( 'plugin_row_meta' ); 107 $this->hook( 'obenland_side_info_column', 'donate_box', 1 ); 108 $this->hook( 'obenland_side_info_column', 'feed_box' ); 109 } 110 111 112 /** 113 * 114 * @author Konstantin Obenland 115 * @since 1.0 - 23.03.2011 116 * @access public 117 * 118 * @param array $plugin_meta 119 * @param string $plugin_file 120 * 121 * @return string 123 if ( ! has_action( 'obenland_side_info_column' ) ) { 124 $this->hook( 'obenland_side_info_column', 'donate_box', 1 ); 125 $this->hook( 'obenland_side_info_column', 'feed_box' ); 126 } 127 } 128 129 130 /** 131 * 132 * @author Konstantin Obenland 133 * @since 1.0 - 23.03.2011 134 * @access public 135 * 136 * @param array $plugin_meta 137 * @param string $plugin_file 138 * 139 * @return string 122 140 */ 123 141 public function plugin_row_meta( $plugin_meta, $plugin_file ) { 124 142 if ( $this->plugin_name == $plugin_file ) { 125 $plugin_meta[] = sprintf('126 <a href="%1$s" target="_blank" title="%2$s">%2$s</a>',143 $plugin_meta[] = sprintf( 144 '<a href="%1$s" target="_blank" title="%2$s">%2$s</a>', 127 145 $this->donate_link, 128 __( 'Donate', $this->textdomain)146 __( 'Donate', 'obenland-wp' ) 129 147 ); 130 148 } 131 149 return $plugin_meta; 132 150 } 133 134 151 152 135 153 /** 136 154 * Displays a box with a donate button and call to action links … … 168 186 <?php 169 187 } 170 171 188 189 172 190 /** 173 191 * Displays a box with feed items and social media links 174 * 192 * 175 193 * Props Joost de Valk, as this is almost entirely from his awesome WordPress 176 194 * SEO Plugin … … 184 202 */ 185 203 public function feed_box() { 186 204 187 205 include_once( ABSPATH . WPINC . '/feed.php' ); 188 206 $feed_url = 'http://en.wp.obenland.it/feed/'; 189 207 $rss = fetch_feed( $feed_url ); 190 208 191 209 // Bail if feed doesn't work 192 210 if ( is_wp_error($rss) ) 193 211 return false; 194 212 195 213 $rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) ); 196 214 197 215 // If the feed was erroneously 198 216 if ( ! $rss_items ) { … … 224 242 225 243 244 /** 245 * Displays a box with a donate button and call to action links. 246 * 247 * Props Joost de Valk, as this is almost entirely from his awesome WordPress 248 * SEO Plugin. 249 * @see http://plugins.svn.wordpress.org/wordpress-seo/tags/1.1.5/admin/class-config.php 250 * 251 * @author Joost de Valk, Konstantin Obenland 252 * @since 2.0.0 - 31.03.2012 253 * @access public 254 * 255 * @return void 256 */ 257 public function donate_box() { 258 $plugin_data = get_plugin_data( $this->plugin_path ); 259 ?> 260 <div id="formatdiv" class="postbox"> 261 <h3 class="hndle"><span><?php esc_html_e( 'Help spread the word!', 'obenland-wp' ); ?></span></h3> 262 <div class="inside"> 263 <p><strong><?php printf( _x( 'Want to help make this plugin even better? All donations are used to improve %1$s, so donate $20, $50 or $100 now!', 'Plugin Name', 'obenland-wp' ), esc_html($plugin_data['Name']) ); ?></strong></p> 264 <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> 265 <input type="hidden" name="cmd" value="_s-xclick"> 266 <input type="hidden" name="hosted_button_id" value="G65Y5CM3HVRNY"> 267 <input type="image" src="https://www.paypalobjects.com/<?php echo get_locale(); ?>/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal Ñ The safer, easier way to pay online."> 268 <img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1"> 269 </form> 270 <p><?php _e( 'Or you could:', 'obenland-wp' ); ?></p> 271 <ul> 272 <li><a href="http://wordpress.org/extend/plugins/wp-approve-user/"><?php _e( 'Rate the plugin 5★ on WordPress.org', 'obenland-wp' ); ?></a></li> 273 <li><a href="<?php echo esc_url( $plugin_data['PluginURI'] ); ?>"><?php _e( 'Blog about it & link to the plugin page', 'obenland-wp' ); ?></a></li> 274 </ul> 275 </div> 276 </div> 277 <?php 278 } 279 280 281 /** 282 * Displays a box with feed items and social media links. 283 * 284 * Props Joost de Valk, as this is almost entirely from his awesome WordPress 285 * SEO Plugin. 286 * @see http://plugins.svn.wordpress.org/wordpress-seo/tags/1.1.5/admin/yst_plugin_tools.php 287 * 288 * @author Joost de Valk, Konstantin Obenland 289 * @since 2.0.0 - 31.03.2012 290 * @access public 291 * 292 * @return void 293 */ 294 public function feed_box() { 295 296 include_once( ABSPATH . WPINC . '/feed.php' ); 297 $feed_url = 'http://en.wp.obenland.it/feed/'; 298 $rss = fetch_feed( $feed_url ); 299 300 // Bail if feed doesn't work. 301 if ( is_wp_error( $rss ) ) 302 return; 303 304 $rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) ); 305 306 // If the feed was erroneously. 307 if ( ! $rss_items ) { 308 $md5 = md5( $feed_url ); 309 delete_transient( 'feed_' . $md5 ); 310 delete_transient( 'feed_mod_' . $md5 ); 311 $rss = fetch_feed( $feed_url ); 312 $rss_items = $rss->get_items( 0, $rss->get_item_quantity( 5 ) ); 313 } 314 ?> 315 <div id="formatdiv" class="postbox"> 316 <h3 class="hndle"><span><?php esc_html_e( 'News from Konstantin', 'obenland-wp' ); ?></span></h3> 317 <div class="inside"> 318 <ul> 319 <?php if ( ! $rss_items ) : ?> 320 <li><?php _e( 'No news items, feed might be broken...', 'obenland-wp' ); ?></li> 321 <?php else : 322 foreach ( $rss_items as $item ) : 323 $url = preg_replace( '/#.*/', '#utm_source=wordpress&utm_medium=sidebannerpostbox&utm_term=rssitem&utm_campaign=' . $this->textdomain, $item->get_permalink() ); ?> 324 <li><a class="rsswidget" href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $item->get_title() ); ?></a></li> 325 <?php endforeach; endif; ?> 326 <li class="twitter"><a href="http://twitter.com/obenland"><?php _e( 'Follow Konstantin on Twitter', 'obenland-wp' ); ?></a></li> 327 <li class="rss"><a href="<?php echo esc_url( $feed_url ); ?>"><?php _e( 'Subscribe via RSS', 'obenland-wp' ); ?></a></li> 328 </ul> 329 </div> 330 </div> 331 <?php 332 } 333 334 226 335 /////////////////////////////////////////////////////////////////////////// 227 336 // METHODS, PROTECTED … … 229 338 230 339 /** 231 * Hooks methods t heir WordPress Actions and Filters340 * Hooks methods to their WordPress Actions and Filters. 232 341 * 233 342 * @example: … … 236 345 * $this->hook( 'omg', 'is_really_tedious', 3 ); 237 346 * 238 * @author Mark Jaquith239 * @see http://sliwww.slideshare.net/markjaquith/creating-and-maintaining-wordpress-plugins240 * @since 1.5 - 12.02.2012241 * @access protected242 * 243 * @param string $hook Action or Filter Hook name244 * 245 * @return booleantrue347 * @author Mark Jaquith 348 * @see http://sliwww.slideshare.net/markjaquith/creating-and-maintaining-wordpress-plugins 349 * @since 1.5 - 12.02.2012 350 * @access protected 351 * 352 * @param string $hook Action or Filter Hook name. 353 * 354 * @return boolean true 246 355 */ 247 356 protected function hook( $hook ) { 248 $priority =10;249 $method =$this->sanitize_method( $hook );250 $args =func_get_args();357 $priority = 10; 358 $method = $this->sanitize_method( $hook ); 359 $args = func_get_args(); 251 360 unset( $args[0] ); // Filter name 252 361 253 362 foreach ( (array) $args as $arg ) { 254 if ( is_int( $arg ) ) { 255 $priority = $arg; 256 } 257 else { 258 $method = $arg; 259 260 } 363 if ( is_int( $arg ) ) 364 $priority = $arg; 365 else 366 $method = $arg; 261 367 } 262 368 263 return add_action( $hook, array( $this, $method ), $priority , 999 );264 } 265 266 267 /** 268 * Sets the donate link 269 * 270 * @author Konstantin Obenland271 * @since 1.1 - 03.04.2011272 * @access protected273 * 274 * @param string$donate_link_id275 * 276 * @return void369 return add_action( $hook, array( $this, $method ), $priority , 999 ); 370 } 371 372 373 /** 374 * Sets the donate link. 375 * 376 * @author Konstantin Obenland 377 * @since 1.1 - 03.04.2011 378 * @access protected 379 * 380 * @param string $donate_link_id 381 * 382 * @return void 277 383 */ 278 384 protected function set_donate_link( $donate_link_id ) { 279 $this->donate_link =add_query_arg( array(280 'cmd' =>'_s-xclick',281 'hosted_button_id' =>$donate_link_id385 $this->donate_link = add_query_arg( array( 386 'cmd' => '_s-xclick', 387 'hosted_button_id' => $donate_link_id 282 388 ), 'https://www.paypal.com/cgi-bin/webscr' ); 283 389 } … … 286 392 // METHODS, PRIVATE 287 393 /////////////////////////////////////////////////////////////////////////// 288 289 /** 290 * Sanitizes method names 291 * 292 * @author Mark Jaquith293 * @see http://sliwww.slideshare.net/markjaquith/creating-and-maintaining-wordpress-plugins294 * @since 1.5 - 12.02.2012295 * @access private296 * 297 * @param string $method Method name to be sanitized298 * 299 * @return stringSanitized method name394 395 /** 396 * Sanitizes method names. 397 * 398 * @author Mark Jaquith 399 * @see http://sliwww.slideshare.net/markjaquith/creating-and-maintaining-wordpress-plugins 400 * @since 1.5 - 12.02.2012 401 * @access private 402 * 403 * @param string $method Method name to be sanitized. 404 * 405 * @return string Sanitized method name 300 406 */ 301 407 private function sanitize_method( $method ) { -
wp-display-header/trunk/readme.txt
r541921 r690895 4 4 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MWUA92KA2TL6Q 5 5 Requires at least: 3.2 6 Tested up to: 3. 4-beta47 Stable tag: 2. 0.16 Tested up to: 3.6 7 Stable tag: 2.1.0 8 8 9 9 Select a specific header or random header image for each content item or archive page. … … 68 68 == Changelog == 69 69 70 = 2.1.0 = 71 * Added an option to not display a header at all. 72 * Updated utility class. 73 * Tested for WordPress 3.6. 74 70 75 = 2.0.1 = 71 * Fixed a bug, where the fallback to the default header did not work. Props carloscorrela 76 * Fixed a bug, where the fallback to the default header did not work. Props carloscorrela. 72 77 73 78 = 2.0.0 = 74 79 * **IMPORTANT**: Version 2.0.0 breaks compatibility with WordPress versions **prior** to 3.2! 75 80 * Added the header selection field to Taxonomy and Author Edit screens. 76 * Fixed a minor bug for themes that have no header images registered 81 * Fixed a minor bug for themes that have no header images registered. 77 82 78 83 = 1.5.3 = 79 84 * Improved user experience when current theme does not support custom headers, on activation of the plugin. 80 * Deprecated settings functions for WP Save Custom Header in preparation for overhaul in v2.0.0 81 * Updated utility class 85 * Deprecated settings functions for WP Save Custom Header in preparation for overhaul in v2.0.0. 86 * Updated utility class. 82 87 83 88 = 1.5.2 = … … 88 93 89 94 = 1.5 = 90 * Adjusted meta box layout to WordPress core 91 * Transfered CSS in external file 92 * Updated FAQ section (thanks Brian!)93 * Tested for WordPress 3.3.1 95 * Adjusted meta box layout to WordPress core. 96 * Transfered CSS in external file. 97 * Updated FAQ section. Props Brian. 98 * Tested for WordPress 3.3.1. 94 99 95 100 = 1.4 = 96 * Added support for WordPress 3.2 core header uploads 101 * Added support for WordPress 3.2 core header uploads. 97 102 98 103 = 1.3 = … … 101 106 102 107 = 1.2.1 = 103 * WordPress Plugin Repository update bug 108 * WordPress Plugin Repository update bug. 104 109 105 110 = 1.2 = 106 * Tested for WordPress 3.1.2 107 * Now a custom folder name can be specified. See: Settings > Media 108 * Added Italian translation (Thanks to Pietro Rossi)111 * Tested for WordPress 3.1.2. 112 * Now a custom folder name can be specified. See: Settings > Media. 113 * Added Italian translation. Props Pietro Rossi. 109 114 110 115 = 1.1 = 111 116 * Tested for WordPress 3.1.1 112 * Adopted [WP Save Custom Header](http://wordpress.org/extend/plugins/wp-save-custom-header/ "This plugin lets you save and reuse your uploaded header images.") multisite capability 113 * Made HTML W3C valid 117 * Adopted [WP Save Custom Header](http://wordpress.org/extend/plugins/wp-save-custom-header/ "This plugin lets you save and reuse your uploaded header images.") multisite capability. 118 * Made HTML W3C valid. 114 119 115 120 = 1.0 = 116 * Initial Release 121 * Initial Release. 117 122 118 123 == Upgrade Notice == -
wp-display-header/trunk/wp-display-header.php
r690454 r690895 2 2 /** wp-display-header.php 3 3 * 4 * Plugin Name: WP Display Header5 * Plugin URI: http://en.wp.obenland.it/wp-display-header/?utm_source=wordpress&utm_medium=plugin&utm_campaign=wp-display-header6 * Description: This plugin lets you specify a header image for each post and taxonomy/author archive page individually, from your default headers and custom headers.7 * Version: 2.0.18 * Author: Konstantin Obenland9 * Author URI: http://en.wp.obenland.it/?utm_source=wordpress&utm_medium=plugin&utm_campaign=wp-display-header10 * Text Domain: wp-display-header11 * Domain Path: /lang12 * License: GPLv24 * Plugin Name: WP Display Header 5 * Plugin URI: http://en.wp.obenland.it/wp-display-header/?utm_source=wordpress&utm_medium=plugin&utm_campaign=wp-display-header 6 * Description: This plugin lets you specify a header image for each post and taxonomy/author archive page individually, from your default headers and custom headers. 7 * Version: 2.1.0 8 * Author: Konstantin Obenland 9 * Author URI: http://en.wp.obenland.it/?utm_source=wordpress&utm_medium=plugin&utm_campaign=wp-display-header 10 * Text Domain: wp-display-header 11 * Domain Path: /lang 12 * License: GPLv2 13 13 */ 14 14 15 15 16 if ( ! class_exists( 'Obenland_Wp_Plugins_v200') ) {16 if ( ! class_exists( 'Obenland_Wp_Plugins_v301' ) ) 17 17 require_once( 'obenland-wp-plugins.php' ); 18 } 19 20 21 register_activation_hook(__FILE__, array( 18 19 20 register_activation_hook( __FILE__, array( 22 21 'Obenland_Wp_Display_Header', 23 22 'activation' 24 )); 25 26 27 class Obenland_Wp_Display_Header extends Obenland_Wp_Plugins_v200 { 28 23 ) ); 24 25 26 class Obenland_Wp_Display_Header extends Obenland_Wp_Plugins_v301 { 29 27 30 28 /////////////////////////////////////////////////////////////////////////// … … 35 33 * Constructor 36 34 * 37 * @author Konstantin Obenland38 * @since 1.0 - 23.03.201139 * @access public40 * 41 * @return Obenland_Wp_Display_Header35 * @author Konstantin Obenland 36 * @since 1.0 - 23.03.2011 37 * @access public 38 * 39 * @return Obenland_Wp_Display_Header 42 40 */ 43 41 public function __construct() { 44 42 45 43 parent::__construct( array( 46 'textdomain' =>'wp-display-header',47 'plugin_path' =>__FILE__,48 'donate_link_id' => 'MWUA92KA2TL6Q'44 'textdomain' => 'wp-display-header', 45 'plugin_path' => __FILE__, 46 'donate_link_id' => 'MWUA92KA2TL6Q', 49 47 )); 50 48 … … 59 57 * if it doesn't. The plugin will stay deactivated. 60 58 * 61 * @author Konstantin Obenland62 * @since 1.0 - 23.03.201163 * @access public59 * @author Konstantin Obenland 60 * @since 1.0 - 23.03.2011 61 * @access public 64 62 * @static 65 63 * 66 * @return void64 * @return void 67 65 */ 68 66 public static function activation() { … … 71 69 if ( ! current_theme_supports( 'custom-header' ) ) { 72 70 wp_die( __( 'Your current theme does not support Custom Headers.', 'wp-display-header' ), '', array( 73 'back_link' =>true71 'back_link' => true 74 72 ) ); 75 73 } 76 74 77 if ( version_compare( get_bloginfo( 'version'), '3.2', '<' ) ) {75 if ( version_compare( get_bloginfo( 'version' ), '3.2', '<' ) ) { 78 76 wp_die( __( 'WP Display Headers requires WordPress version 3.2 or later.', 'wp-display-header' ), '', array( 79 'back_link' =>true77 'back_link' => true 80 78 ) ); 81 79 } … … 86 84 * Hooks in all the hooks :) 87 85 * 88 * @author Konstantin Obenland89 * @since 1.5.3 - 24.02.201290 * @access public91 * 92 * @return void86 * @author Konstantin Obenland 87 * @since 1.5.3 - 24.02.2012 88 * @access public 89 * 90 * @return void 93 91 */ 94 92 public function init() { … … 100 98 $this->hook( 'save_post' ); 101 99 $this->hook( 'edit_term' ); 102 $this->hook( 'personal_options_update', 'update_user');103 $this->hook( 'edit_user_profile_update', 'update_user');100 $this->hook( 'personal_options_update', 'update_user' ); 101 $this->hook( 'edit_user_profile_update', 'update_user' ); 104 102 105 103 // Styles 106 $this->hook( 'admin_init', 'register_scripts_styles', 9 ); // Set priority to 9, so they can easily be deregistered107 $this->hook( 'admin_print_styles-post-new.php', 'admin_print_styles');108 $this->hook( 'admin_print_styles-post.php', 'admin_print_styles');109 $this->hook( 'admin_print_styles-edit-tags.php', 'admin_print_styles');110 $this->hook( 'admin_print_styles-profile.php', 'admin_print_styles');111 $this->hook( 'admin_print_styles-user-edit.php', 'admin_print_styles');104 $this->hook( 'admin_init', 'register_scripts_styles', 9 ); // Set priority to 9, so they can easily be deregistered. 105 $this->hook( 'admin_print_styles-post-new.php', 'admin_print_styles' ); 106 $this->hook( 'admin_print_styles-post.php', 'admin_print_styles' ); 107 $this->hook( 'admin_print_styles-edit-tags.php', 'admin_print_styles' ); 108 $this->hook( 'admin_print_styles-profile.php', 'admin_print_styles' ); 109 $this->hook( 'admin_print_styles-user-edit.php', 'admin_print_styles' ); 112 110 113 111 // Edit forms 114 foreach ( get_taxonomies( array( 'show_ui' => true) ) as $_tax ) {115 $this->hook( "{$_tax}_edit_form", 'edit_form' , 9 ); //Let's make us a bit more important than we are116 } 117 $this->hook( 'admin_init', 'add_settings_field');118 $this->hook( 'show_user_profile', 'edit_form');119 $this->hook( 'show_user_profile', 'edit_form');120 } 121 122 123 /** 124 * Returns the header url 112 foreach ( get_taxonomies( array( 'show_ui' => true ) ) as $_tax ) 113 $this->hook( "{$_tax}_edit_form", 'edit_form', 9 ); // Let's make us a bit more important than we are. 114 115 $this->hook( 'admin_init', 'add_settings_field' ); 116 $this->hook( 'show_user_profile', 'edit_form' ); 117 $this->hook( 'show_user_profile', 'edit_form' ); 118 } 119 120 121 /** 122 * Returns the header url. 125 123 * 126 124 * Returns the default header when we are on the blog page, the header … … 128 126 * filtered! 129 127 * 130 * @author Konstantin Obenland131 * @since 1.0 - 23.03.2011132 * @access public133 * 134 * @param string $header_url The header url as saved in the theme mods135 * 136 * @return string128 * @author Konstantin Obenland 129 * @since 1.0 - 23.03.2011 130 * @access public 131 * 132 * @param string $header_url The header url as saved in the theme mods. 133 * 134 * @return string 137 135 */ 138 136 public function theme_mod_header_image( $header_url ) { 139 137 140 if ( is_category() OR is_tag() OR is_tax() ) {138 if ( is_category() OR is_tag() OR is_tax() ) 141 139 $active_header = $this->get_active_tax_header(); 142 } 143 else if ( is_author() ) {140 141 else if ( is_author() ) 144 142 $active_header = $this->get_active_author_header(); 145 } 146 else if ( is_singular() ) {143 144 else if ( is_singular() ) 147 145 $active_header = $this->get_active_post_header(); 148 } 149 150 if ( isset($active_header) AND $active_header ) { 146 147 if ( isset( $active_header ) AND $active_header ) 151 148 $header_url = $active_header; 152 }153 149 154 150 return $header_url; … … 157 153 158 154 /** 159 * Adds the header post meta box 160 * 161 * @author Konstantin Obenland162 * @since 1.0 - 23.03.2011163 * @access public164 * 165 * @param string$post_type166 * 167 * @return void155 * Adds the header post meta box. 156 * 157 * @author Konstantin Obenland 158 * @since 1.0 - 23.03.2011 159 * @access public 160 * 161 * @param string $post_type 162 * 163 * @return void 168 164 */ 169 165 public function add_meta_boxes( $post_type ) { 170 add_meta_box( 'wp-display-header', __( 'Header'), array( &$this, 'display_meta_box' ), $post_type, 'normal', 'high' );171 } 172 173 174 /** 175 * Registers the stylesheet 166 add_meta_box( 'wp-display-header', __( 'Header' ), array( &$this, 'display_meta_box' ), $post_type, 'normal', 'high' ); 167 } 168 169 170 /** 171 * Registers the stylesheet. 176 172 * 177 173 * The stylesheets can easily be deregistered be calling 178 174 * <code>wp_deregister_style( 'wp-display-header' );</code> on the 179 * admin_init hook 180 * 181 * @author Konstantin Obenland182 * @since 1.5 - 22.01.2012183 * @access public184 * 185 * @return void175 * admin_init hook. 176 * 177 * @author Konstantin Obenland 178 * @since 1.5 - 22.01.2012 179 * @access public 180 * 181 * @return void 186 182 */ 187 183 public function register_scripts_styles() { 188 184 $plugin_data = get_plugin_data( __FILE__, false, false ); 189 $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';185 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 190 186 191 187 wp_register_style( … … 201 197 * Enqueues the CSS so the Header meta box looks nice :) 202 198 * 203 * @author Konstantin Obenland204 * @since 1.0 - 23.03.2011205 * @access public206 * 207 * @return void199 * @author Konstantin Obenland 200 * @since 1.0 - 23.03.2011 201 * @access public 202 * 203 * @return void 208 204 */ 209 205 public function admin_print_styles() { … … 214 210 /** 215 211 * Registers the setting and the settings field if it does not already 216 * exist 217 * 218 * @author Konstantin Obenland219 * @since 1.0 - 22.01.2012220 * @access public221 * 222 * return void212 * exist. 213 * 214 * @author Konstantin Obenland 215 * @since 1.0 - 22.01.2012 216 * @access public 217 * 218 * return void 223 219 */ 224 220 public function add_settings_field() { … … 226 222 add_settings_section( 227 223 $this->textdomain, 228 __( 'Header'),224 __( 'Header' ), 229 225 array( 230 226 &$this, … … 236 232 add_settings_field( 237 233 $this->textdomain, 238 __( 'Choose Header', 'wp-display-header-pro'),234 __( 'Choose Header', 'wp-display-header' ), 239 235 array( 240 236 &$this, … … 248 244 249 245 /** 250 * Adds a settings section to the category edit screen 251 * 252 * @author Konstantin Obenland253 * @since 1.0 - 22.01.2012254 * @access public255 * 256 * @param stdClass$object257 * 258 * @return void246 * Adds a settings section to the category edit screen. 247 * 248 * @author Konstantin Obenland 249 * @since 1.0 - 22.01.2012 250 * @access public 251 * 252 * @param stdClass $object 253 * 254 * @return void 259 255 */ 260 256 public function edit_form( $object ) { … … 264 260 265 261 /** 266 * Renders the content of the post meta box 267 * 268 * @author Konstantin Obenland269 * @since 1.0 - 22.01.2012270 * @access public271 * 272 * @param stdClass$post273 * 274 * @return void262 * Renders the content of the post meta box. 263 * 264 * @author Konstantin Obenland 265 * @since 1.0 - 22.01.2012 266 * @access public 267 * 268 * @param stdClass $post 269 * 270 * @return void 275 271 */ 276 272 public function display_meta_box( $post ) { 277 $active =$this->get_active_post_header( $post->ID, true );273 $active = $this->get_active_post_header( $post->ID, true ); 278 274 $this->header_selection_form( $active ); 279 275 } … … 284 280 * fields). 285 281 * 286 * @author Konstantin Obenland287 * @since 1.0 - 22.01.2012288 * @access public289 * 290 * return void282 * @author Konstantin Obenland 283 * @since 1.0 - 22.01.2012 284 * @access public 285 * 286 * return void 291 287 */ 292 288 public function settings_section_callback() { 293 294 switch ( get_current_screen()->base ) { 295 case 'profile': 296 _e( 'Select a header image for the author page.', 'wp-display-header-pro' ); 297 break; 298 299 case 'edit-tags': 300 _e( 'Select a header image for the taxonomy archive page.', 'wp-display-header-pro' ); 301 break; 302 } 303 } 304 305 306 /** 307 * Displays the settings field HTML 308 * 309 * @author Konstantin Obenland 310 * @since 1.0 - 22.01.2012 311 * @access public 312 * 313 * @return void 289 if ( 'profile' == get_current_screen()->base ) 290 _e( 'Select a header image for the author page.', 'wp-display-header' ); 291 292 elseif ( 'edit-tags' == get_current_screen()->base ) 293 _e( 'Select a header image for the taxonomy archive page.', 'wp-display-header' ); 294 } 295 296 297 /** 298 * Displays the settings field HTML. 299 * 300 * @author Konstantin Obenland 301 * @since 1.0 - 22.01.2012 302 * @access public 303 * 304 * @return void 314 305 */ 315 306 public function header_selection_callback() { 316 317 $active = ''; 307 $active = ''; 318 308 319 309 switch ( get_current_screen()->base ) { … … 325 315 case 'edit-tags': 326 316 global $tag; 327 if ( $active = get_option( 'wpdh_tax_meta', '' ) ) { 328 $active = isset($active[$tag->term_taxonomy_id]) ? $active[$tag->term_taxonomy_id] : ''; 329 } 317 if ( $active = get_option( 'wpdh_tax_meta', '' ) ) 318 $active = isset( $active[ $tag->term_taxonomy_id ] ) ? $active[ $tag->term_taxonomy_id ] : ''; 330 319 break; 331 320 } 332 321 333 322 // If no header set yet, get default header 334 if ( ! $active ) { 335 $active = get_theme_mod( 'header_image' ); 336 } 323 if ( ! $active ) 324 $active = get_theme_mod( 'header_image' ); 337 325 338 326 $this->header_selection_form( $active ); … … 341 329 342 330 /** 343 * Saves the selected header for this post 344 * 345 * @author Konstantin Obenland346 * @since 1.0 - 23.03.2011347 * @access public348 * 349 * @param int$post_ID350 * 351 * @return intPost ID331 * Saves the selected header for this post. 332 * 333 * @author Konstantin Obenland 334 * @since 1.0 - 23.03.2011 335 * @access public 336 * 337 * @param int $post_ID 338 * 339 * @return int Post ID 352 340 */ 353 341 public function save_post( $post_ID ) { 354 342 355 343 if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND 356 ( isset($_POST[$this->textdomain]) ) AND 357 ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) { 358 359 $value = ('random' == $_POST[$this->textdomain]) ? 'random' : esc_url_raw( $_POST[$this->textdomain] ); 360 361 if ( isset($_POST['wpdh-reset-header']) ) { 344 isset( $_POST[ $this->textdomain ] ) AND 345 wp_verify_nonce( $_POST["{$this->textdomain}-nonce"], $this->textdomain ) ) { 346 347 if ( isset( $_POST['wpdh-reset-header'] ) ) { 362 348 delete_post_meta( $post_ID, '_wpdh_display_header' ); 363 } 364 else { 349 350 } else { 351 $value = in_array( $_POST[ $this->textdomain ], array( 'random', 'remove-header' ) ) ? $_POST[ $this->textdomain ] : esc_url_raw( $_POST[ $this->textdomain ] ); 365 352 update_post_meta( $post_ID, '_wpdh_display_header', $value ); 366 353 } … … 373 360 374 361 /** 375 * Sanitizes the settings field input 376 * 377 * @author Konstantin Obenland378 * @since 2.0.0 - 12.03.2012379 * @access public380 * 381 * @param int$term_id382 * @param string$tt_id383 * @param string$taxonomy384 * 385 * @return intTerm ID362 * Sanitizes the settings field input. 363 * 364 * @author Konstantin Obenland 365 * @since 2.0.0 - 12.03.2012 366 * @access public 367 * 368 * @param int $term_id 369 * @param string $tt_id 370 * @param string $taxonomy 371 * 372 * @return int Term ID 386 373 */ 387 374 public function edit_term( $term_id, $tt_id, $taxonomy ) { 388 375 389 376 if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND 390 ( isset($_POST[$this->textdomain])) AND391 ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain)) ) {392 393 $term_meta =get_option( 'wpdh_tax_meta', array() );394 395 if ( isset( $_POST['wpdh-reset-header']) ) {396 unset( $term_meta[ $tt_id] );397 } 398 else {399 $term_meta[ $tt_id] = ('random' == $_POST[$this->textdomain]) ? 'random' : esc_url_raw( $_POST[$this->textdomain] );400 } 377 isset( $_POST[ $this->textdomain] ) AND 378 wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) { 379 380 $term_meta = get_option( 'wpdh_tax_meta', array() ); 381 382 if ( isset( $_POST['wpdh-reset-header'] ) ) 383 unset( $term_meta[ $tt_id ] ); 384 385 else 386 $term_meta[ $tt_id ] = in_array( $_POST[ $this->textdomain ], array( 'random', 'remove-header' ) ) ? $_POST[ $this->textdomain ] : esc_url_raw( $_POST[ $this->textdomain ] ); 387 401 388 update_option( 'wpdh_tax_meta', $term_meta ); 402 389 } … … 407 394 408 395 /** 409 * Sanitizes the settings field input 410 * 411 * @author Konstantin Obenland412 * @since 2.0.0 - 12.03.2012413 * @access public414 * 415 * @param int$user_id416 * 417 * @return intUser ID396 * Sanitizes the settings field input. 397 * 398 * @author Konstantin Obenland 399 * @since 2.0.0 - 12.03.2012 400 * @access public 401 * 402 * @param int $user_id 403 * 404 * @return int User ID 418 405 */ 419 406 public function update_user( $user_id ) { 420 407 421 408 if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND 422 ( isset($_POST[$this->textdomain])) AND423 ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain)) ) {424 425 if ( isset( $_POST['wpdh-reset-header']) ) {409 isset( $_POST[ $this->textdomain ] ) AND 410 wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain ) ) { 411 412 if ( isset( $_POST['wpdh-reset-header'] ) ) { 426 413 delete_user_meta( $user_id, $this->textdomain ); 427 } 428 else {429 $value = ('random' == $_POST[$this->textdomain]) ? 'random' : esc_url_raw( $_POST[$this->textdomain] );414 415 } else { 416 $value = in_array( $_POST[ $this->textdomain ], array( 'random', 'remove-header' ) ) ? $_POST[ $this->textdomain ] : esc_url_raw( $_POST[ $this->textdomain ] ); 430 417 update_user_meta( $user_id, $this->textdomain, $value ); 431 418 } … … 441 428 442 429 /** 443 * Displays the settings field HTML 444 * 445 * @author Konstantin Obenland446 * @since 1.0 - 22.01.2012447 * @access protected448 * 449 * @param string$active450 * 451 * @return void430 * Displays the settings field HTML. 431 * 432 * @author Konstantin Obenland 433 * @since 1.0 - 22.01.2012 434 * @access protected 435 * 436 * @param string $active 437 * 438 * @return void 452 439 */ 453 440 protected function header_selection_form( $active = '' ) { 454 441 455 $headers =$this->get_headers();456 457 if ( empty( $headers) ) {442 $headers = $this->get_headers(); 443 444 if ( empty( $headers ) ) { 458 445 printf( 459 __( 'The are no headers available. Please <a href="%s">upload a header image</a>!', 'wp-display-header'),460 ad min_url('themes.php?page=custom-header')446 __( 'The are no headers available. Please <a href="%s">upload a header image</a>!', 'wp-display-header' ), 447 add_query_arg( array( 'page' => 'custom-header' ), admin_url( 'themes.php' ) ) 461 448 ); 462 449 return; 463 450 } 464 451 465 foreach ( array_keys( $headers) as $header ) {466 foreach ( array( 'url', 'thumbnail_url') as $url ) {467 $headers[ $header][$url] =sprintf(468 $headers[ $header][$url],452 foreach ( array_keys( $headers ) as $header ) { 453 foreach ( array( 'url', 'thumbnail_url' ) as $url ) { 454 $headers[ $header ][ $url ] = sprintf( 455 $headers[ $header ][ $url ], 469 456 get_template_directory_uri(), 470 457 get_stylesheet_directory_uri() … … 477 464 <div class="available-headers"> 478 465 <div class="random-header"> 479 <label> 480 <input name="wp-display-header" type="radio" value="random" <?php checked( 'random', $active ); ?> /> 481 <?php _e( '<strong>Random:</strong> Show a different image on each page.' ); ?> 482 </label> 466 <p> 467 <label> 468 <input name="wp-display-header" type="radio" value="random" <?php checked( 'random', $active ); ?> /> 469 <?php _e( '<strong>Random:</strong> Show a different image on each page.' ); ?> 470 </label> 471 </p> 472 <p> 473 <label> 474 <input name="wp-display-header" type="radio" value="remove-header" <?php checked( 'remove-header', $active ); ?> /> 475 <?php _e( '<strong>None:</strong> Show no header image.' ); ?> 476 </label> 477 </p> 483 478 </div> 484 479 <?php 485 480 foreach ( $headers as $header_key => $header ) { 486 $header_url =$header['url'];487 $header_thumbnail =$header['thumbnail_url'];488 $header_desc = isset($header['description']) ?$header['description'] : '';481 $header_url = $header['url']; 482 $header_thumbnail = $header['thumbnail_url']; 483 $header_desc = isset( $header['description'] ) ? $header['description'] : ''; 489 484 ?> 490 485 <div class="default-header"> 491 486 <label> 492 <input name="wp-display-header" type="radio" value="<?php echo esc_attr( $header_url); ?>" <?php checked($header_url, $active); ?> />493 <img width="230" src="<?php echo esc_url( $header_thumbnail); ?>" alt="<?php echo esc_attr($header_desc); ?>" title="<?php echo esc_attr($header_desc); ?>" />487 <input name="wp-display-header" type="radio" value="<?php echo esc_attr( $header_url ); ?>" <?php checked( $header_url, $active ); ?> /> 488 <img width="230" src="<?php echo esc_url( $header_thumbnail ); ?>" alt="<?php echo esc_attr( $header_desc ); ?>" title="<?php echo esc_attr( $header_desc ); ?>" /> 494 489 </label> 495 490 </div> … … 505 500 506 501 /** 507 * Returns all registered headers 502 * Returns all registered headers. 508 503 * 509 504 * If there are uploaded headers via the WP Save Custom Header Plugin, they 510 505 * will be loaded, too. 511 506 * 512 * @author Konstantin Obenland513 * @since 1.0 - 23.03.2011514 * @access public515 * @global $_wp_default_headers516 * 517 * @return array507 * @author Konstantin Obenland 508 * @since 1.0 - 23.03.2011 509 * @access public 510 * @global $_wp_default_headers 511 * 512 * @return array 518 513 */ 519 514 protected function get_headers() { 520 515 global $_wp_default_headers; 521 516 522 // Cast $_wp_default_headers to an array, in case there are no headers523 517 $headers = array_merge( (array) $_wp_default_headers, get_uploaded_header_images() ); 524 518 525 return apply_filters( 'wpdh_get_headers', (array)$headers );526 } 527 528 529 /** 530 * Determines the active header for the post and returns the url 519 return (array) apply_filters( 'wpdh_get_headers', $headers ); 520 } 521 522 523 /** 524 * Determines the active header for the post and returns the url. 531 525 * 532 526 * The $raw variable is necessary so that the 'random' option stays 533 * selected in post edit screens 534 * 535 * @author Konstantin Obenland536 * @since 2.0.0 - 12.03.2012537 * @access protected538 * 539 * @param string$post_ID540 * @param boolean$raw541 * 542 * @return string527 * selected in post edit screens. 528 * 529 * @author Konstantin Obenland 530 * @since 2.0.0 - 12.03.2012 531 * @access protected 532 * 533 * @param string $post_ID 534 * @param boolean $raw 535 * 536 * @return string 543 537 */ 544 538 protected function get_active_post_header( $post_ID = 0, $raw = false ) { … … 546 540 if ( ! $post_ID ) { 547 541 global $post; 548 $post_ID =$post->ID;549 } 550 551 $active =get_post_meta( $post_ID, '_wpdh_display_header', true );542 $post_ID = $post->ID; 543 } 544 545 $active = get_post_meta( $post_ID, '_wpdh_display_header', true ); 552 546 553 547 return apply_filters( 'wpdh_get_active_post_header', $this->get_active_header( $active, $raw ) ); … … 556 550 557 551 /** 558 * Determines the active header for the category and returns the url 552 * Determines the active header for the category and returns the url. 559 553 * 560 554 * The $raw variable is necessary so that the 'random' option stays 561 * selected in post edit screens 562 * 563 * @author Konstantin Obenland564 * @since 2.0.0 - 12.03.2012565 * @access protected566 * 567 * @return string555 * selected in post edit screens. 556 * 557 * @author Konstantin Obenland 558 * @since 2.0.0 - 12.03.2012 559 * @access protected 560 * 561 * @return string 568 562 */ 569 563 protected function get_active_tax_header() { 570 564 571 565 if ( $active = get_option( 'wpdh_tax_meta', false ) ) { 572 $tt_id =get_queried_object()->term_taxonomy_id;573 $active = isset($active[$tt_id]) ? $active[$tt_id] : '';566 $tt_id = get_queried_object()->term_taxonomy_id; 567 $active = isset( $active[ $tt_id ] ) ? $active[ $tt_id ] : ''; 574 568 } 575 569 … … 579 573 580 574 /** 581 * Determines the active header for the author and returns the url 575 * Determines the active header for the author and returns the url. 582 576 * 583 577 * The $raw variable is necessary so that the 'random' option stays 584 * selected in post edit screens 585 * 586 * @author Konstantin Obenland587 * @since 2.0.0 - 12.03.2012588 * @access protected589 * 590 * @return string578 * selected in post edit screens. 579 * 580 * @author Konstantin Obenland 581 * @since 2.0.0 - 12.03.2012 582 * @access protected 583 * 584 * @return string 591 585 */ 592 586 protected function get_active_author_header() { 593 594 $active = get_user_meta( get_queried_object()->ID, $this->textdomain, true ); 595 587 $active = get_user_meta( get_queried_object()->ID, $this->textdomain, true ); 596 588 return apply_filters( 'wpdh_get_active_author_header', $this->get_active_header( $active ) ); 597 589 } … … 599 591 600 592 /** 601 * Determines the active header for the post and returns the url 593 * Determines the active header for the post and returns the url. 602 594 * 603 595 * The $raw variable is necessary so that the 'random' option stays 604 * selected in post edit screens 605 * 606 * @author Konstantin Obenland607 * @since 1.0 - 23.03.2011608 * @access public609 * 610 * @param string $headerHeader URL611 * @param boolean$raw612 * 613 * @return string596 * selected in post edit screens. 597 * 598 * @author Konstantin Obenland 599 * @since 1.0 - 23.03.2011 600 * @access public 601 * 602 * @param string $header Header URL 603 * @param boolean $raw 604 * 605 * @return string 614 606 */ 615 607 protected function get_active_header( $header, $raw = false ) { 616 608 617 if ( ! $header ) { 618 $header = get_theme_mod( 'header_image' ); 619 } 620 621 if ( is_random_header_image() OR 'random' == $header ) { 622 if ( $raw ) { 623 $header = 'random'; 624 } 625 else { 626 $headers = $this->get_headers(); 627 $header = sprintf( 628 $headers[array_rand($headers)]['url'], 629 get_template_directory_uri(), 630 get_stylesheet_directory_uri() 631 ); 632 } 609 if ( 'random' == $header AND ! $raw ) { 610 $headers = $this->get_headers(); 611 $header = sprintf( 612 $headers[ array_rand( $headers ) ]['url'], 613 get_template_directory_uri(), 614 get_stylesheet_directory_uri() 615 ); 633 616 } 634 617 635 618 return apply_filters( 'wpdh_get_active_header', $header ); 636 619 } 637 638 } // End of class Obenland_Wp_Display_Header 620 } // End of class Obenland_Wp_Display_Header. 639 621 640 622 641 623 /** 642 * Instantiates the class if current theme supports Custom Headers 624 * Instantiates the class if current theme supports Custom Headers. 643 625 * 644 * @author Konstantin Obenland645 * @since 1.2 - 03.05.2011626 * @author Konstantin Obenland 627 * @since 1.2 - 03.05.2011 646 628 * 647 * @return void629 * @return void 648 630 */ 649 631 function Obenland_wpdh_instantiate() { 650 632 651 if ( current_theme_supports( 'custom-header') ) {633 if ( current_theme_supports( 'custom-header' ) ) 652 634 new Obenland_Wp_Display_Header; 653 }654 635 } 655 636 add_action( 'init', 'Obenland_wpdh_instantiate', 1 );
Note: See TracChangeset
for help on using the changeset viewer.