public static function fromString($shortcode) { $pattern = get_shortcode_regex(); $nodes = array(); if (preg_match_all("/{$pattern}/s", $shortcode, $matches)) { $node_count = count($matches[0]); for ($node_index = 0; $node_index < $node_count; $node_index++) { if (strlen($matches[2][$node_index])) { // Name $name = $matches[2][$node_index]; // Attributes $atts = shortcode_parse_atts($matches[3][$node_index]); // Instantiate $node = new Shortcode($name, '' === $atts ? array() : $atts); // Siblings $siblings = array(); if (strlen($matches[5][$node_index])) { if (0 === strpos($matches[5][$node_index], '[')) { $siblings = Shortcode::fromString($matches[5][$node_index]); } else { $node->setContent($matches[5][$node_index]); } } foreach ($siblings as $sibling) { $node->add_shortcode($sibling); } // Processed array_push($nodes, $node); } } } return $nodes; }