Introduce get_page_template_slug( $id = null ) to return a page's template (like "showcase.php"). Returns false if post ID is not a page, and an empty string for the default page template. Use the function across core. props billerickson for initial patch. fixes #18750.
git-svn-id: http://svn.automattic.com/wordpress/trunk@20075 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
73938cd0a9
commit
ae8af5d0dd
|
@ -1177,7 +1177,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
||||||
// Get the author info.
|
// Get the author info.
|
||||||
$author = get_userdata($page->post_author);
|
$author = get_userdata($page->post_author);
|
||||||
|
|
||||||
$page_template = get_post_meta( $page->ID, '_wp_page_template', true );
|
$page_template = get_page_template_slug( $page->ID );
|
||||||
if ( empty( $page_template ) )
|
if ( empty( $page_template ) )
|
||||||
$page_template = 'default';
|
$page_template = 'default';
|
||||||
|
|
||||||
|
|
|
@ -487,7 +487,7 @@ function get_body_class( $class = '' ) {
|
||||||
}
|
}
|
||||||
if ( is_page_template() ) {
|
if ( is_page_template() ) {
|
||||||
$classes[] = 'page-template';
|
$classes[] = 'page-template';
|
||||||
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
|
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_page_template_slug( $page_id ) ) );
|
||||||
} else {
|
} else {
|
||||||
$classes[] = 'page-template-default';
|
$classes[] = 'page-template-default';
|
||||||
}
|
}
|
||||||
|
@ -1241,29 +1241,43 @@ function get_the_password_form() {
|
||||||
* @param string $template The specific template name if specific matching is required.
|
* @param string $template The specific template name if specific matching is required.
|
||||||
* @return bool False on failure, true if success.
|
* @return bool False on failure, true if success.
|
||||||
*/
|
*/
|
||||||
function is_page_template($template = '') {
|
function is_page_template( $template = '' ) {
|
||||||
if (!is_page()) {
|
if ( ! is_page() )
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
global $wp_query;
|
$page_template = get_page_template_slug( get_queried_object_id() );
|
||||||
|
|
||||||
$page = $wp_query->get_queried_object();
|
if ( empty( $template ) )
|
||||||
$custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
|
return (bool) $page_template;
|
||||||
$page_template = $custom_fields[0];
|
|
||||||
|
|
||||||
// We have no argument passed so just see if a page_template has been specified
|
if ( $template == $page_template )
|
||||||
if ( empty( $template ) ) {
|
return true;
|
||||||
if ( !empty( $page_template ) and ( 'default' != $page_template ) ) {
|
|
||||||
return true;
|
if ( 'default' == $template && ! $page_template )
|
||||||
}
|
|
||||||
} elseif ( $template == $page_template) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the specific template name for a page.
|
||||||
|
*
|
||||||
|
* @since 3.4.0
|
||||||
|
*
|
||||||
|
* @param int $id The page ID to check. Defaults to the current post, when used in the loop.
|
||||||
|
* @return string|bool Page template filename. Returns an empty string when the default page template
|
||||||
|
* is in use. Returns false if the post is not a page.
|
||||||
|
*/
|
||||||
|
function get_page_template_slug( $post_id = null ) {
|
||||||
|
$post = get_post( $post_id );
|
||||||
|
if ( 'page' != $post->post_type )
|
||||||
|
return false;
|
||||||
|
$template = get_post_meta( $post->ID, '_wp_page_template', true );
|
||||||
|
if ( ! $template || 'default' == $template )
|
||||||
|
return '';
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve formatted date timestamp of a revision (linked to that revisions's page).
|
* Retrieve formatted date timestamp of a revision (linked to that revisions's page).
|
||||||
*
|
*
|
||||||
|
|
|
@ -5339,4 +5339,3 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache
|
||||||
update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
|
update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -225,20 +225,17 @@ function get_front_page_template() {
|
||||||
*/
|
*/
|
||||||
function get_page_template() {
|
function get_page_template() {
|
||||||
$id = get_queried_object_id();
|
$id = get_queried_object_id();
|
||||||
$template = get_post_meta($id, '_wp_page_template', true);
|
$template = get_page_template_slug();
|
||||||
$pagename = get_query_var('pagename');
|
$pagename = get_query_var('pagename');
|
||||||
|
|
||||||
if ( !$pagename && $id > 0 ) {
|
if ( ! $pagename && $id ) {
|
||||||
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
|
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
|
||||||
$post = get_queried_object();
|
$post = get_queried_object();
|
||||||
$pagename = $post->post_name;
|
$pagename = $post->post_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'default' == $template )
|
|
||||||
$template = '';
|
|
||||||
|
|
||||||
$templates = array();
|
$templates = array();
|
||||||
if ( !empty($template) && !validate_file($template) )
|
if ( $template && 0 === validate_file( $template ) )
|
||||||
$templates[] = $template;
|
$templates[] = $template;
|
||||||
if ( $pagename )
|
if ( $pagename )
|
||||||
$templates[] = "page-$pagename.php";
|
$templates[] = "page-$pagename.php";
|
||||||
|
|
Loading…
Reference in New Issue