with shortcode_atts there is no need to check if attr is set

This commit is contained in:
Matthias Pfefferle 2023-01-23 20:11:18 +01:00
parent 75cc35c66e
commit 3666f89f6e

View file

@ -204,21 +204,24 @@ class Shortcodes {
}
$atts = shortcode_atts(
array( 'type' => 'html' ), $atts, $tag );
array(
'type' => 'html',
),
$atts,
$tag
);
if ( is_array( $atts ) && array_key_exists( 'type', $atts ) ) {
if ( $atts['type'] == 'raw' ) {
if ( 'raw' === $atts['type'] ) {
return \get_permalink( $post->ID );
}
if ( $atts['type'] == 'esc' ) {
if ( 'esc' === $atts['type'] ) {
return \esc_url( \get_permalink( $post->ID ) );
}
if ( $atts['type'] == 'blank' ) {
if ( 'blank' === $atts['type'] ) {
return \sprintf( '<a href="%1$s" target="_blank">%1$s</a>', \esc_url( \get_permalink( $post->ID ) ) );
}
}
return \sprintf( '<a href="%1$s">%1$s</a>', \esc_url( \get_permalink( $post->ID ) ) );
}
@ -239,21 +242,25 @@ class Shortcodes {
return '';
}
$atts = shortcode_atts( array( 'type' => 'html' ), $atts, $tag );
$atts = shortcode_atts(
array(
'type' => 'html',
),
$atts,
$tag
);
if ( is_array( $atts ) && array_key_exists( 'type', $atts ) ) {
if ( $atts['type'] == 'raw' ) {
if ( 'raw' === $atts['type'] ) {
return \wp_get_shortlink( $post->ID );
}
if ( $atts['type'] == 'esc' ) {
if ( 'esc' === $atts['type'] ) {
return \esc_url( \wp_get_shortlink( $post->ID ) );
}
if ( $atts['type'] == 'blank' ) {
if ( 'blank' === $atts['type'] ) {
return \sprintf( '<a href="%1$s" target="_blank">%1$s</a>', \esc_url( \wp_get_shortlink( $post->ID ) ) );
}
}
return \sprintf( '<a href="%1$s">%1$s</a>', \esc_url( \wp_get_shortlink( $post->ID ) ) );
}