Edit File by line
/home/barbar84/www/wp-inclu...
File: template.php
* @see get_query_template()
[500] Fix | Delete
*
[501] Fix | Delete
* @return string Full path to single template file.
[502] Fix | Delete
*/
[503] Fix | Delete
function get_single_template() {
[504] Fix | Delete
$object = get_queried_object();
[505] Fix | Delete
[506] Fix | Delete
$templates = array();
[507] Fix | Delete
[508] Fix | Delete
if ( ! empty( $object->post_type ) ) {
[509] Fix | Delete
$template = get_page_template_slug( $object );
[510] Fix | Delete
if ( $template && 0 === validate_file( $template ) ) {
[511] Fix | Delete
$templates[] = $template;
[512] Fix | Delete
}
[513] Fix | Delete
[514] Fix | Delete
$name_decoded = urldecode( $object->post_name );
[515] Fix | Delete
if ( $name_decoded !== $object->post_name ) {
[516] Fix | Delete
$templates[] = "single-{$object->post_type}-{$name_decoded}.php";
[517] Fix | Delete
}
[518] Fix | Delete
[519] Fix | Delete
$templates[] = "single-{$object->post_type}-{$object->post_name}.php";
[520] Fix | Delete
$templates[] = "single-{$object->post_type}.php";
[521] Fix | Delete
}
[522] Fix | Delete
[523] Fix | Delete
$templates[] = 'single.php';
[524] Fix | Delete
[525] Fix | Delete
return get_query_template( 'single', $templates );
[526] Fix | Delete
}
[527] Fix | Delete
[528] Fix | Delete
/**
[529] Fix | Delete
* Retrieves an embed template path in the current or parent template.
[530] Fix | Delete
*
[531] Fix | Delete
* The hierarchy for this template looks like:
[532] Fix | Delete
*
[533] Fix | Delete
* 1. embed-{post_type}-{post_format}.php
[534] Fix | Delete
* 2. embed-{post_type}.php
[535] Fix | Delete
* 3. embed.php
[536] Fix | Delete
*
[537] Fix | Delete
* An example of this is:
[538] Fix | Delete
*
[539] Fix | Delete
* 1. embed-post-audio.php
[540] Fix | Delete
* 2. embed-post.php
[541] Fix | Delete
* 3. embed.php
[542] Fix | Delete
*
[543] Fix | Delete
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
[544] Fix | Delete
* and {@see '$type_template'} dynamic hooks, where `$type` is 'embed'.
[545] Fix | Delete
*
[546] Fix | Delete
* @since 4.5.0
[547] Fix | Delete
*
[548] Fix | Delete
* @see get_query_template()
[549] Fix | Delete
*
[550] Fix | Delete
* @return string Full path to embed template file.
[551] Fix | Delete
*/
[552] Fix | Delete
function get_embed_template() {
[553] Fix | Delete
$object = get_queried_object();
[554] Fix | Delete
[555] Fix | Delete
$templates = array();
[556] Fix | Delete
[557] Fix | Delete
if ( ! empty( $object->post_type ) ) {
[558] Fix | Delete
$post_format = get_post_format( $object );
[559] Fix | Delete
if ( $post_format ) {
[560] Fix | Delete
$templates[] = "embed-{$object->post_type}-{$post_format}.php";
[561] Fix | Delete
}
[562] Fix | Delete
$templates[] = "embed-{$object->post_type}.php";
[563] Fix | Delete
}
[564] Fix | Delete
[565] Fix | Delete
$templates[] = 'embed.php';
[566] Fix | Delete
[567] Fix | Delete
return get_query_template( 'embed', $templates );
[568] Fix | Delete
}
[569] Fix | Delete
[570] Fix | Delete
/**
[571] Fix | Delete
* Retrieves the path of the singular template in current or parent template.
[572] Fix | Delete
*
[573] Fix | Delete
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
[574] Fix | Delete
* and {@see '$type_template'} dynamic hooks, where `$type` is 'singular'.
[575] Fix | Delete
*
[576] Fix | Delete
* @since 4.3.0
[577] Fix | Delete
*
[578] Fix | Delete
* @see get_query_template()
[579] Fix | Delete
*
[580] Fix | Delete
* @return string Full path to singular template file
[581] Fix | Delete
*/
[582] Fix | Delete
function get_singular_template() {
[583] Fix | Delete
return get_query_template( 'singular' );
[584] Fix | Delete
}
[585] Fix | Delete
[586] Fix | Delete
/**
[587] Fix | Delete
* Retrieve path of attachment template in current or parent template.
[588] Fix | Delete
*
[589] Fix | Delete
* The hierarchy for this template looks like:
[590] Fix | Delete
*
[591] Fix | Delete
* 1. {mime_type}-{sub_type}.php
[592] Fix | Delete
* 2. {sub_type}.php
[593] Fix | Delete
* 3. {mime_type}.php
[594] Fix | Delete
* 4. attachment.php
[595] Fix | Delete
*
[596] Fix | Delete
* An example of this is:
[597] Fix | Delete
*
[598] Fix | Delete
* 1. image-jpeg.php
[599] Fix | Delete
* 2. jpeg.php
[600] Fix | Delete
* 3. image.php
[601] Fix | Delete
* 4. attachment.php
[602] Fix | Delete
*
[603] Fix | Delete
* The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
[604] Fix | Delete
* and {@see '$type_template'} dynamic hooks, where `$type` is 'attachment'.
[605] Fix | Delete
*
[606] Fix | Delete
* @since 2.0.0
[607] Fix | Delete
* @since 4.3.0 The order of the mime type logic was reversed so the hierarchy is more logical.
[608] Fix | Delete
*
[609] Fix | Delete
* @see get_query_template()
[610] Fix | Delete
*
[611] Fix | Delete
* @global array $posts
[612] Fix | Delete
*
[613] Fix | Delete
* @return string Full path to attachment template file.
[614] Fix | Delete
*/
[615] Fix | Delete
function get_attachment_template() {
[616] Fix | Delete
$attachment = get_queried_object();
[617] Fix | Delete
[618] Fix | Delete
$templates = array();
[619] Fix | Delete
[620] Fix | Delete
if ( $attachment ) {
[621] Fix | Delete
if ( false !== strpos( $attachment->post_mime_type, '/' ) ) {
[622] Fix | Delete
list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
[623] Fix | Delete
} else {
[624] Fix | Delete
list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
[625] Fix | Delete
}
[626] Fix | Delete
[627] Fix | Delete
if ( ! empty( $subtype ) ) {
[628] Fix | Delete
$templates[] = "{$type}-{$subtype}.php";
[629] Fix | Delete
$templates[] = "{$subtype}.php";
[630] Fix | Delete
}
[631] Fix | Delete
$templates[] = "{$type}.php";
[632] Fix | Delete
}
[633] Fix | Delete
$templates[] = 'attachment.php';
[634] Fix | Delete
[635] Fix | Delete
return get_query_template( 'attachment', $templates );
[636] Fix | Delete
}
[637] Fix | Delete
[638] Fix | Delete
/**
[639] Fix | Delete
* Retrieve the name of the highest priority template file that exists.
[640] Fix | Delete
*
[641] Fix | Delete
* Searches in the STYLESHEETPATH before TEMPLATEPATH and wp-includes/theme-compat
[642] Fix | Delete
* so that themes which inherit from a parent theme can just overload one file.
[643] Fix | Delete
*
[644] Fix | Delete
* @since 2.7.0
[645] Fix | Delete
* @since 5.5.0 The `$args` parameter was added.
[646] Fix | Delete
*
[647] Fix | Delete
* @param string|array $template_names Template file(s) to search for, in order.
[648] Fix | Delete
* @param bool $load If true the template file will be loaded if it is found.
[649] Fix | Delete
* @param bool $require_once Whether to require_once or require. Has no effect if `$load` is false.
[650] Fix | Delete
* Default true.
[651] Fix | Delete
* @param array $args Optional. Additional arguments passed to the template.
[652] Fix | Delete
* Default empty array.
[653] Fix | Delete
* @return string The template filename if one is located.
[654] Fix | Delete
*/
[655] Fix | Delete
function locate_template( $template_names, $load = false, $require_once = true, $args = array() ) {
[656] Fix | Delete
$located = '';
[657] Fix | Delete
foreach ( (array) $template_names as $template_name ) {
[658] Fix | Delete
if ( ! $template_name ) {
[659] Fix | Delete
continue;
[660] Fix | Delete
}
[661] Fix | Delete
if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) {
[662] Fix | Delete
$located = STYLESHEETPATH . '/' . $template_name;
[663] Fix | Delete
break;
[664] Fix | Delete
} elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) {
[665] Fix | Delete
$located = TEMPLATEPATH . '/' . $template_name;
[666] Fix | Delete
break;
[667] Fix | Delete
} elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {
[668] Fix | Delete
$located = ABSPATH . WPINC . '/theme-compat/' . $template_name;
[669] Fix | Delete
break;
[670] Fix | Delete
}
[671] Fix | Delete
}
[672] Fix | Delete
[673] Fix | Delete
if ( $load && '' !== $located ) {
[674] Fix | Delete
load_template( $located, $require_once, $args );
[675] Fix | Delete
}
[676] Fix | Delete
[677] Fix | Delete
return $located;
[678] Fix | Delete
}
[679] Fix | Delete
[680] Fix | Delete
/**
[681] Fix | Delete
* Require the template file with WordPress environment.
[682] Fix | Delete
*
[683] Fix | Delete
* The globals are set up for the template file to ensure that the WordPress
[684] Fix | Delete
* environment is available from within the function. The query variables are
[685] Fix | Delete
* also available.
[686] Fix | Delete
*
[687] Fix | Delete
* @since 1.5.0
[688] Fix | Delete
* @since 5.5.0 The `$args` parameter was added.
[689] Fix | Delete
*
[690] Fix | Delete
* @global array $posts
[691] Fix | Delete
* @global WP_Post $post Global post object.
[692] Fix | Delete
* @global bool $wp_did_header
[693] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[694] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[695] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[696] Fix | Delete
* @global string $wp_version
[697] Fix | Delete
* @global WP $wp Current WordPress environment instance.
[698] Fix | Delete
* @global int $id
[699] Fix | Delete
* @global WP_Comment $comment Global comment object.
[700] Fix | Delete
* @global int $user_ID
[701] Fix | Delete
*
[702] Fix | Delete
* @param string $_template_file Path to template file.
[703] Fix | Delete
* @param bool $require_once Whether to require_once or require. Default true.
[704] Fix | Delete
* @param array $args Optional. Additional arguments passed to the template.
[705] Fix | Delete
* Default empty array.
[706] Fix | Delete
*/
[707] Fix | Delete
function load_template( $_template_file, $require_once = true, $args = array() ) {
[708] Fix | Delete
global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;
[709] Fix | Delete
[710] Fix | Delete
if ( is_array( $wp_query->query_vars ) ) {
[711] Fix | Delete
/*
[712] Fix | Delete
* This use of extract() cannot be removed. There are many possible ways that
[713] Fix | Delete
* templates could depend on variables that it creates existing, and no way to
[714] Fix | Delete
* detect and deprecate it.
[715] Fix | Delete
*
[716] Fix | Delete
* Passing the EXTR_SKIP flag is the safest option, ensuring globals and
[717] Fix | Delete
* function variables cannot be overwritten.
[718] Fix | Delete
*/
[719] Fix | Delete
// phpcs:ignore WordPress.PHP.DontExtract.extract_extract
[720] Fix | Delete
extract( $wp_query->query_vars, EXTR_SKIP );
[721] Fix | Delete
}
[722] Fix | Delete
[723] Fix | Delete
if ( isset( $s ) ) {
[724] Fix | Delete
$s = esc_attr( $s );
[725] Fix | Delete
}
[726] Fix | Delete
[727] Fix | Delete
if ( $require_once ) {
[728] Fix | Delete
require_once $_template_file;
[729] Fix | Delete
} else {
[730] Fix | Delete
require $_template_file;
[731] Fix | Delete
}
[732] Fix | Delete
}
[733] Fix | Delete
[734] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function