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