Opened 6 years ago
Closed 5 years ago
#31983 closed defect (bug) (invalid)
PHP warning when shortcode function does not exist
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.1.1 |
Component: | Shortcodes | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
The problem is on wp-includes/shortcodes.php line 280: it may sometimes generates warnings because $m[5] is set but $shortcode_tags[$tag] is not set.
Just add those three lines after line 278:
279 if (!isset($shortcode_tags[$tag])) { 280 return false; 281 }
So no warning is raised. Here's a sample of the warning raised - just in case:
PHP Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /mywebpath/wp-includes/shortcodes.php on line 286, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP Stack trace:, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 1. {main}() /mywebpath/index.php:0, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 2. require() /mywebpath/index.php:17, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 3. require_once() /mywebpath/wp-blog-header.php:16, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 4. include() /mywebpath/wp-includes/template-loader.php:74, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 5. the_content() /mywebpath/wp-content/themes/krystallopolis/index.php:115, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 6. apply_filters() /mywebpath/wp-includes/post-template.php:221, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 7. call_user_func_array:{/mywebpath/wp-includes/plugin.php:213}() /mywebpath/wp-includes/plugin.php:213, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 8. do_shortcode() /mywebpath/wp-includes/plugin.php:213, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 9. preg_replace_callback() /mywebpath/wp-includes/shortcodes.php:197, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 10. do_shortcode_tag() /mywebpath/wp-includes/shortcodes.php:197, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit PHP 11. call_user_func:{/mywebpath/wp-includes/shortcodes.php:286}() /mywebpath/wp-includes/shortcodes.php:286, referer: http://mywebsite/wp-admin/post.php?post=ccc&action=edit
Change History (5)
#2
follow-up:
↓ 3
@
6 years ago
Hi,
It's after a call to
remove_shortcode( 'anyshortcode' );
If I try to call "by hand"
do_shortcode( 'anyshortcode' )
(i.e.) the shortcode that I've just removed, I get this warning.
#3
in reply to:
↑ 2
@
6 years ago
Replying to olivier.pons:
(i.e.) the shortcode that I've just removed, I get this warning.
I can't reproduce that. do_shortcode_tag()
is only called for your shortcode if it's still a part of get_shortcode_regex()
when do_shortcode() is called. Otherwise, the shortcode is just displayed as is.
Note: See
TracTickets for help on using
tickets.
Thanks for the report, Olivier!
Can you let us know how to reproduce this please? Which shortcode are you using? What does the shortcode callback function look like?
The warning sounds like you have a callback function hooked which doesn't actually exist. Can you double check the callback function name?