Edit File by line
/home/zeestwma/redstone.../wp-inclu...
File: theme-templates.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Sets a custom slug when creating auto-draft template parts.
[3] Fix | Delete
*
[4] Fix | Delete
* This is only needed for auto-drafts created by the regular WP editor.
[5] Fix | Delete
* If this page is to be removed, this will not be necessary.
[6] Fix | Delete
*
[7] Fix | Delete
* @since 5.9.0
[8] Fix | Delete
*
[9] Fix | Delete
* @param int $post_id Post ID.
[10] Fix | Delete
*/
[11] Fix | Delete
function wp_set_unique_slug_on_create_template_part( $post_id ) {
[12] Fix | Delete
$post = get_post( $post_id );
[13] Fix | Delete
if ( 'auto-draft' !== $post->post_status ) {
[14] Fix | Delete
return;
[15] Fix | Delete
}
[16] Fix | Delete
[17] Fix | Delete
if ( ! $post->post_name ) {
[18] Fix | Delete
wp_update_post(
[19] Fix | Delete
array(
[20] Fix | Delete
'ID' => $post_id,
[21] Fix | Delete
'post_name' => 'custom_slug_' . uniqid(),
[22] Fix | Delete
)
[23] Fix | Delete
);
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
$terms = get_the_terms( $post_id, 'wp_theme' );
[27] Fix | Delete
if ( ! is_array( $terms ) || ! count( $terms ) ) {
[28] Fix | Delete
wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
[29] Fix | Delete
}
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Generates a unique slug for templates.
[34] Fix | Delete
*
[35] Fix | Delete
* @access private
[36] Fix | Delete
* @since 5.8.0
[37] Fix | Delete
*
[38] Fix | Delete
* @param string $override_slug The filtered value of the slug (starts as `null` from apply_filter).
[39] Fix | Delete
* @param string $slug The original/un-filtered slug (post_name).
[40] Fix | Delete
* @param int $post_id Post ID.
[41] Fix | Delete
* @param string $post_status No uniqueness checks are made if the post is still draft or pending.
[42] Fix | Delete
* @param string $post_type Post type.
[43] Fix | Delete
* @return string The original, desired slug.
[44] Fix | Delete
*/
[45] Fix | Delete
function wp_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_id, $post_status, $post_type ) {
[46] Fix | Delete
if ( 'wp_template' !== $post_type && 'wp_template_part' !== $post_type ) {
[47] Fix | Delete
return $override_slug;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
if ( ! $override_slug ) {
[51] Fix | Delete
$override_slug = $slug;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/*
[55] Fix | Delete
* Template slugs must be unique within the same theme.
[56] Fix | Delete
* TODO - Figure out how to update this to work for a multi-theme environment.
[57] Fix | Delete
* Unfortunately using `get_the_terms()` for the 'wp-theme' term does not work
[58] Fix | Delete
* in the case of new entities since is too early in the process to have been saved
[59] Fix | Delete
* to the entity. So for now we use the currently activated theme for creation.
[60] Fix | Delete
*/
[61] Fix | Delete
$theme = get_stylesheet();
[62] Fix | Delete
$terms = get_the_terms( $post_id, 'wp_theme' );
[63] Fix | Delete
if ( $terms && ! is_wp_error( $terms ) ) {
[64] Fix | Delete
$theme = $terms[0]->name;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
$check_query_args = array(
[68] Fix | Delete
'post_name__in' => array( $override_slug ),
[69] Fix | Delete
'post_type' => $post_type,
[70] Fix | Delete
'posts_per_page' => 1,
[71] Fix | Delete
'no_found_rows' => true,
[72] Fix | Delete
'post__not_in' => array( $post_id ),
[73] Fix | Delete
'tax_query' => array(
[74] Fix | Delete
array(
[75] Fix | Delete
'taxonomy' => 'wp_theme',
[76] Fix | Delete
'field' => 'name',
[77] Fix | Delete
'terms' => $theme,
[78] Fix | Delete
),
[79] Fix | Delete
),
[80] Fix | Delete
);
[81] Fix | Delete
$check_query = new WP_Query( $check_query_args );
[82] Fix | Delete
$posts = $check_query->posts;
[83] Fix | Delete
[84] Fix | Delete
if ( count( $posts ) > 0 ) {
[85] Fix | Delete
$suffix = 2;
[86] Fix | Delete
do {
[87] Fix | Delete
$query_args = $check_query_args;
[88] Fix | Delete
$alt_post_name = _truncate_post_slug( $override_slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
[89] Fix | Delete
$query_args['post_name__in'] = array( $alt_post_name );
[90] Fix | Delete
$query = new WP_Query( $query_args );
[91] Fix | Delete
++$suffix;
[92] Fix | Delete
} while ( count( $query->posts ) > 0 );
[93] Fix | Delete
$override_slug = $alt_post_name;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return $override_slug;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Enqueues the skip-link script & styles.
[101] Fix | Delete
*
[102] Fix | Delete
* @access private
[103] Fix | Delete
* @since 6.4.0
[104] Fix | Delete
*
[105] Fix | Delete
* @global string $_wp_current_template_content
[106] Fix | Delete
*/
[107] Fix | Delete
function wp_enqueue_block_template_skip_link() {
[108] Fix | Delete
global $_wp_current_template_content;
[109] Fix | Delete
[110] Fix | Delete
// Back-compat for plugins that disable functionality by unhooking this action.
[111] Fix | Delete
if ( ! has_action( 'wp_footer', 'the_block_template_skip_link' ) ) {
[112] Fix | Delete
return;
[113] Fix | Delete
}
[114] Fix | Delete
remove_action( 'wp_footer', 'the_block_template_skip_link' );
[115] Fix | Delete
[116] Fix | Delete
// Early exit if not a block theme.
[117] Fix | Delete
if ( ! current_theme_supports( 'block-templates' ) ) {
[118] Fix | Delete
return;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Early exit if not a block template.
[122] Fix | Delete
if ( ! $_wp_current_template_content ) {
[123] Fix | Delete
return;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$skip_link_styles = '
[127] Fix | Delete
.skip-link.screen-reader-text {
[128] Fix | Delete
border: 0;
[129] Fix | Delete
clip-path: inset(50%);
[130] Fix | Delete
height: 1px;
[131] Fix | Delete
margin: -1px;
[132] Fix | Delete
overflow: hidden;
[133] Fix | Delete
padding: 0;
[134] Fix | Delete
position: absolute !important;
[135] Fix | Delete
width: 1px;
[136] Fix | Delete
word-wrap: normal !important;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
.skip-link.screen-reader-text:focus {
[140] Fix | Delete
background-color: #eee;
[141] Fix | Delete
clip-path: none;
[142] Fix | Delete
color: #444;
[143] Fix | Delete
display: block;
[144] Fix | Delete
font-size: 1em;
[145] Fix | Delete
height: auto;
[146] Fix | Delete
left: 5px;
[147] Fix | Delete
line-height: normal;
[148] Fix | Delete
padding: 15px 23px 14px;
[149] Fix | Delete
text-decoration: none;
[150] Fix | Delete
top: 5px;
[151] Fix | Delete
width: auto;
[152] Fix | Delete
z-index: 100000;
[153] Fix | Delete
}';
[154] Fix | Delete
[155] Fix | Delete
$handle = 'wp-block-template-skip-link';
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Print the skip-link styles.
[159] Fix | Delete
*/
[160] Fix | Delete
wp_register_style( $handle, false );
[161] Fix | Delete
wp_add_inline_style( $handle, $skip_link_styles );
[162] Fix | Delete
wp_enqueue_style( $handle );
[163] Fix | Delete
[164] Fix | Delete
/**
[165] Fix | Delete
* Enqueue the skip-link script.
[166] Fix | Delete
*/
[167] Fix | Delete
ob_start();
[168] Fix | Delete
?>
[169] Fix | Delete
<script>
[170] Fix | Delete
( function() {
[171] Fix | Delete
var skipLinkTarget = document.querySelector( 'main' ),
[172] Fix | Delete
sibling,
[173] Fix | Delete
skipLinkTargetID,
[174] Fix | Delete
skipLink;
[175] Fix | Delete
[176] Fix | Delete
// Early exit if a skip-link target can't be located.
[177] Fix | Delete
if ( ! skipLinkTarget ) {
[178] Fix | Delete
return;
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
/*
[182] Fix | Delete
* Get the site wrapper.
[183] Fix | Delete
* The skip-link will be injected in the beginning of it.
[184] Fix | Delete
*/
[185] Fix | Delete
sibling = document.querySelector( '.wp-site-blocks' );
[186] Fix | Delete
[187] Fix | Delete
// Early exit if the root element was not found.
[188] Fix | Delete
if ( ! sibling ) {
[189] Fix | Delete
return;
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
// Get the skip-link target's ID, and generate one if it doesn't exist.
[193] Fix | Delete
skipLinkTargetID = skipLinkTarget.id;
[194] Fix | Delete
if ( ! skipLinkTargetID ) {
[195] Fix | Delete
skipLinkTargetID = 'wp--skip-link--target';
[196] Fix | Delete
skipLinkTarget.id = skipLinkTargetID;
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
// Create the skip link.
[200] Fix | Delete
skipLink = document.createElement( 'a' );
[201] Fix | Delete
skipLink.classList.add( 'skip-link', 'screen-reader-text' );
[202] Fix | Delete
skipLink.id = 'wp-skip-link';
[203] Fix | Delete
skipLink.href = '#' + skipLinkTargetID;
[204] Fix | Delete
skipLink.innerText = '<?php /* translators: Hidden accessibility text. Do not use HTML entities (&nbsp;, etc.). */ esc_html_e( 'Skip to content' ); ?>';
[205] Fix | Delete
[206] Fix | Delete
// Inject the skip link.
[207] Fix | Delete
sibling.parentElement.insertBefore( skipLink, sibling );
[208] Fix | Delete
}() );
[209] Fix | Delete
</script>
[210] Fix | Delete
<?php
[211] Fix | Delete
$skip_link_script = wp_remove_surrounding_empty_script_tags( ob_get_clean() );
[212] Fix | Delete
$script_handle = 'wp-block-template-skip-link';
[213] Fix | Delete
wp_register_script( $script_handle, false, array(), false, array( 'in_footer' => true ) );
[214] Fix | Delete
wp_add_inline_script( $script_handle, $skip_link_script );
[215] Fix | Delete
wp_enqueue_script( $script_handle );
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Enables the block templates (editor mode) for themes with theme.json by default.
[220] Fix | Delete
*
[221] Fix | Delete
* @access private
[222] Fix | Delete
* @since 5.8.0
[223] Fix | Delete
*/
[224] Fix | Delete
function wp_enable_block_templates() {
[225] Fix | Delete
if ( wp_is_block_theme() || wp_theme_has_theme_json() ) {
[226] Fix | Delete
add_theme_support( 'block-templates' );
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function