mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Shortcodes: Always return an array in shortcode_parse_atts().
Previously, `shortcode_parse_atts()` would return the input (an empty string) if a shortcode had no attributes, even though the documentation said otherwise. Always returning an (empty) array reduces confusion and improves developer experience as the return value does not have to be manually checked in the shortcode itself. Props: nicolefurlan, swissspidy, johnbillion, bedas. Fixes #59249. git-svn-id: https://develop.svn.wordpress.org/trunk@57597 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -105,9 +105,13 @@ class Tests_Shortcode extends WP_UnitTestCase {
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 59249
|
||||
*/
|
||||
public function test_noatts() {
|
||||
do_shortcode( '[test-shortcode-tag /]' );
|
||||
$this->assertSame( '', $this->atts );
|
||||
$this->assertIsArray( $this->atts );
|
||||
$this->assertEmpty( $this->atts );
|
||||
$this->assertSame( 'test-shortcode-tag', $this->tagname );
|
||||
}
|
||||
|
||||
@@ -181,9 +185,13 @@ class Tests_Shortcode extends WP_UnitTestCase {
|
||||
$this->assertSame( 'test-shortcode-tag', $this->tagname );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 59249
|
||||
*/
|
||||
public function test_noatts_enclosing() {
|
||||
do_shortcode( '[test-shortcode-tag]content[/test-shortcode-tag]' );
|
||||
$this->assertSame( '', $this->atts );
|
||||
$this->assertIsArray( $this->atts );
|
||||
$this->assertEmpty( $this->atts );
|
||||
$this->assertSame( 'content', $this->content );
|
||||
$this->assertSame( 'test-shortcode-tag', $this->tagname );
|
||||
}
|
||||
@@ -208,10 +216,14 @@ class Tests_Shortcode extends WP_UnitTestCase {
|
||||
$this->assertSame( 'test-shortcode-tag', $this->tagname );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 59249
|
||||
*/
|
||||
public function test_unclosed() {
|
||||
$out = do_shortcode( '[test-shortcode-tag]' );
|
||||
$this->assertSame( '', $out );
|
||||
$this->assertSame( '', $this->atts );
|
||||
$this->assertIsArray( $this->atts );
|
||||
$this->assertEmpty( $this->atts );
|
||||
$this->assertSame( 'test-shortcode-tag', $this->tagname );
|
||||
}
|
||||
|
||||
@@ -998,4 +1010,13 @@ EOF;
|
||||
);
|
||||
$this->assertSame( 'test-shortcode-tag', $this->tagname );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 59249
|
||||
*/
|
||||
public function test_shortcode_parse_atts_empty() {
|
||||
$out = shortcode_parse_atts( '' );
|
||||
$this->assertIsArray( $out, 'Return value is not an array' );
|
||||
$this->assertEmpty( $out, 'Returned array is not empty' );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user