( $conflictingShortcodes as $shortcode ) { $shortcodeTag = str_replace( [ '[', ']' ], '', $shortcode ); if ( array_key_exists( $shortcodeTag, $shortcode_tags ) ) { $tagsToRemove[ $shortcodeTag ] = $shortcode_tags[ $shortcodeTag ]; } } // Remove all conflicting shortcodes before parsing the content. foreach ( $tagsToRemove as $shortcodeTag => $shortcodeCallback ) { remove_shortcode( $shortcodeTag ); } if ( $postId ) { global $post; $post = get_post( $postId ); if ( is_a( $post, 'WP_Post' ) ) { // Add the current post to the loop so that shortcodes can use it if needed. setup_postdata( $post ); } } // Set a flag to indicate Divi that it's processing internal content. // https://github.com/awesomemotive/aioseo/issues/5099 $default = aioseo()->helpers->setDiviInternalRendering( true ); $content = do_shortcode( $content ); // Reset the Divi flag to its default value. aioseo()->helpers->setDiviInternalRendering( $default ); if ( $postId ) { wp_reset_postdata(); } // Add back shortcodes as remove_shortcode() disables them site-wide. foreach ( $tagsToRemove as $shortcodeTag => $shortcodeCallback ) { add_shortcode( $shortcodeTag, $shortcodeCallback ); } return $content; } /** * Extracts the shortcode tags from the content. * * @since 4.1.2 * * @param string $content The content. * @return array $tags The shortcode tags. */ private function getShortcodeTags( $content ) { $tags = []; $pattern = '\\[(\\[?)([^\s]*)(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)'; if ( preg_match_all( "#$pattern#s", $content, $matches ) && array_key_exists( 2, $matches ) ) { $tags = array_unique( $matches[2] ); } if ( ! count( $tags ) ) { return $tags; } // Extract nested shortcodes. foreach ( $matches[5] as $innerContent ) { $tags = array_merge( $tags, $this->getShortcodeTags( $innerContent ) ); } return $tags; } }