Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcode: Properly handle case where no attributes are passed #13432

Merged
11 changes: 8 additions & 3 deletions includes/Shortcode/Embed_Shortcode.php
Expand Up @@ -53,11 +53,16 @@
*
* @since 1.1.0
*
* @param array<string, string|int> $attributes Shortcode attributes.
* @param string $content Shortcode content.
* @param array<string, string|int>|string $attributes Shortcode attributes.
* @param string $content Shortcode content.
* @return string Rendered Shortcode
*/
public function render_shortcode( array $attributes, string $content ): string { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
public function render_shortcode( $attributes, string $content ): string { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
// Initialize '$attrs' when not an array OR is an empty string.
if ( empty( $attributes ) || ! \is_array( $attributes ) ) {
$attributes = [];

Check warning on line 63 in includes/Shortcode/Embed_Shortcode.php

View check run for this annotation

Codecov / codecov/patch

includes/Shortcode/Embed_Shortcode.php#L63

Added line #L63 was not covered by tests
}

$attributes = shortcode_atts( $this->default_attrs(), $attributes, self::SHORTCODE_NAME );

$attributes['class'] = 'wp-shortcode-web-stories-embed';
Expand Down