Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-inclu.../blocks
File: page-list.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/pages` 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 pages markup in the front-end when it is a descendant of navigation.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 5.8.0
[11] Fix | Delete
*
[12] Fix | Delete
* @param array $attributes Block attributes.
[13] Fix | Delete
* @param array $context Navigation block context.
[14] Fix | Delete
* @return array Colors CSS classes and inline styles.
[15] Fix | Delete
*/
[16] Fix | Delete
function block_core_page_list_build_css_colors( $attributes, $context ) {
[17] Fix | Delete
$colors = array(
[18] Fix | Delete
'css_classes' => array(),
[19] Fix | Delete
'inline_styles' => '',
[20] Fix | Delete
'overlay_css_classes' => array(),
[21] Fix | Delete
'overlay_inline_styles' => '',
[22] Fix | Delete
);
[23] Fix | Delete
[24] Fix | Delete
// Text color.
[25] Fix | Delete
$has_named_text_color = array_key_exists( 'textColor', $context );
[26] Fix | Delete
$has_picked_text_color = array_key_exists( 'customTextColor', $context );
[27] Fix | Delete
$has_custom_text_color = isset( $context['style']['color']['text'] );
[28] Fix | Delete
[29] Fix | Delete
// If has text color.
[30] Fix | Delete
if ( $has_custom_text_color || $has_picked_text_color || $has_named_text_color ) {
[31] Fix | Delete
// Add has-text-color class.
[32] Fix | Delete
$colors['css_classes'][] = 'has-text-color';
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
if ( $has_named_text_color ) {
[36] Fix | Delete
// Add the color class.
[37] Fix | Delete
$colors['css_classes'][] = sprintf( 'has-%s-color', _wp_to_kebab_case( $context['textColor'] ) );
[38] Fix | Delete
} elseif ( $has_picked_text_color ) {
[39] Fix | Delete
$colors['inline_styles'] .= sprintf( 'color: %s;', $context['customTextColor'] );
[40] Fix | Delete
} elseif ( $has_custom_text_color ) {
[41] Fix | Delete
// Add the custom color inline style.
[42] Fix | Delete
$colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] );
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
// Background color.
[46] Fix | Delete
$has_named_background_color = array_key_exists( 'backgroundColor', $context );
[47] Fix | Delete
$has_picked_background_color = array_key_exists( 'customBackgroundColor', $context );
[48] Fix | Delete
$has_custom_background_color = isset( $context['style']['color']['background'] );
[49] Fix | Delete
[50] Fix | Delete
// If has background color.
[51] Fix | Delete
if ( $has_custom_background_color || $has_picked_background_color || $has_named_background_color ) {
[52] Fix | Delete
// Add has-background class.
[53] Fix | Delete
$colors['css_classes'][] = 'has-background';
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
if ( $has_named_background_color ) {
[57] Fix | Delete
// Add the background-color class.
[58] Fix | Delete
$colors['css_classes'][] = sprintf( 'has-%s-background-color', _wp_to_kebab_case( $context['backgroundColor'] ) );
[59] Fix | Delete
} elseif ( $has_picked_background_color ) {
[60] Fix | Delete
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['customBackgroundColor'] );
[61] Fix | Delete
} elseif ( $has_custom_background_color ) {
[62] Fix | Delete
// Add the custom background-color inline style.
[63] Fix | Delete
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['style']['color']['background'] );
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
// Overlay text color.
[67] Fix | Delete
$has_named_overlay_text_color = array_key_exists( 'overlayTextColor', $context );
[68] Fix | Delete
$has_picked_overlay_text_color = array_key_exists( 'customOverlayTextColor', $context );
[69] Fix | Delete
[70] Fix | Delete
// If it has a text color.
[71] Fix | Delete
if ( $has_named_overlay_text_color || $has_picked_overlay_text_color ) {
[72] Fix | Delete
$colors['overlay_css_classes'][] = 'has-text-color';
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
// Give overlay colors priority, fall back to Navigation block colors, then global styles.
[76] Fix | Delete
if ( $has_named_overlay_text_color ) {
[77] Fix | Delete
$colors['overlay_css_classes'][] = sprintf( 'has-%s-color', _wp_to_kebab_case( $context['overlayTextColor'] ) );
[78] Fix | Delete
} elseif ( $has_picked_overlay_text_color ) {
[79] Fix | Delete
$colors['overlay_inline_styles'] .= sprintf( 'color: %s;', $context['customOverlayTextColor'] );
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
// Overlay background colors.
[83] Fix | Delete
$has_named_overlay_background_color = array_key_exists( 'overlayBackgroundColor', $context );
[84] Fix | Delete
$has_picked_overlay_background_color = array_key_exists( 'customOverlayBackgroundColor', $context );
[85] Fix | Delete
[86] Fix | Delete
// If has background color.
[87] Fix | Delete
if ( $has_named_overlay_background_color || $has_picked_overlay_background_color ) {
[88] Fix | Delete
$colors['overlay_css_classes'][] = 'has-background';
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
if ( $has_named_overlay_background_color ) {
[92] Fix | Delete
$colors['overlay_css_classes'][] = sprintf( 'has-%s-background-color', _wp_to_kebab_case( $context['overlayBackgroundColor'] ) );
[93] Fix | Delete
} elseif ( $has_picked_overlay_background_color ) {
[94] Fix | Delete
$colors['overlay_inline_styles'] .= sprintf( 'background-color: %s;', $context['customOverlayBackgroundColor'] );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
return $colors;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Build an array with CSS classes and inline styles defining the font sizes
[102] Fix | Delete
* which will be applied to the pages markup in the front-end when it is a descendant of navigation.
[103] Fix | Delete
*
[104] Fix | Delete
* @since 5.8.0
[105] Fix | Delete
*
[106] Fix | Delete
* @param array $context Navigation block context.
[107] Fix | Delete
* @return array Font size CSS classes and inline styles.
[108] Fix | Delete
*/
[109] Fix | Delete
function block_core_page_list_build_css_font_sizes( $context ) {
[110] Fix | Delete
// CSS classes.
[111] Fix | Delete
$font_sizes = array(
[112] Fix | Delete
'css_classes' => array(),
[113] Fix | Delete
'inline_styles' => '',
[114] Fix | Delete
);
[115] Fix | Delete
[116] Fix | Delete
$has_named_font_size = array_key_exists( 'fontSize', $context );
[117] Fix | Delete
$has_custom_font_size = isset( $context['style']['typography']['fontSize'] );
[118] Fix | Delete
[119] Fix | Delete
if ( $has_named_font_size ) {
[120] Fix | Delete
// Add the font size class.
[121] Fix | Delete
$font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] );
[122] Fix | Delete
} elseif ( $has_custom_font_size ) {
[123] Fix | Delete
// Add the custom font size inline style.
[124] Fix | Delete
$font_sizes['inline_styles'] = sprintf(
[125] Fix | Delete
'font-size: %s;',
[126] Fix | Delete
wp_get_typography_font_size_value(
[127] Fix | Delete
array(
[128] Fix | Delete
'size' => $context['style']['typography']['fontSize'],
[129] Fix | Delete
)
[130] Fix | Delete
)
[131] Fix | Delete
);
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
return $font_sizes;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* Outputs Page list markup from an array of pages with nested children.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 5.8.0
[141] Fix | Delete
*
[142] Fix | Delete
* @param boolean $open_submenus_on_click Whether to open submenus on click instead of hover.
[143] Fix | Delete
* @param boolean $show_submenu_icons Whether to show submenu indicator icons.
[144] Fix | Delete
* @param boolean $is_navigation_child If block is a child of Navigation block.
[145] Fix | Delete
* @param array $nested_pages The array of nested pages.
[146] Fix | Delete
* @param boolean $is_nested Whether the submenu is nested or not.
[147] Fix | Delete
* @param array $active_page_ancestor_ids An array of ancestor ids for active page.
[148] Fix | Delete
* @param array $colors Color information for overlay styles.
[149] Fix | Delete
* @param integer $depth The nesting depth.
[150] Fix | Delete
*
[151] Fix | Delete
* @return string List markup.
[152] Fix | Delete
*/
[153] Fix | Delete
function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) {
[154] Fix | Delete
if ( empty( $nested_pages ) ) {
[155] Fix | Delete
return;
[156] Fix | Delete
}
[157] Fix | Delete
$front_page_id = (int) get_option( 'page_on_front' );
[158] Fix | Delete
$markup = '';
[159] Fix | Delete
foreach ( (array) $nested_pages as $page ) {
[160] Fix | Delete
$css_class = $page['is_active'] ? ' current-menu-item' : '';
[161] Fix | Delete
$aria_current = $page['is_active'] ? ' aria-current="page"' : '';
[162] Fix | Delete
$style_attribute = '';
[163] Fix | Delete
[164] Fix | Delete
$css_class .= in_array( $page['page_id'], $active_page_ancestor_ids, true ) ? ' current-menu-ancestor' : '';
[165] Fix | Delete
if ( isset( $page['children'] ) ) {
[166] Fix | Delete
$css_class .= ' has-child';
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
if ( $is_navigation_child ) {
[170] Fix | Delete
$css_class .= ' wp-block-navigation-item';
[171] Fix | Delete
[172] Fix | Delete
if ( $open_submenus_on_click ) {
[173] Fix | Delete
$css_class .= ' open-on-click';
[174] Fix | Delete
} elseif ( $show_submenu_icons ) {
[175] Fix | Delete
$css_class .= ' open-on-hover-click';
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
$navigation_child_content_class = $is_navigation_child ? ' wp-block-navigation-item__content' : '';
[180] Fix | Delete
[181] Fix | Delete
// If this is the first level of submenus, include the overlay colors.
[182] Fix | Delete
if ( ( ( 0 < $depth && ! $is_nested ) || $is_nested ) && isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) {
[183] Fix | Delete
$css_class .= ' ' . trim( implode( ' ', $colors['overlay_css_classes'] ) );
[184] Fix | Delete
if ( '' !== $colors['overlay_inline_styles'] ) {
[185] Fix | Delete
$style_attribute = sprintf( ' style="%s"', esc_attr( $colors['overlay_inline_styles'] ) );
[186] Fix | Delete
}
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
if ( (int) $page['page_id'] === $front_page_id ) {
[190] Fix | Delete
$css_class .= ' menu-item-home';
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
$title = wp_kses_post( $page['title'] );
[194] Fix | Delete
$aria_label = sprintf(
[195] Fix | Delete
/* translators: Accessibility text. %s: Parent page title. */
[196] Fix | Delete
__( '%s submenu' ),
[197] Fix | Delete
wp_strip_all_tags( $title )
[198] Fix | Delete
);
[199] Fix | Delete
[200] Fix | Delete
$markup .= '<li class="wp-block-pages-list__item' . esc_attr( $css_class ) . '"' . $style_attribute . '>';
[201] Fix | Delete
[202] Fix | Delete
if ( isset( $page['children'] ) && $is_navigation_child && $open_submenus_on_click ) {
[203] Fix | Delete
$markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="' . esc_attr( $navigation_child_content_class ) . ' wp-block-navigation-submenu__toggle" aria-expanded="false">' . esc_html( $title ) .
[204] Fix | Delete
'</button><span class="wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></span>';
[205] Fix | Delete
} else {
[206] Fix | Delete
$markup .= '<a class="wp-block-pages-list__item__link' . esc_attr( $navigation_child_content_class ) . '" href="' . esc_url( $page['link'] ) . '"' . $aria_current . '>' . $title . '</a>';
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
if ( isset( $page['children'] ) ) {
[210] Fix | Delete
if ( $is_navigation_child && $show_submenu_icons && ! $open_submenus_on_click ) {
[211] Fix | Delete
$markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle" aria-expanded="false">';
[212] Fix | Delete
$markup .= '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
[213] Fix | Delete
$markup .= '</button>';
[214] Fix | Delete
}
[215] Fix | Delete
$markup .= '<ul class="wp-block-navigation__submenu-container">';
[216] Fix | Delete
$markup .= block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $page['children'], $is_nested, $active_page_ancestor_ids, $colors, $depth + 1 );
[217] Fix | Delete
$markup .= '</ul>';
[218] Fix | Delete
}
[219] Fix | Delete
$markup .= '</li>';
[220] Fix | Delete
}
[221] Fix | Delete
return $markup;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Outputs nested array of pages
[226] Fix | Delete
*
[227] Fix | Delete
* @since 5.8.0
[228] Fix | Delete
*
[229] Fix | Delete
* @param array $current_level The level being iterated through.
[230] Fix | Delete
* @param array $children The children grouped by parent post ID.
[231] Fix | Delete
*
[232] Fix | Delete
* @return array The nested array of pages.
[233] Fix | Delete
*/
[234] Fix | Delete
function block_core_page_list_nest_pages( $current_level, $children ) {
[235] Fix | Delete
if ( empty( $current_level ) ) {
[236] Fix | Delete
return;
[237] Fix | Delete
}
[238] Fix | Delete
foreach ( (array) $current_level as $key => $current ) {
[239] Fix | Delete
if ( isset( $children[ $key ] ) ) {
[240] Fix | Delete
$current_level[ $key ]['children'] = block_core_page_list_nest_pages( $children[ $key ], $children );
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
return $current_level;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Renders the `core/page-list` block on server.
[248] Fix | Delete
*
[249] Fix | Delete
* @since 5.8.0
[250] Fix | Delete
*
[251] Fix | Delete
* @param array $attributes The block attributes.
[252] Fix | Delete
* @param string $content The saved content.
[253] Fix | Delete
* @param WP_Block $block The parsed block.
[254] Fix | Delete
*
[255] Fix | Delete
* @return string Returns the page list markup.
[256] Fix | Delete
*/
[257] Fix | Delete
function render_block_core_page_list( $attributes, $content, $block ) {
[258] Fix | Delete
static $block_id = 0;
[259] Fix | Delete
++$block_id;
[260] Fix | Delete
[261] Fix | Delete
$parent_page_id = $attributes['parentPageID'];
[262] Fix | Delete
$is_nested = $attributes['isNested'];
[263] Fix | Delete
[264] Fix | Delete
$all_pages = get_pages(
[265] Fix | Delete
array(
[266] Fix | Delete
'sort_column' => 'menu_order,post_title',
[267] Fix | Delete
'order' => 'asc',
[268] Fix | Delete
)
[269] Fix | Delete
);
[270] Fix | Delete
[271] Fix | Delete
// If there are no pages, there is nothing to show.
[272] Fix | Delete
if ( empty( $all_pages ) ) {
[273] Fix | Delete
return;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
$top_level_pages = array();
[277] Fix | Delete
[278] Fix | Delete
$pages_with_children = array();
[279] Fix | Delete
[280] Fix | Delete
$active_page_ancestor_ids = array();
[281] Fix | Delete
[282] Fix | Delete
foreach ( (array) $all_pages as $page ) {
[283] Fix | Delete
$is_active = ! empty( $page->ID ) && ( get_queried_object_id() === $page->ID );
[284] Fix | Delete
[285] Fix | Delete
if ( $is_active ) {
[286] Fix | Delete
$active_page_ancestor_ids = get_post_ancestors( $page->ID );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
if ( $page->post_parent ) {
[290] Fix | Delete
$pages_with_children[ $page->post_parent ][ $page->ID ] = array(
[291] Fix | Delete
'page_id' => $page->ID,
[292] Fix | Delete
'title' => $page->post_title,
[293] Fix | Delete
'link' => get_permalink( $page ),
[294] Fix | Delete
'is_active' => $is_active,
[295] Fix | Delete
);
[296] Fix | Delete
} else {
[297] Fix | Delete
$top_level_pages[ $page->ID ] = array(
[298] Fix | Delete
'page_id' => $page->ID,
[299] Fix | Delete
'title' => $page->post_title,
[300] Fix | Delete
'link' => get_permalink( $page ),
[301] Fix | Delete
'is_active' => $is_active,
[302] Fix | Delete
);
[303] Fix | Delete
[304] Fix | Delete
}
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
$colors = block_core_page_list_build_css_colors( $attributes, $block->context );
[308] Fix | Delete
$font_sizes = block_core_page_list_build_css_font_sizes( $block->context );
[309] Fix | Delete
$classes = array_merge(
[310] Fix | Delete
$colors['css_classes'],
[311] Fix | Delete
$font_sizes['css_classes']
[312] Fix | Delete
);
[313] Fix | Delete
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
[314] Fix | Delete
$css_classes = trim( implode( ' ', $classes ) );
[315] Fix | Delete
[316] Fix | Delete
$nested_pages = block_core_page_list_nest_pages( $top_level_pages, $pages_with_children );
[317] Fix | Delete
[318] Fix | Delete
if ( 0 !== $parent_page_id ) {
[319] Fix | Delete
// If the parent page has no child pages, there is nothing to show.
[320] Fix | Delete
if ( ! array_key_exists( $parent_page_id, $pages_with_children ) ) {
[321] Fix | Delete
return;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
$nested_pages = block_core_page_list_nest_pages(
[325] Fix | Delete
$pages_with_children[ $parent_page_id ],
[326] Fix | Delete
$pages_with_children
[327] Fix | Delete
);
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
$is_navigation_child = array_key_exists( 'showSubmenuIcon', $block->context );
[331] Fix | Delete
[332] Fix | Delete
$open_submenus_on_click = array_key_exists( 'openSubmenusOnClick', $block->context ) ? $block->context['openSubmenusOnClick'] : false;
[333] Fix | Delete
[334] Fix | Delete
$show_submenu_icons = array_key_exists( 'showSubmenuIcon', $block->context ) ? $block->context['showSubmenuIcon'] : false;
[335] Fix | Delete
[336] Fix | Delete
$wrapper_markup = $is_nested ? '%2$s' : '<ul %1$s>%2$s</ul>';
[337] Fix | Delete
[338] Fix | Delete
$items_markup = block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids, $colors );
[339] Fix | Delete
[340] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes(
[341] Fix | Delete
array(
[342] Fix | Delete
'class' => $css_classes,
[343] Fix | Delete
'style' => $style_attribute,
[344] Fix | Delete
)
[345] Fix | Delete
);
[346] Fix | Delete
[347] Fix | Delete
return sprintf(
[348] Fix | Delete
$wrapper_markup,
[349] Fix | Delete
$wrapper_attributes,
[350] Fix | Delete
$items_markup
[351] Fix | Delete
);
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Registers the `core/pages` block on server.
[356] Fix | Delete
*
[357] Fix | Delete
* @since 5.8.0
[358] Fix | Delete
*/
[359] Fix | Delete
function register_block_core_page_list() {
[360] Fix | Delete
register_block_type_from_metadata(
[361] Fix | Delete
__DIR__ . '/page-list',
[362] Fix | Delete
array(
[363] Fix | Delete
'render_callback' => 'render_block_core_page_list',
[364] Fix | Delete
)
[365] Fix | Delete
);
[366] Fix | Delete
}
[367] Fix | Delete
add_action( 'init', 'register_block_core_page_list' );
[368] Fix | Delete
[369] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function