Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: home-link.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/home-link` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Build an array with CSS classes and inline styles defining the colors
[8] Fix | Delete
* which will be applied to the home link markup in the front-end.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 6.0.0
[11] Fix | Delete
*
[12] Fix | Delete
* @param array $context home link block context.
[13] Fix | Delete
* @return array Colors CSS classes and inline styles.
[14] Fix | Delete
*/
[15] Fix | Delete
function block_core_home_link_build_css_colors( $context ) {
[16] Fix | Delete
$colors = array(
[17] Fix | Delete
'css_classes' => array(),
[18] Fix | Delete
'inline_styles' => '',
[19] Fix | Delete
);
[20] Fix | Delete
[21] Fix | Delete
// Text color.
[22] Fix | Delete
$has_named_text_color = array_key_exists( 'textColor', $context );
[23] Fix | Delete
$has_custom_text_color = isset( $context['style']['color']['text'] );
[24] Fix | Delete
[25] Fix | Delete
// If has text color.
[26] Fix | Delete
if ( $has_custom_text_color || $has_named_text_color ) {
[27] Fix | Delete
// Add has-text-color class.
[28] Fix | Delete
$colors['css_classes'][] = 'has-text-color';
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
if ( $has_named_text_color ) {
[32] Fix | Delete
// Add the color class.
[33] Fix | Delete
$colors['css_classes'][] = sprintf( 'has-%s-color', $context['textColor'] );
[34] Fix | Delete
} elseif ( $has_custom_text_color ) {
[35] Fix | Delete
// Add the custom color inline style.
[36] Fix | Delete
$colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] );
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
// Background color.
[40] Fix | Delete
$has_named_background_color = array_key_exists( 'backgroundColor', $context );
[41] Fix | Delete
$has_custom_background_color = isset( $context['style']['color']['background'] );
[42] Fix | Delete
[43] Fix | Delete
// If has background color.
[44] Fix | Delete
if ( $has_custom_background_color || $has_named_background_color ) {
[45] Fix | Delete
// Add has-background class.
[46] Fix | Delete
$colors['css_classes'][] = 'has-background';
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ( $has_named_background_color ) {
[50] Fix | Delete
// Add the background-color class.
[51] Fix | Delete
$colors['css_classes'][] = sprintf( 'has-%s-background-color', $context['backgroundColor'] );
[52] Fix | Delete
} elseif ( $has_custom_background_color ) {
[53] Fix | Delete
// Add the custom background-color inline style.
[54] Fix | Delete
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['style']['color']['background'] );
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
return $colors;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* Build an array with CSS classes and inline styles defining the font sizes
[62] Fix | Delete
* which will be applied to the home link markup in the front-end.
[63] Fix | Delete
*
[64] Fix | Delete
* @since 6.0.0
[65] Fix | Delete
*
[66] Fix | Delete
* @param array $context Home link block context.
[67] Fix | Delete
* @return array Font size CSS classes and inline styles.
[68] Fix | Delete
*/
[69] Fix | Delete
function block_core_home_link_build_css_font_sizes( $context ) {
[70] Fix | Delete
// CSS classes.
[71] Fix | Delete
$font_sizes = array(
[72] Fix | Delete
'css_classes' => array(),
[73] Fix | Delete
'inline_styles' => '',
[74] Fix | Delete
);
[75] Fix | Delete
[76] Fix | Delete
$has_named_font_size = array_key_exists( 'fontSize', $context );
[77] Fix | Delete
$has_custom_font_size = isset( $context['style']['typography']['fontSize'] );
[78] Fix | Delete
[79] Fix | Delete
if ( $has_named_font_size ) {
[80] Fix | Delete
// Add the font size class.
[81] Fix | Delete
$font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] );
[82] Fix | Delete
} elseif ( $has_custom_font_size ) {
[83] Fix | Delete
// Add the custom font size inline style.
[84] Fix | Delete
$font_sizes['inline_styles'] = sprintf( 'font-size: %s;', $context['style']['typography']['fontSize'] );
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
return $font_sizes;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Builds an array with classes and style for the li wrapper
[92] Fix | Delete
*
[93] Fix | Delete
* @since 6.0.0
[94] Fix | Delete
*
[95] Fix | Delete
* @param array $context Home link block context.
[96] Fix | Delete
* @return string The li wrapper attributes.
[97] Fix | Delete
*/
[98] Fix | Delete
function block_core_home_link_build_li_wrapper_attributes( $context ) {
[99] Fix | Delete
$colors = block_core_home_link_build_css_colors( $context );
[100] Fix | Delete
$font_sizes = block_core_home_link_build_css_font_sizes( $context );
[101] Fix | Delete
$classes = array_merge(
[102] Fix | Delete
$colors['css_classes'],
[103] Fix | Delete
$font_sizes['css_classes']
[104] Fix | Delete
);
[105] Fix | Delete
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
[106] Fix | Delete
$classes[] = 'wp-block-navigation-item';
[107] Fix | Delete
[108] Fix | Delete
if ( is_front_page() ) {
[109] Fix | Delete
$classes[] = 'current-menu-item';
[110] Fix | Delete
} elseif ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) {
[111] Fix | Delete
// Edge case where the Reading settings has a posts page set but not a static homepage.
[112] Fix | Delete
$classes[] = 'current-menu-item';
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes(
[116] Fix | Delete
array(
[117] Fix | Delete
'class' => implode( ' ', $classes ),
[118] Fix | Delete
'style' => $style_attribute,
[119] Fix | Delete
)
[120] Fix | Delete
);
[121] Fix | Delete
[122] Fix | Delete
return $wrapper_attributes;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Renders the `core/home-link` block.
[127] Fix | Delete
*
[128] Fix | Delete
* @since 6.0.0
[129] Fix | Delete
*
[130] Fix | Delete
* @param array $attributes The block attributes.
[131] Fix | Delete
* @param string $content The saved content.
[132] Fix | Delete
* @param WP_Block $block The parsed block.
[133] Fix | Delete
*
[134] Fix | Delete
* @return string Returns the post content with the home url added.
[135] Fix | Delete
*/
[136] Fix | Delete
function render_block_core_home_link( $attributes, $content, $block ) {
[137] Fix | Delete
if ( empty( $attributes['label'] ) ) {
[138] Fix | Delete
$attributes['label'] = __( 'Home' );
[139] Fix | Delete
}
[140] Fix | Delete
$aria_current = '';
[141] Fix | Delete
[142] Fix | Delete
if ( is_front_page() ) {
[143] Fix | Delete
$aria_current = ' aria-current="page"';
[144] Fix | Delete
} elseif ( is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) {
[145] Fix | Delete
// Edge case where the Reading settings has a posts page set but not a static homepage.
[146] Fix | Delete
$aria_current = ' aria-current="page"';
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
return sprintf(
[150] Fix | Delete
'<li %1$s><a class="wp-block-home-link__content wp-block-navigation-item__content" href="%2$s" rel="home"%3$s>%4$s</a></li>',
[151] Fix | Delete
block_core_home_link_build_li_wrapper_attributes( $block->context ),
[152] Fix | Delete
esc_url( home_url() ),
[153] Fix | Delete
$aria_current,
[154] Fix | Delete
wp_kses_post( $attributes['label'] )
[155] Fix | Delete
);
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Register the home block
[160] Fix | Delete
*
[161] Fix | Delete
* @since 6.0.0
[162] Fix | Delete
*
[163] Fix | Delete
* @uses render_block_core_home_link()
[164] Fix | Delete
* @throws WP_Error An WP_Error exception parsing the block definition.
[165] Fix | Delete
*/
[166] Fix | Delete
function register_block_core_home_link() {
[167] Fix | Delete
register_block_type_from_metadata(
[168] Fix | Delete
__DIR__ . '/home-link',
[169] Fix | Delete
array(
[170] Fix | Delete
'render_callback' => 'render_block_core_home_link',
[171] Fix | Delete
)
[172] Fix | Delete
);
[173] Fix | Delete
}
[174] Fix | Delete
add_action( 'init', 'register_block_core_home_link' );
[175] Fix | Delete
[176] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function