Changeset 690451
- Timestamp:
- 04/02/2013 04:33:22 AM (13 years ago)
- File:
-
- 1 edited
-
wp-display-header/trunk/wp-display-header.php (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-display-header/trunk/wp-display-header.php
r541921 r690451 26 26 27 27 class Obenland_Wp_Display_Header extends Obenland_Wp_Plugins_v200 { 28 29 28 29 30 30 /////////////////////////////////////////////////////////////////////////// 31 31 // METHODS, PUBLIC … … 48 48 'donate_link_id' => 'MWUA92KA2TL6Q' 49 49 )); 50 50 51 51 load_plugin_textdomain( 'wp-display-header' , false, 'wp-display-header/lang' ); 52 52 … … 54 54 } 55 55 56 56 57 57 /** 58 58 * Checks if the current theme supports custom header functionality and bails … … 68 68 public static function activation() { 69 69 load_plugin_textdomain( 'wp-display-header' , false, 'wp-display-header/lang' ); 70 70 71 71 if ( ! current_theme_supports( 'custom-header' ) ) { 72 72 wp_die( __( 'Your current theme does not support Custom Headers.', 'wp-display-header' ), '', array( … … 74 74 ) ); 75 75 } 76 76 77 77 if ( version_compare( get_bloginfo('version'), '3.2', '<' ) ) { 78 78 wp_die( __( 'WP Display Headers requires WordPress version 3.2 or later.', 'wp-display-header' ), '', array( … … 81 81 } 82 82 } 83 84 83 84 85 85 /** 86 86 * Hooks in all the hooks :) … … 96 96 $this->hook( 'theme_mod_header_image' ); 97 97 $this->hook( 'add_meta_boxes' ); 98 98 99 99 // Save info 100 100 $this->hook( 'save_post' ); … … 102 102 $this->hook( 'personal_options_update', 'update_user' ); 103 103 $this->hook( 'edit_user_profile_update', 'update_user' ); 104 104 105 105 // Styles 106 106 $this->hook( 'admin_init', 'register_scripts_styles', 9 ); // Set priority to 9, so they can easily be deregistered … … 110 110 $this->hook( 'admin_print_styles-profile.php', 'admin_print_styles' ); 111 111 $this->hook( 'admin_print_styles-user-edit.php', 'admin_print_styles' ); 112 112 113 113 // Edit forms 114 114 foreach ( get_taxonomies( array('show_ui' => true) ) as $_tax ) { … … 120 120 } 121 121 122 122 123 123 /** 124 124 * Returns the header url … … 137 137 */ 138 138 public function theme_mod_header_image( $header_url ) { 139 139 140 140 if ( is_category() OR is_tag() OR is_tax() ) { 141 141 $active_header = $this->get_active_tax_header(); … … 147 147 $active_header = $this->get_active_post_header(); 148 148 } 149 149 150 150 if ( isset($active_header) AND $active_header ) { 151 151 $header_url = $active_header; … … 155 155 } 156 156 157 157 158 158 /** 159 159 * Adds the header post meta box … … 170 170 add_meta_box( 'wp-display-header', __('Header'), array( &$this, 'display_meta_box' ), $post_type, 'normal', 'high' ); 171 171 } 172 173 172 173 174 174 /** 175 175 * Registers the stylesheet … … 188 188 $plugin_data = get_plugin_data( __FILE__, false, false ); 189 189 $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : ''; 190 190 191 191 wp_register_style( 192 192 $this->textdomain, … … 196 196 ); 197 197 } 198 199 198 199 200 200 /** 201 201 * Enqueues the CSS so the Header meta box looks nice :) … … 210 210 wp_enqueue_style( $this->textdomain ); 211 211 } 212 213 212 213 214 214 /** 215 215 * Registers the setting and the settings field if it does not already … … 223 223 */ 224 224 public function add_settings_field() { 225 225 226 226 add_settings_section( 227 227 $this->textdomain, … … 233 233 $this->textdomain 234 234 ); 235 235 236 236 add_settings_field( 237 237 $this->textdomain, … … 245 245 ); 246 246 } 247 248 247 248 249 249 /** 250 250 * Adds a settings section to the category edit screen … … 262 262 } 263 263 264 264 265 265 /** 266 266 * Renders the content of the post meta box … … 278 278 $this->header_selection_form( $active ); 279 279 } 280 281 280 281 282 282 /** 283 283 * Echos out a description at the top of the section (between heading and … … 296 296 _e( 'Select a header image for the author page.', 'wp-display-header-pro' ); 297 297 break; 298 298 299 299 case 'edit-tags': 300 300 _e( 'Select a header image for the taxonomy archive page.', 'wp-display-header-pro' ); … … 302 302 } 303 303 } 304 305 304 305 306 306 /** 307 307 * Displays the settings field HTML … … 314 314 */ 315 315 public function header_selection_callback() { 316 316 317 317 $active = ''; 318 318 319 319 switch ( get_current_screen()->base ) { 320 320 case 'profile': … … 322 322 $active = get_user_meta( $profileuser->ID, $this->textdomain, true ); 323 323 break; 324 324 325 325 case 'edit-tags': 326 326 global $tag; … … 330 330 break; 331 331 } 332 332 333 333 // If no header set yet, get default header 334 334 if ( ! $active ) { 335 335 $active = get_theme_mod( 'header_image' ); 336 336 } 337 337 338 338 $this->header_selection_form( $active ); 339 339 } 340 341 340 341 342 342 /** 343 343 * Saves the selected header for this post … … 352 352 */ 353 353 public function save_post( $post_ID ) { 354 354 355 355 if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND 356 356 ( isset($_POST[$this->textdomain]) ) AND 357 357 ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) { 358 358 359 359 $value = ('random' == $_POST[$this->textdomain]) ? 'random' : esc_url_raw( $_POST[$this->textdomain] ); 360 360 361 361 if ( isset($_POST['wpdh-reset-header']) ) { 362 362 delete_post_meta( $post_ID, '_wpdh_display_header' ); … … 366 366 } 367 367 } 368 368 369 369 return $post_ID; 370 370 } 371 372 373 371 372 373 374 374 /** 375 375 * Sanitizes the settings field input … … 390 390 ( isset($_POST[$this->textdomain]) ) AND 391 391 ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) { 392 392 393 393 $term_meta = get_option( 'wpdh_tax_meta', array() ); 394 394 395 395 if ( isset($_POST['wpdh-reset-header']) ) { 396 396 unset( $term_meta[$tt_id] ); … … 401 401 update_option( 'wpdh_tax_meta', $term_meta ); 402 402 } 403 403 404 404 return $term_id; 405 405 } 406 407 406 407 408 408 /** 409 409 * Sanitizes the settings field input … … 418 418 */ 419 419 public function update_user( $user_id ) { 420 420 421 421 if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND 422 422 ( isset($_POST[$this->textdomain]) ) AND 423 423 ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) { 424 424 425 425 if ( isset($_POST['wpdh-reset-header']) ) { 426 426 delete_user_meta( $user_id, $this->textdomain ); … … 431 431 } 432 432 } 433 433 434 434 return $user_id; 435 435 } 436 437 436 437 438 438 /////////////////////////////////////////////////////////////////////////// 439 439 // METHODS, PROTECTED 440 440 /////////////////////////////////////////////////////////////////////////// 441 441 442 442 /** 443 443 * Displays the settings field HTML … … 452 452 */ 453 453 protected function header_selection_form( $active = '' ) { 454 454 455 455 $headers = $this->get_headers(); 456 456 457 457 if ( empty($headers) ) { 458 458 printf( … … 462 462 return; 463 463 } 464 464 465 465 foreach ( array_keys($headers) as $header ) { 466 466 foreach ( array('url', 'thumbnail_url') as $url ) { … … 496 496 <?php } ?> 497 497 <div class="clear"></div> 498 498 499 499 <?php submit_button( __( 'Restore Original Header Image' ), 'button', 'wpdh-reset-header', false ); ?> 500 500 <span class="description"><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></span> … … 502 502 <?php 503 503 } 504 505 504 505 506 506 /** 507 507 * Returns all registered headers … … 520 520 global $_wp_default_headers; 521 521 522 // Cast $_wp_default_headers to an array, in case there are no headers 522 523 $headers = array_merge( (array) $_wp_default_headers, get_uploaded_header_images() ); 523 524 524 525 return apply_filters( 'wpdh_get_headers', (array) $headers ); 525 526 } 526 527 527 528 528 529 /** 529 530 * Determines the active header for the post and returns the url … … 542 543 */ 543 544 protected function get_active_post_header( $post_ID = 0, $raw = false ) { 544 545 545 546 if ( ! $post_ID ) { 546 547 global $post; 547 548 $post_ID = $post->ID; 548 549 } 549 550 550 551 $active = get_post_meta( $post_ID, '_wpdh_display_header', true ); 551 552 552 553 return apply_filters( 'wpdh_get_active_post_header', $this->get_active_header( $active, $raw ) ); 553 554 } 554 555 555 556 556 557 /** 557 558 * Determines the active header for the category and returns the url … … 567 568 */ 568 569 protected function get_active_tax_header() { 569 570 570 571 if ( $active = get_option( 'wpdh_tax_meta', false ) ) { 571 572 $tt_id = get_queried_object()->term_taxonomy_id; 572 573 $active = isset($active[$tt_id]) ? $active[$tt_id] : ''; 573 574 } 574 575 575 576 return apply_filters( 'wpdh_get_active_tax_header', $this->get_active_header( $active ) ); 576 577 } 577 578 578 579 579 580 /** 580 581 * Determines the active header for the author and returns the url … … 590 591 */ 591 592 protected function get_active_author_header() { 592 593 593 594 $active = get_user_meta( get_queried_object()->ID, $this->textdomain, true ); 594 595 595 596 return apply_filters( 'wpdh_get_active_author_header', $this->get_active_header( $active ) ); 596 597 } 597 598 598 599 599 600 /** 600 601 * Determines the active header for the post and returns the url … … 625 626 return apply_filters( 'wpdh_get_active_header', $header ); 626 627 } 627 628 628 629 } // End of class Obenland_Wp_Display_Header 629 630
Note: See TracChangeset
for help on using the changeset viewer.