#28030 closed defect (bug) (invalid)
cast $content as a string when calling do_shortcode()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9 |
Component: | Shortcodes | Keywords: | |
Focuses: | Cc: |
Description
There is a warning message in 3.9...
Warning: strpos() expects parameter 1 to be string, array given in /public_html/wp-includes/shortcodes.php on line 193
To fix this we should cast $content as a string in /wp-includes/shortcodes.php
on line 193
Change:
if ( false === strpos( $content, '[' ) ) {
To:
if ( false === strpos( (string) $content, '[' ) ) {
Change History (8)
#3
@
11 years ago
There are numerous people getting this errors from themes and plugins...
http://wordpress.org/support/topic/wp-39-warning-strpos-expects-parameter-1-to-be-string?replies=17
In my case it was this function. $atts
is an array but gets passed to make_more_shortcodes($atts)
which runs do_shortcode()
- this was created for nested shortcodes.
add_shortcode('action', 'sc_action'); function sc_action($atts, $content=null) { $atts = make_more_shortcodes($atts); extract(shortcode_atts(array( 'name' => 'scroll_form', 'text' => 'click here to schedule' ), $atts)); if($name == 'scroll_form') $anchor = '#bigOffer'; return '<a href="'.$anchor.'">'.$text.'</a>'; }
#4
follow-up:
↓ 6
@
11 years ago
You can't cast an array to a string. It should give you a array to string conversion notice. $content should be always a string.
What is the code of make_more_shortcodes()
?
#6
in reply to:
↑ 4
@
11 years ago
Replying to ocean90:
You can't cast an array to a string. It should give you a array to string conversion notice. $content should be always a string.
What is the code of
make_more_shortcodes()
?
This is the make_more_shortcodes()
function...
function make_more_shortcodes($atts) { return do_shortcode(preg_replace('/~([^{|}]*)~/', "[$1]", $atts)); }
Should content ever be an array?