Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [myform]
- Foo: [mytextbox name="foo"]
- [/myform]
- function shortcode_myform($atts, $content = null) {
- return '<form action="#" method="post">' . do_shortcode($content) . '</form>';
- }
- add_shortcode('myform','shortcode_myform');
- function shortcode_mytextbox($atts) {
- return '<input type="text" name="'$atts['name']'" />';
- }
- add_shortcode('mytextbox','shortcode_mytextbox');
- function attribute_map($str, $att = null) {
- $res = array();
- $reg = get_shortcode_regex();
- preg_match_all('~'.$reg.'~',$str, $matches);
- foreach($matches[2] as $key => $name) {
- $parsed = shortcode_parse_atts($matches[3][$key]);
- $parsed = is_array($parsed) ? $parsed : array();
- if(array_key_exists($name, $res)) {
- $arr = array();
- if(is_array($res[$name])) {
- $arr = $res[$name];
- } else {
- $arr[] = $res[$name];
- }
- $arr[] = array_key_exists($att, $parsed) ? $parsed[$att] : $parsed;
- $res[$name] = $arr;
- } else {
- $res[$name] = array_key_exists($att, $parsed) ? $parsed[$att] : $parsed;
- }
- }
- return $res;
- }
- [outer_shortcode]
- [inner_code url="#" title="Hello"]
- [/outer_shortcode]
- add_shortcode('outer_shortcode',function($atts,$content) {
- return attribute_map($content);
- });
- add_shortcode('inner_shortcode',function($atts,$content) {
- return '';
- });
- Array
- (
- [inner_shortcode] => Array
- (
- [url] => #
- [title] => Hello
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement