Plugin Directory

Changeset 690451


Ignore:
Timestamp:
04/02/2013 04:33:22 AM (13 years ago)
Author:
kobenland
Message:

Cast $_wp_default_headers to an array, in case there are no headers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-display-header/trunk/wp-display-header.php

    r541921 r690451  
    2626
    2727class Obenland_Wp_Display_Header extends Obenland_Wp_Plugins_v200 {
    28    
    29    
     28
     29
    3030    ///////////////////////////////////////////////////////////////////////////
    3131    // METHODS, PUBLIC
     
    4848            'donate_link_id'    =>  'MWUA92KA2TL6Q'
    4949        ));
    50        
     50
    5151        load_plugin_textdomain( 'wp-display-header' , false, 'wp-display-header/lang' );
    5252
     
    5454    }
    5555
    56    
     56
    5757    /**
    5858     * Checks if the current theme supports custom header functionality and bails
     
    6868    public static function activation() {
    6969        load_plugin_textdomain( 'wp-display-header' , false, 'wp-display-header/lang' );
    70        
     70
    7171        if ( ! current_theme_supports( 'custom-header' ) ) {
    7272            wp_die( __( 'Your current theme does not support Custom Headers.', 'wp-display-header' ), '', array(
     
    7474            ) );
    7575        }
    76        
     76
    7777        if ( version_compare( get_bloginfo('version'), '3.2', '<' ) ) {
    7878            wp_die( __( 'WP Display Headers requires WordPress version 3.2 or later.', 'wp-display-header' ), '', array(
     
    8181        }
    8282    }
    83    
    84    
     83
     84
    8585    /**
    8686     * Hooks in all the hooks :)
     
    9696        $this->hook( 'theme_mod_header_image' );
    9797        $this->hook( 'add_meta_boxes' );
    98        
     98
    9999        // Save info
    100100        $this->hook( 'save_post' );
     
    102102        $this->hook( 'personal_options_update',             'update_user' );
    103103        $this->hook( 'edit_user_profile_update',            'update_user' );
    104        
     104
    105105        // Styles
    106106        $this->hook( 'admin_init', 'register_scripts_styles', 9 ); // Set priority to 9, so they can easily be deregistered
     
    110110        $this->hook( 'admin_print_styles-profile.php',      'admin_print_styles' );
    111111        $this->hook( 'admin_print_styles-user-edit.php',    'admin_print_styles' );
    112    
     112
    113113        // Edit forms
    114114        foreach ( get_taxonomies( array('show_ui' => true) ) as $_tax ) {
     
    120120    }
    121121
    122    
     122
    123123    /**
    124124     * Returns the header url
     
    137137     */
    138138    public function theme_mod_header_image( $header_url ) {
    139        
     139
    140140        if ( is_category() OR is_tag() OR is_tax() ) {
    141141            $active_header = $this->get_active_tax_header();
     
    147147            $active_header = $this->get_active_post_header();
    148148        }
    149        
     149
    150150        if ( isset($active_header) AND $active_header ) {
    151151            $header_url = $active_header;
     
    155155    }
    156156
    157  
     157
    158158    /**
    159159     * Adds the header post meta box
     
    170170        add_meta_box( 'wp-display-header', __('Header'), array( &$this, 'display_meta_box' ), $post_type, 'normal', 'high' );
    171171    }
    172    
    173    
     172
     173
    174174    /**
    175175     * Registers the stylesheet
     
    188188        $plugin_data = get_plugin_data( __FILE__, false, false );
    189189        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';
    190        
     190
    191191        wp_register_style(
    192192            $this->textdomain,
     
    196196        );
    197197    }
    198    
    199    
     198
     199
    200200    /**
    201201     * Enqueues the CSS so the Header meta box looks nice :)
     
    210210        wp_enqueue_style( $this->textdomain );
    211211    }
    212    
    213    
     212
     213
    214214    /**
    215215     * Registers the setting and the settings field if it does not already
     
    223223     */
    224224    public function add_settings_field() {
    225            
     225
    226226        add_settings_section(
    227227            $this->textdomain,
     
    233233            $this->textdomain
    234234        );
    235        
     235
    236236        add_settings_field(
    237237            $this->textdomain,
     
    245245        );
    246246    }
    247    
    248    
     247
     248
    249249    /**
    250250     * Adds a settings section to the category edit screen
     
    262262    }
    263263
    264    
     264
    265265    /**
    266266     * Renders the content of the post meta box
     
    278278        $this->header_selection_form( $active );
    279279    }
    280    
    281    
     280
     281
    282282    /**
    283283     * Echos out a description at the top of the section (between heading and
     
    296296                _e( 'Select a header image for the author page.', 'wp-display-header-pro' );
    297297                break;
    298            
     298
    299299            case 'edit-tags':
    300300                _e( 'Select a header image for the taxonomy archive page.', 'wp-display-header-pro' );
     
    302302        }
    303303    }
    304    
    305    
     304
     305
    306306    /**
    307307     * Displays the settings field HTML
     
    314314     */
    315315    public function header_selection_callback() {
    316        
     316
    317317        $active =   '';
    318        
     318
    319319        switch ( get_current_screen()->base ) {
    320320            case 'profile':
     
    322322                $active = get_user_meta( $profileuser->ID, $this->textdomain, true );
    323323                break;
    324            
     324
    325325            case 'edit-tags':
    326326                global $tag;
     
    330330                break;
    331331        }
    332        
     332
    333333        // If no header set yet, get default header
    334334        if ( ! $active ) {
    335335            $active =   get_theme_mod( 'header_image' );
    336336        }
    337        
     337
    338338        $this->header_selection_form( $active );
    339339    }
    340  
    341  
     340
     341
    342342    /**
    343343     * Saves the selected header for this post
     
    352352     */
    353353    public function save_post( $post_ID ) {
    354        
     354
    355355        if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND
    356356            ( isset($_POST[$this->textdomain]) ) AND
    357357            ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) {
    358            
     358
    359359            $value  =   ('random' == $_POST[$this->textdomain]) ? 'random' : esc_url_raw( $_POST[$this->textdomain] );
    360            
     360
    361361            if ( isset($_POST['wpdh-reset-header']) ) {
    362362                delete_post_meta( $post_ID, '_wpdh_display_header' );
     
    366366            }
    367367        }
    368        
     368
    369369        return $post_ID;
    370370    }
    371    
    372 
    373    
     371
     372
     373
    374374    /**
    375375     * Sanitizes the settings field input
     
    390390            ( isset($_POST[$this->textdomain]) ) AND
    391391            ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) {
    392                
     392
    393393            $term_meta          =   get_option( 'wpdh_tax_meta', array() );
    394            
     394
    395395            if ( isset($_POST['wpdh-reset-header']) ) {
    396396                unset( $term_meta[$tt_id] );
     
    401401            update_option( 'wpdh_tax_meta', $term_meta );
    402402        }
    403        
     403
    404404        return $term_id;
    405405    }
    406    
    407    
     406
     407
    408408    /**
    409409     * Sanitizes the settings field input
     
    418418     */
    419419    public function update_user( $user_id ) {
    420        
     420
    421421        if ( ( ! defined('DOING_AUTOSAVE') OR ! DOING_AUTOSAVE ) AND
    422422            ( isset($_POST[$this->textdomain]) ) AND
    423423            ( wp_verify_nonce($_POST["{$this->textdomain}-nonce"], $this->textdomain) ) ) {
    424            
     424
    425425            if ( isset($_POST['wpdh-reset-header']) ) {
    426426                delete_user_meta( $user_id, $this->textdomain );
     
    431431            }
    432432        }
    433        
     433
    434434        return $user_id;
    435435    }
    436    
    437    
     436
     437
    438438    ///////////////////////////////////////////////////////////////////////////
    439439    // METHODS, PROTECTED
    440440    ///////////////////////////////////////////////////////////////////////////
    441    
     441
    442442    /**
    443443     * Displays the settings field HTML
     
    452452     */
    453453    protected function header_selection_form( $active = '' ) {
    454        
     454
    455455        $headers    =   $this->get_headers();
    456        
     456
    457457        if ( empty($headers) ) {
    458458            printf(
     
    462462            return;
    463463        }
    464    
     464
    465465        foreach ( array_keys($headers) as $header ) {
    466466            foreach ( array('url', 'thumbnail_url') as $url ) {
     
    496496            <?php } ?>
    497497            <div class="clear"></div>
    498            
     498
    499499            <?php submit_button( __( 'Restore Original Header Image' ), 'button', 'wpdh-reset-header', false ); ?>
    500500            <span class="description"><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></span>
     
    502502        <?php
    503503    }
    504    
    505    
     504
     505
    506506    /**
    507507     * Returns all registered headers
     
    520520        global $_wp_default_headers;
    521521
     522        // Cast $_wp_default_headers to an array, in case there are no headers
    522523        $headers = array_merge( (array) $_wp_default_headers, get_uploaded_header_images() );
    523        
     524
    524525        return apply_filters( 'wpdh_get_headers', (array) $headers );
    525526    }
    526527
    527    
     528
    528529    /**
    529530     * Determines the active header for the post and returns the url
     
    542543     */
    543544    protected function get_active_post_header( $post_ID = 0, $raw = false ) {
    544        
     545
    545546        if ( ! $post_ID ) {
    546547            global $post;
    547548            $post_ID    =   $post->ID;
    548549        }
    549        
     550
    550551        $active =   get_post_meta( $post_ID, '_wpdh_display_header', true );
    551        
     552
    552553        return apply_filters( 'wpdh_get_active_post_header', $this->get_active_header( $active, $raw ) );
    553554    }
    554    
    555    
     555
     556
    556557    /**
    557558     * Determines the active header for the category and returns the url
     
    567568     */
    568569    protected function get_active_tax_header() {
    569        
     570
    570571        if ( $active = get_option( 'wpdh_tax_meta', false ) ) {
    571572            $tt_id  =   get_queried_object()->term_taxonomy_id;
    572573            $active =   isset($active[$tt_id]) ? $active[$tt_id] : '';
    573574        }
    574        
     575
    575576        return apply_filters( 'wpdh_get_active_tax_header', $this->get_active_header( $active ) );
    576577    }
    577    
    578    
     578
     579
    579580    /**
    580581     * Determines the active header for the author and returns the url
     
    590591     */
    591592    protected function get_active_author_header() {
    592        
     593
    593594        $active =   get_user_meta( get_queried_object()->ID, $this->textdomain, true );
    594        
     595
    595596        return apply_filters( 'wpdh_get_active_author_header', $this->get_active_header( $active ) );
    596597    }
    597    
    598    
     598
     599
    599600    /**
    600601     * Determines the active header for the post and returns the url
     
    625626        return apply_filters( 'wpdh_get_active_header', $header );
    626627    }
    627    
     628
    628629} // End of class Obenland_Wp_Display_Header
    629630
Note: See TracChangeset for help on using the changeset viewer.