Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. [myform]
  2. Foo: [mytextbox name="foo"]
  3. [/myform]
  4.  
  5. function shortcode_myform($atts, $content = null) {
  6. return '<form action="#" method="post">' . do_shortcode($content) . '</form>';
  7. }
  8. add_shortcode('myform','shortcode_myform');
  9.  
  10. function shortcode_mytextbox($atts) {
  11. return '<input type="text" name="'$atts['name']'" />';
  12. }
  13. add_shortcode('mytextbox','shortcode_mytextbox');
  14.  
  15. function attribute_map($str, $att = null) {
  16. $res = array();
  17. $reg = get_shortcode_regex();
  18. preg_match_all('~'.$reg.'~',$str, $matches);
  19. foreach($matches[2] as $key => $name) {
  20. $parsed = shortcode_parse_atts($matches[3][$key]);
  21. $parsed = is_array($parsed) ? $parsed : array();
  22.  
  23. if(array_key_exists($name, $res)) {
  24. $arr = array();
  25. if(is_array($res[$name])) {
  26. $arr = $res[$name];
  27. } else {
  28. $arr[] = $res[$name];
  29. }
  30.  
  31. $arr[] = array_key_exists($att, $parsed) ? $parsed[$att] : $parsed;
  32. $res[$name] = $arr;
  33.  
  34. } else {
  35. $res[$name] = array_key_exists($att, $parsed) ? $parsed[$att] : $parsed;
  36. }
  37. }
  38.  
  39. return $res;
  40. }
  41.  
  42. [outer_shortcode]
  43. [inner_code url="#" title="Hello"]
  44. [/outer_shortcode]
  45.  
  46. add_shortcode('outer_shortcode',function($atts,$content) {
  47. return attribute_map($content);
  48. });
  49.  
  50. add_shortcode('inner_shortcode',function($atts,$content) {
  51. return '';
  52. });
  53.  
  54. Array
  55. (
  56. [inner_shortcode] => Array
  57. (
  58. [url] => #
  59. [title] => Hello
  60. )
  61.  
  62. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement