Ticket #18375: 18375.patch
File 18375.patch, 8.4 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/meta-boxes.php
569 569 <?php 570 570 } // end empty pages check 571 571 } // end hierarchical check. 572 if ( 'page' == $post->post_type && 0 != count( get_page_templates() ) ) {572 if ( 0 != count( get_post_type_templates( $post->post_type ) ) ) { 573 573 $template = !empty($post->page_template) ? $post->page_template : false; 574 574 ?> 575 575 <p><strong><?php _e('Template') ?></strong></p> 576 <label class="screen-reader-text" for="page_template"><?php _e('Page Template') ?></label><select name="page_template" id="page_template"> 577 <option value='default'><?php _e('Default Template'); ?></option> 578 <?php page_template_dropdown($template); ?> 576 <label class="screen-reader-text" for="page_template"><?php _e('Template') ?></label> 577 <select name="page_template" id="page_template"> 578 <option value='default'><?php _e('Default Template'); ?></option> 579 <?php post_type_template_dropdown( $template, $post->post_type ); ?> 579 580 </select> 580 581 <?php 581 582 } ?> -
wp-admin/includes/post.php
476 476 477 477 $post = get_post( $id, OBJECT, 'edit' ); 478 478 479 if ( $post->post_type == 'page' ) 480 $post->page_template = get_post_meta( $id, '_wp_page_template', true ); 479 $post->page_template = get_post_meta( $id, '_wp_page_template', true ); 481 480 482 481 return $post; 483 482 } -
wp-admin/includes/template.php
291 291 if ( $post_type_object->hierarchical ) 292 292 echo '<div class="post_parent">' . $post->post_parent . '</div>'; 293 293 294 if ( $post->post_type == 'page' ) 295 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; 294 echo '<div class="page_template">' . esc_html( get_post_meta( $post->ID, '_wp_page_template', true ) ) . '</div>'; 296 295 297 296 if ( $post_type_object->hierarchical ) 298 297 echo '<div class="menu_order">' . $post->menu_order . '</div>'; … … 647 646 } 648 647 649 648 /** 650 * {@internal Missing Short Description}}649 * Display dropdown options for template files from the active theme 651 650 * 652 * @since 1.5.0651 * @since 3.3 653 652 * 654 * @param unknown_type $default 653 * @param string $default Template file to select by default 654 * @param string $post_type Post type 655 655 */ 656 function p age_template_dropdown( $default = '' ) {657 $templates = get_p age_templates();656 function post_type_template_dropdown( $default = '', $post_type = 'page' ) { 657 $templates = get_post_type_templates( $post_type ); 658 658 ksort( $templates ); 659 foreach ( array_keys( $templates ) as $template )660 :if ( $default == $templates[$template] )659 foreach ( array_keys( $templates ) as $template ) { 660 if ( $default == $templates[$template] ) 661 661 $selected = " selected='selected'"; 662 662 else 663 663 $selected = ''; 664 echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";665 endforeach;664 echo "\n\t<option value='" . $templates[$template] . "' $selected>$template</option>"; 665 } 666 666 } 667 667 668 668 /** 669 * Display dropdown options for page template files from the active theme 670 * 671 * @since 1.5.0 672 * 673 * @param string $default Template to select by default 674 */ 675 function page_template_dropdown( $default = '' ) { 676 post_type_template_dropdown( $default, 'page' ); 677 } 678 679 /** 669 680 * {@internal Missing Short Description}} 670 681 * 671 682 * @since 1.5.0 -
wp-admin/includes/theme.php
159 159 } 160 160 161 161 /** 162 * Get the Page Templates available in this theme162 * Get the templates available in this theme for the given post type 163 163 * 164 * @since 1.5.0164 * @since 3.3 165 165 * 166 166 * @return array Key is the template name, value is the filename of the template 167 167 */ 168 function get_page_templates() { 168 function get_post_type_templates( $post_type ) { 169 static $post_type_templates; 170 171 if ( isset( $post_type_templates ) ) { 172 if ( isset( $post_type_templates[$post_type] ) ) 173 return $post_type_templates[$post_type]; 174 else 175 return array(); 176 } 177 169 178 $themes = get_themes(); 170 179 $theme = get_current_theme(); 171 180 $templates = $themes[$theme]['Template Files']; 172 $p age_templates = array();181 $post_type_templates = array(); 173 182 174 183 if ( is_array( $templates ) ) { 175 $base = array( trailingslashit( get_template_directory()), trailingslashit(get_stylesheet_directory()) );184 $base = array( trailingslashit( get_template_directory() ), trailingslashit( get_stylesheet_directory() ) ); 176 185 177 186 foreach ( $templates as $template ) { 178 $basename = str_replace( $base, '', $template);187 $basename = str_replace( $base, '', $template ); 179 188 180 189 // don't allow template files in subdirectories 181 if ( false !== strpos( $basename, '/') )190 if ( false !== strpos( $basename, '/' ) ) 182 191 continue; 183 192 184 193 if ( 'functions.php' == $basename ) 185 194 continue; 186 195 187 $template_data = implode( '', file( $template )); 196 $template_data = implode( '', file( $template ) ); 197 $name = ''; 188 198 189 $name = '';190 199 if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) 191 $name = _cleanup_header_comment($name[1]);200 $name = trim( _cleanup_header_comment( $name[1] ) ); 192 201 202 if ( preg_match( '|Template Type:(.*)$|mi', $template_data, $type ) ) 203 $types = explode( ',', _cleanup_header_comment( $type[1] ) ); 204 else 205 $types = array( 'page' ); 206 193 207 if ( !empty( $name ) ) { 194 $page_templates[trim( $name )] = $basename; 208 foreach ( $types as $type ) { 209 $type = trim( $type ); 210 if ( !isset( $post_type_templates[$type] ) ) 211 $post_type_templates[$type] = array(); 212 $post_type_templates[$type][$name] = $basename; 213 } 195 214 } 196 215 } 197 216 } 198 217 199 return $page_templates; 218 if ( isset( $post_type_templates[$post_type] ) ) 219 return $post_type_templates[$post_type]; 220 else 221 return array(); 200 222 } 201 223 202 224 /** 225 * Get the Page Templates available in this theme 226 * 227 * @since 1.5.0 228 * 229 * @return array Key is the template name, value is the filename of the template 230 */ 231 function get_page_templates() { 232 return get_post_type_templates( 'page' ); 233 } 234 235 /** 203 236 * Tidies a filename for url display by the theme editor. 204 237 * 205 238 * @since 2.9.0 -
wp-includes/post-template.php
1235 1235 * @return bool False on failure, true if success. 1236 1236 */ 1237 1237 function is_page_template($template = '') { 1238 if (!is_page()) {1239 return false;1240 }1241 1238 1242 1239 global $wp_query; 1243 1240 1244 $p age= $wp_query->get_queried_object();1245 $custom_fields = get_post_custom_values('_wp_page_template',$p age->ID);1241 $post = $wp_query->get_queried_object(); 1242 $custom_fields = get_post_custom_values('_wp_page_template',$post->ID); 1246 1243 $page_template = $custom_fields[0]; 1247 1244 1248 1245 // We have no argument passed so just see if a page_template has been specified -
wp-includes/post.php
2621 2621 2622 2622 $post = get_post($post_ID); 2623 2623 2624 if ( !empty($page_template) && 'page' == $data['post_type']) {2624 if ( !empty($page_template) ) { 2625 2625 $post->page_template = $page_template; 2626 $page_templates = get_p age_templates();2626 $page_templates = get_post_type_templates( $post->post_type ); 2627 2627 if ( 'default' != $page_template && !in_array($page_template, $page_templates) ) { 2628 2628 if ( $wp_error ) 2629 2629 return new WP_Error('invalid_page_template', __('The page template is invalid.')); -
wp-includes/theme.php
1001 1001 */ 1002 1002 function get_single_template() { 1003 1003 $object = get_queried_object(); 1004 $template = get_post_meta( $object->ID, '_wp_page_template', true ); 1004 1005 1006 if ( 'default' == $template ) 1007 $template = ''; 1008 1005 1009 $templates = array(); 1010 if ( !empty($template) && !validate_file($template) ) 1011 $templates[] = $template; 1006 1012 1007 1013 $templates[] = "single-{$object->post_type}.php"; 1008 1014 $templates[] = "single.php";