SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | add_action( 'after_setup_theme', 'dr_post_theme_setup' ); | |
| 3 | if ( !function_exists( 'dr_post_theme_setup' ) ): | |
| 4 | function dr_post_theme_setup() {
| |
| 5 | ||
| 6 | /* Remove the twenty eleven default Headers */ | |
| 7 | function dr_update_twenty_eleven_headers(){
| |
| 8 | unregister_default_headers( array( | |
| 9 | 'wheel', | |
| 10 | 'shore', | |
| 11 | 'trolley', | |
| 12 | 'pine-cone', | |
| 13 | 'chessboard', | |
| 14 | 'lanterns', | |
| 15 | 'willow' , | |
| 16 | 'hanoi') | |
| 17 | ); | |
| 18 | ||
| 19 | // Register default custom headers packaged with the child theme. | |
| 20 | $headers = dr_default_headers(); | |
| 21 | if( $headers ) register_default_headers( $headers ); | |
| 22 | } | |
| 23 | add_action( 'after_setup_theme', 'dr_update_twenty_eleven_headers', 11 ); | |
| 24 | } | |
| 25 | endif; | |
| 26 | ||
| 27 | // read through the /images/headers/ to get a list of custom headers. | |
| 28 | function dr_default_headers(){
| |
| 29 | // Create an empty array | |
| 30 | $list = array(); | |
| 31 | // Get the file directory path and url | |
| 32 | $path = get_stylesheet_directory() .'/images/headers/'; | |
| 33 | $url = get_stylesheet_directory_uri() .'/images/headers/'; | |
| 34 | // Open the /images/headers/ folder | |
| 35 | $dir_handle = @opendir($path) or die("Unable to open $path");
| |
| 36 | // Loop through the header images | |
| 37 | while($file = readdir($dir_handle)){
| |
| 38 | if($file == "." || $file == ".."){continue;}
| |
| 39 | $filename = explode(".",$file);
| |
| 40 | $cnt = count($filename); $cnt--; $ext = $filename[$cnt]; | |
| 41 | // Is the image a jpg or png | |
| 42 | if(strtolower($ext) == ('png' || 'jpg')){
| |
| 43 | // if the image is post fixed with -thumbnail add it to the array | |
| 44 | if ( strpos($file, '-thumbnail') > 0 ) {
| |
| 45 | $name = substr($file, 0, strpos($file, '-thumbnail') ); | |
| 46 | $list[$name] = array( | |
| 47 | 'url' => $url .$name .'.' .$ext, | |
| 48 | 'thumbnail_url' => $url .$file, | |
| 49 | 'description' => __( ucwords( str_replace("-"," ",$name) ), 'twentyeleven' )
| |
| 50 | ); | |
| 51 | } | |
| 52 | } | |
| 53 | } | |
| 54 | return $list; | |
| 55 | } |