Merge remote-tracking branch 'upstream/develop' into category-widget

This commit is contained in:
IanDelMar 2022-08-06 07:59:06 +02:00
commit 1f38b39ae7
9 changed files with 146 additions and 31 deletions

View File

@ -78,7 +78,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
array(
'default' => 'container',
'type' => 'theme_mod',
'sanitize_callback' => 'understrap_theme_slug_sanitize_select',
'sanitize_callback' => 'understrap_customize_sanitize_select',
'capability' => 'edit_theme_options',
)
);
@ -123,7 +123,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
),
'section' => 'understrap_theme_layout_options',
'type' => 'select',
'sanitize_callback' => 'understrap_theme_slug_sanitize_select',
'sanitize_callback' => 'understrap_customize_sanitize_select',
'choices' => array(
'collapse' => __( 'Collapse', 'understrap' ),
'offcanvas' => __( 'Offcanvas', 'understrap' ),
@ -155,7 +155,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
),
'section' => 'understrap_theme_layout_options',
'type' => 'select',
'sanitize_callback' => 'understrap_theme_slug_sanitize_select',
'sanitize_callback' => 'understrap_customize_sanitize_select',
'choices' => array(
'right' => __( 'Right sidebar', 'understrap' ),
'left' => __( 'Left sidebar', 'understrap' ),
@ -195,7 +195,7 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) {
} // End of if function_exists( 'understrap_theme_customize_register' ).
add_action( 'customize_register', 'understrap_theme_customize_register' );
if ( ! function_exists( 'understrap_theme_slug_sanitize_select' ) ) {
if ( ! function_exists( 'understrap_customize_sanitize_select' ) ) {
/**
* Sanitize select.
*
@ -204,7 +204,7 @@ if ( ! function_exists( 'understrap_theme_slug_sanitize_select' ) ) {
* @return string|bool Sanitized slug if it is a valid choice; the setting default for
* invalid choices and false in all other cases.
*/
function understrap_theme_slug_sanitize_select( $input, $setting ) {
function understrap_customize_sanitize_select( $input, $setting ) {
// Ensure input is a slug (lowercase alphanumeric characters, dashes and underscores are allowed only).
$input = sanitize_key( $input );

View File

@ -8,6 +8,25 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! function_exists( 'understrap_theme_slug_sanitize_select' ) ) {
/**
* Sanitize select.
*
* @param string $input Slug to sanitize.
* @param WP_Customize_Setting $setting Setting instance.
* @return string|bool Sanitized slug if it is a valid choice; the setting default for
* invalid choices and false in all other cases.
*/
function understrap_theme_slug_sanitize_select( $input, $setting ) {
_deprecated_function(
'understrap_theme_slug_sanitize_select',
'1.2.0',
'understrap_customize_sanitize_select'
);
return understrap_customize_sanitize_select( $input, $setting );
}
}
if ( ! function_exists( 'understrap_adjust_body_class' ) ) {
/**
* Setup body classes.

View File

@ -70,7 +70,7 @@ if ( ! function_exists( 'understrap_setup' ) ) {
/*
* Adding Thumbnail basic support
*/
add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-thumbnails', true );
/*
* Adding support for Widget edit icons in customizer

View File

@ -70,28 +70,70 @@ if ( ! function_exists( 'understrap_entry_footer' ) ) {
function understrap_entry_footer() {
// Hide category and tag text for pages.
if ( 'post' === get_post_type() ) {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'understrap' ) );
if ( $categories_list && understrap_categorized_blog() ) {
/* translators: %s: Categories of current post */
printf( '<span class="cat-links">' . esc_html__( 'Posted in %s', 'understrap' ) . '</span>', $categories_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'understrap' ) );
if ( $tags_list && ! is_wp_error( $tags_list ) ) {
/* translators: %s: Tags of current post */
printf( '<span class="tags-links">' . esc_html__( 'Tagged %s', 'understrap' ) . '</span>', $tags_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
echo '<span class="comments-link">';
comments_popup_link( esc_html__( 'Leave a comment', 'understrap' ), esc_html__( '1 Comment', 'understrap' ), esc_html__( '% Comments', 'understrap' ) );
echo '</span>';
understrap_categories_tags_list();
}
understrap_comments_popup_link();
understrap_edit_post_link();
}
}
if ( ! function_exists( 'understrap_categories_tags_list' ) ) {
/**
* Displays a list of categories and a list of tags.
*/
function understrap_categories_tags_list() {
understrap_categories_list();
understrap_tags_list();
}
}
if ( ! function_exists( 'understrap_categories_list' ) ) {
/**
* Displays a list of categories.
*/
function understrap_categories_list() {
/* translators: used between list items, there is a space after the comma */
$categories_list = get_the_category_list( esc_html__( ', ', 'understrap' ) );
if ( $categories_list && understrap_categorized_blog() ) {
/* translators: %s: Categories of current post */
printf( '<span class="cat-links">' . esc_html__( 'Posted in %s', 'understrap' ) . '</span>', $categories_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
if ( ! function_exists( 'understrap_tags_list' ) ) {
/**
* Displays a list of tags.
*/
function understrap_tags_list() {
/* translators: used between list items, there is a space after the comma */
$tags_list = get_the_tag_list( '', esc_html__( ', ', 'understrap' ) );
if ( $tags_list && ! is_wp_error( $tags_list ) ) {
/* translators: %s: Tags of current post */
printf( '<span class="tags-links">' . esc_html__( 'Tagged %s', 'understrap' ) . '</span>', $tags_list ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
}
if ( ! function_exists( 'understrap_comments_popup_link' ) ) {
/**
* Displays the link to the comments for the current post.
*/
function understrap_comments_popup_link() {
if ( is_single() || post_password_required() || ! comments_open() || 0 === absint( get_comments_number() ) ) {
return;
}
echo '<span class="comments-link">';
comments_popup_link(
esc_html__( 'Leave a comment', 'understrap' ),
esc_html__( '1 Comment', 'understrap' ),
esc_html__( '% Comments', 'understrap' )
);
echo '</span>';
}
}
if ( ! function_exists( 'understrap_categorized_blog' ) ) {
/**
* Returns true if a blog has more than 1 category.

View File

@ -118,6 +118,61 @@ if ( ! function_exists( 'understrap_add_block_widget_search_classes' ) ) {
}
add_filter( 'render_block_core/search', 'understrap_add_block_widget_search_classes', 10, 2 );
/**
* Add active class of first item of carousel hero widget area.
*
* @param array $params {
* Parameters passed to a widgets display callback.
*
* @type array $args {
* An array of widget display arguments.
*
* @type string $name Name of the sidebar the widget is assigned to.
* @type string $id ID of the sidebar the widget is assigned to.
* @type string $description The sidebar description.
* @type string $class CSS class applied to the sidebar container.
* @type string $before_widget HTML markup to prepend to each widget in the sidebar.
* @type string $after_widget HTML markup to append to each widget in the sidebar.
* @type string $before_title HTML markup to prepend to the widget title when displayed.
* @type string $after_title HTML markup to append to the widget title when displayed.
* @type string $widget_id ID of the widget.
* @type string $widget_name Name of the widget.
* }
* @type array $widget_args {
* An array of multi-widget arguments.
*
* @type int $number Number increment used for multiples of the same widget.
* }
* }
* @return array Maybe filtered parameters.
*/
function understrap_hero_active_carousel_item( $params ) {
if (
! isset( $params[0] )
|| ! isset( $params[0]['id'] )
|| 'hero' !== $params[0]['id']
) {
return $params;
}
static $item_number = 1;
if (
1 === $item_number
&& isset( $params[0]['before_widget'] )
&& is_string( $params[0]['before_widget'] )
) {
$params[0]['before_widget'] = str_replace(
'carousel-item',
'carousel-item active',
$params[0]['before_widget']
);
}
$item_number++;
return $params;
}
add_filter( 'dynamic_sidebar_params', 'understrap_hero_active_carousel_item' );
/**
* Add filter to the parameters passed to a widget's display callback.
* The filter is evaluated on both the front and the back end!
@ -157,7 +212,7 @@ if ( ! function_exists( 'understrap_widget_classes' ) ) {
* @type int $number Number increment used for multiples of the same widget.
* }
* }
* @return array $params
* @return array Maybe filtered parameters.
*/
function understrap_widget_classes( $params ) {

View File

@ -1,7 +1,6 @@
<?xml version="1.0"?>
<phpmd-baseline>
<violation rule="PHPMD\Rule\Design\LongMethod" file="inc/customizer.php"/>
<violation rule="PHPMD\Rule\CyclomaticComplexity" file="inc/template-tags.php"/>
<violation rule="PHPMD\Rule\Naming\LongVariable" file="inc/widgets.php"/>
<violation rule="PHPMD\Rule\UnusedFormalParameter" file="inc/woocommerce.php"/>
</phpmd-baseline>

View File

@ -101,12 +101,12 @@ parameters:
path: inc/widgets.php
-
message: "#^Function understrap_add_widget_categories_class\\(\\) has parameter \\$cat_args with no value type specified in iterable type array\\.$#"
message: "#^Function understrap_hero_active_carousel_item\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
count: 1
path: inc/widgets.php
-
message: "#^Function understrap_add_widget_categories_class\\(\\) return type has no value type specified in iterable type array\\.$#"
message: "#^Function understrap_hero_active_carousel_item\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: inc/widgets.php

View File

@ -50,3 +50,7 @@ parameters:
- '#Function understrap_woocommerce_wrapper_end\(\) has no return type specified.#'
- '#Function understrap_wpcom_setup\(\) has no return type specified.#'
- '#Function understrap_wpcom_styles\(\) has no return type specified.#'
- '#Function understrap_categories_tags_list\(\) has no return type specified.#'
- '#Function understrap_categories_list\(\) has no return type specified.#'
- '#Function understrap_tags_list\(\) has no return type specified.#'
- '#Function understrap_comments_popup_link\(\) has no return type specified.#'

View File

@ -39,9 +39,5 @@ defined( 'ABSPATH' ) || exit;
</div><!-- .carousel -->
<script>
jQuery( ".carousel-item" ).first().addClass( "active" );
</script>
<?php
endif;