Automattic / Automattic/jetpack
remove_shortcode( 'portfolio' ) probably does more harm than good.
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
The removal of the portfolio shortcode ( at the end of the portfolio_shortcode_html() method ) can lead to unexpected and unwanted results.
The first is that this message is issued.
`Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in C:\apache\htdocs\wordpress\wp-includes\shortcodes.php on line 283
`
The second is that the user doesn't get to see the content they're expecting.
Example: simplest case
- I have a Project (portfolio CPT) entitled "Jetpack [[portfolio]]"
- I have a post that uses the [portfolio] shortcode twice
- I expect to see my project appearing twice
- The second shortcode is run - but doesn't work - we get the Warning message instead
Example: (more complicated)
- Post content is These [portfolio include_type=these] Those [portfolio include_type=those]
- There are multiple projects, categorised these and those
- The Jetpack [[portfolio]] project is one of 'these'
- No those are listed.
- Swap the shortcodes around and it works.
Workaround:
Use [jetpack_portfolio] instead. Although this produces another interesting side effect due to the fact that the portfolio shortcode is no longer present - so strip_shortcodes doesn't do the same as it did before.
Comments:
- I assume that the code was written in an attempt prevent an infinite loop.
- With WordPress SEO active preventing these loops can get tricky.
- e.g. Create a project that contains [[portfolio]] and try to view it.
- Yes, it's an edge case
- I'd rather the remove_shortcode() was removed than also checking for [jetpack_testimonial] as well. :-)
Contributor guide
Research direction
Start by inspecting the portfolio_shortcode_html() method and its remove_shortcode('portfolio') call, then trace the callback warning in wp-includes/shortcodes.php around line 283. Compare the reported repeated [portfolio] cases with the [jetpack_portfolio] workaround and strip_shortcodes behavior; done means the warning and missing repeated content are addressed without introducing the reported recursive shortcode problem.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100