WordPress Download Alias: A Simple Solution for Multiple WordPress Sites
As you may know, do_shortcode() is used in countless plugins and themes. So there is currently no option to deprecate it. But if the community can start building a consensus around the alias, apply_shortcodes(), then deprecation may eventually become a real option in the future.
WordPress 5.4 introduces a new function \u2013 apply_shortcodes(). It's an alias for the current do_shortcode() function.\n\n\n\nThe semantics of do_* implies the function displays the result of the shortcode. But that's not actually the case. In fact, do_shortcode() needs to be echoed to display its result. \n\n\n\nHere is the current implementation:\n\n\n\necho do_shortcode( '[wporg]My Text[/wporg]' );\n// Displays the result of the shortcode\n\n\n\nSemantically, we should be able to do this:\n\n\n\ndo_shortcode( '[wporg]My Text[/wporg]' );\n// but it doesn\u2019t display anything\u2026\n\n\n\nAs you may know, do_shortcode() is used in countless plugins and themes. So there is currently no option to deprecate it. But if the community can start building a consensus around the alias, apply_shortcodes(), then deprecation may eventually become a real option in the future.\n\n\n\nThere is a precedent for making this move. It's the same process the core team followed with get_permalink() and get_the_permalink(). \n\n\n\napply_shortcodes is meant to get better semantics: instead of performing an action and outputting to the current buffer, the idea is to apply filters to the input and return a result. The process is simpler, cleaner and more maintainable \u2013 not to mention easier to teach new developers.\n\n\n\napply_shortcodes() can be used the same way do_shortcode() is currently used:\n\n\n\necho apply_shortcodes( '[wporg]My Text[/wporg]' );\n// Displays the result of the shortcode\n\n\n\nThemes/Plugins authors and WordPress developers are invited to start using apply_shortcodes() instead of do_shortcode(). \n\n\n\nTo be clear, there is no plan for deprecating the former function right now. But the sooner developers can all switch to the much more semantic apply_shortcodes(), the sooner the core team can plan to deprecate the old function. With WordPress 5.4, apply_shortcodes() is now the recommended way to display the result of a shortcode.\n\n\n\n\n\n\n\nFor reference, see the related Trac ticket: #37422\n\n\n\nCopy review: @marybaum\n\n\n#5-4, #dev-notes, #shortcodes","contentFiltered":"WordPress 5.4 introduces a new function \u2013 apply_shortcodes(). It\u2019s an alias for the current do_shortcode() function.\n\n\n\nThe semantics of do_* implies the function\u00a0displays the result of the shortcodeShortcode A shortcode is a placeholder used within a WordPress post, page, or widget to insert a form or function generated by a plugin in a specific location on your site.. But that\u2019s not actually the case. In fact, do_shortcode() needs to be echoed to display its result. \n\n\n\nHere is the current implementation:\n\n\n\necho do_shortcode( '[wporg]My Text[/wporg]' );\n// Displays the result of the shortcode\n\n\n\nSemantically, we should be able to do this:\n\n\n\ndo_shortcode( '[wporg]My Text[/wporg]' );\n// but it doesn\u2019t display anything\u2026\n\n\n\nAs you may know, do_shortcode()\u00a0is used in countless plugins and themes. So there is currently no option to deprecate it. But if the community can start building a consensus around the alias, apply_shortcodes(), then deprecation may eventually become a real option in the future.\n\n\n\nThere is a precedent for making this move. It\u2019s the same process the coreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. team followed with\u00a0get_permalink() and get_the_permalink(). \n\n\n\napply_shortcodes is meant to get better semantics: instead of performing an action and outputting to the current buffer, the idea is to apply filters to the input and return a result. The process is simpler, cleaner and more maintainable \u2013 not to mention easier to teach new developers.\n\n\n\napply_shortcodes() can be used the same way do_shortcode() is currently used:\n\n\n\necho apply_shortcodes( '[wporg]My Text[/wporg]' );\n// Displays the result of the shortcode\n\n\n\nThemes/Plugins authors and WordPress developers are invited to start using apply_shortcodes() instead of do_shortcode(). \n\n\n\nTo be clear, there is no plan for deprecating the former function right now. But the sooner developers can all switch to the much more semantic apply_shortcodes(), the sooner the core team can plan to deprecate the old function. With WordPress 5.4, apply_shortcodes() is now the recommended way to display the result of a shortcode.\n\n\n\nFor reference, see the related TracTrac An open source project by Edgewall Software that serves as a bug tracker and project management tool for WordPress. ticketticket Created for both bug reports and feature development on the bug tracker.: #37422\n\n\n\nCopy review: @marybaum\n#5-4, #dev-notes, #shortcodesShare this:
TwitterFacebook","permalink":"https://make.wordpress.org/core/2020/02/13/wordpress-5-4-introduces-apply-shortcodes-as-an-alias-for-do-shortcode/","unixtime":1581631197,"unixtimeModified":1581999549,"entryHeaderMeta":"","linkPages":"","footerEntryMeta":"","tagsRaw":"5.4, dev-notes, shortcodes","tagsArray":["label":"5.4","count":53,"link":"https://make.wordpress.org/core/tag/5-4/","label":"dev-notes","count":472,"link":"https://make.wordpress.org/core/tag/dev-notes/","label":"shortcodes","count":30,"link":"https://make.wordpress.org/core/tag/shortcodes/"],"loginRedirectURL":"https://login.wordpress.org/?redirect_to=https%3A%2F%2Fmake.wordpress.org%2Fcore%2F2020%2F02%2F13%2Fwordpress-5-4-introduces-apply-shortcodes-as-an-alias-for-do-shortcode%2F&locale=en_US","hasPrevPost":true,"prevPostTitle":"An updated Button component in WordPress 5.4","prevPostURL":"https://make.wordpress.org/core/2020/02/13/an-updated-button-component-in-wordpress-5-4/","hasNextPost":true,"nextPostTitle":"CSS Chat Summary: 13 February 2020","nextPostURL":"https://make.wordpress.org/core/2020/02/14/css-chat-summary-13-february-2020/","commentsOpen":false,"is_xpost":false,"editURL":null,"postActions":"Post Actions - Scroll - Shortlink","comments":["type":"comment","id":"37940","postID":"79518","postTitleRaw":"WordPress 5.4 introduces apply_shortcodes() as an alias for do_shortcode()","cssClasses":"comment byuser comment-author-cybr even thread-even depth-1","parentID":"0","contentRaw":"I was confused by this post. To summarize it in 3 lines:\n[code]function apply_shortcodes( $content, $ignore_html = false ) \n\treturn do_shortcode( $content, $ignore_html );\n[/code]\n\nIn other words: it's exactly the same. It's an alias. The name changed to make it easier to understand what the function does.","contentFiltered":"I was confused by this post. To summarize it in 3 lines:\n\nfunction apply_shortcodes( $content, $ignore_html = false ) \n\treturn do_shortcode( $content, $ignore_html );\n\nIn other words: it\u2019s exactly the same. It\u2019s an alias. The name changed to make it easier to understand what the function does.\n","permalink":"https://make.wordpress.org/core/2020/02/13/wordpress-5-4-introduces-apply-shortcodes-as-an-alias-for-do-shortcode/#comment-37940","unixtime":1581641529,"loginRedirectURL":"https://login.wordpress.org/?redirect_to=https%3A%2F%2Fmake.wordpress.org%2Fcore%2F2020%2F02%2F13%2Fwordpress-5-4-introduces-apply-shortcodes-as-an-alias-for-do-shortcode%2F%23comment-37940&locale=en_US","approved":true,"isTrashed":false,"prevDeleted":"","editURL":null,"depth":1,"commentDropdownActions":"","commentFooterActions":"","commentTrashedActions":" - Untrash","mentions":[],"mentionContext":"","commentCreated":"1581641529","hasChildren":false,"userLogin":"Cybr","userNicename":"cybr","type":"comment","id":"37942","postID":"79518","postTitleRaw":"WordPress 5.4 introduces apply_shortcodes() as an alias for do_shortcode()","cssClasses":"comment byuser comment-author-backups odd alt depth-2","parentID":"37940","contentRaw":"I had the same feeling one would expect it to be like this\n\n[code]function do_shortcodes( $content, $ignore_html = false ) \n return apply_shortcode( $content, $ignore_html );\n[/code]\n\nIf you want to convert to apply_shortcodes that would be the logical way. Now it is pretty useless.","contentFiltered":"I had the same feeling one would expect it to be like this\nfunction do_shortcodes( $content, $ignore_html = false ) \n return apply_shortcode( $content, $ignore_html );\n\nIf you want to convert to apply_shortcodes that would be the logical way. Now it is pretty useless.\n","permalink":"https://make.wordpress.org/core/2020/02/13/wordpress-5-4-introduces-apply-shortcodes-as-an-alias-for-do-shortcode/#comment-37942","unixtime":1581684779,"loginRedirectURL":"https://login.wordpress.org/?redirect_to=https%3A%2F%2Fmake.wordpress.org%2Fcore%2F2020%2F02%2F13%2Fwordpress-5-4-introduces-apply-shortcodes-as-an-alias-for-do-shortcode%2F%23comment-37942&locale=en_US","approved":true,"isTrashed":false,"prevDeleted":"","editURL":null,"depth":2,"commentDropdownActions":"","commentFooterActions":"","commentTrashedActions":" - Untrash","mentions":[],"mentionContext":"","commentCreated":"1581684779","hasChildren":false,"userLogin":"BackuPs","userNicename":"backups","type":"comment","id":"37943","postID":"79518","postTitleRaw":"WordPress 5.4 introduces apply_shortcodes() as an alias for do_shortcode()","cssClasses":"comment byuser comment-author-backups even depth-3","parentID":"37942","contentRaw":"i ment do_shortcode not do_shortcodes\n\n[code]function do_shortcode( $content, $ignore_h