@@ -47,18 +47,17 @@ function baztag_func($atts, $content='') {
4747
4848$ shortcode_tags = array ();
4949
50- function add_shortcode ($ tag , $ func, $ after_formatting = false ) {
50+ function add_shortcode ($ tag , $ func ) {
5151 global $ shortcode_tags ;
5252
53- if ( is_callable ($ func ) ) {
54- $ shortcode_tags [($ after_formatting )? 11 :9 ][$ tag ] = $ func ;
55- }
53+ if ( is_callable ($ func ) )
54+ $ shortcode_tags [$ tag ] = $ func ;
5655}
5756
5857function remove_shortcode ($ tag ) {
5958 global $ shortcode_tags ;
6059
61- unset($ shortcode_tags [9 ][ $ tag ], $ shortcode_tags [ 11 ][ $ tag ]);
60+ unset($ shortcode_tags [$ tag ]);
6261}
6362
6463function remove_all_shortcodes () {
@@ -67,48 +66,32 @@ function remove_all_shortcodes() {
6766 $ shortcode_tags = array ();
6867}
6968
70- function do_shortcode_after_formatting ($ content ) {
71- return do_shortcode ($ content , true );
72- }
73- function do_shortcode ($ content , $ after_formatting = false ) {
74- $ pattern = get_shortcode_regex ($ after_formatting );
75- if (!$ pattern ) {
76- return $ content ;
77- } else {
78- $ callback_func = 'do_shortcode_tag ' ;
79- if ($ after_formatting )
80- $ callback_func .= '_after_formatting ' ;
81-
82- return preg_replace_callback ('/ ' . $ pattern . '/s ' , $ callback_func , $ content );
83- }
84- }
85- function get_shortcode_regex ($ after_formatting ) {
69+ function do_shortcode ($ content ) {
8670 global $ shortcode_tags ;
8771
88- if (empty ($ shortcode_tags[( $ after_formatting )? 11 : 9 ]) || !is_array ($ shortcode_tags[( $ after_formatting )? 11 : 9 ] ))
89- return false ;
72+ if (empty ($ shortcode_tags) || !is_array ($ shortcode_tags ))
73+ return $ content ;
9074
91- $ tagnames = array_keys ($ shortcode_tags[( $ after_formatting )? 11 : 9 ] );
75+ $ tagnames = array_keys ($ shortcode_tags );
9276 $ tagregexp = join ( '| ' , array_map ('preg_quote ' , $ tagnames ) );
9377
94- return '\[( ' .$ tagregexp .')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])? ' ;
95- }
78+ $ pattern = '/\[( ' .$ tagregexp .')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/s ' ;
9679
97- function do_shortcode_tag_after_formatting ($ m ) {
98- return do_shortcode_tag ($ m , true );
80+ return preg_replace_callback ($ pattern , 'do_shortcode_tag ' , $ content );
9981}
100- function do_shortcode_tag ($ m , $ after_formatting = false ) {
82+
83+ function do_shortcode_tag ($ m ) {
10184 global $ shortcode_tags ;
10285
10386 $ tag = $ m [1 ];
10487 $ attr = shortcode_parse_atts ($ m [2 ]);
10588
10689 if ( isset ($ m [4 ]) ) {
10790 // enclosing tag - extra parameter
108- return call_user_func ($ shortcode_tags [( $ after_formatting )? 11 : 9 ][ $ tag ], $ attr , $ m [4 ]);
91+ return call_user_func ($ shortcode_tags [$ tag ], $ attr , $ m [4 ]);
10992 } else {
11093 // self-closing tag
111- return call_user_func ($ shortcode_tags [( $ after_formatting )? 11 : 9 ][ $ tag ], $ attr );
94+ return call_user_func ($ shortcode_tags [$ tag ], $ attr );
11295 }
11396}
11497
@@ -147,7 +130,6 @@ function shortcode_atts($pairs, $atts) {
147130 return $ out ;
148131}
149132
150- add_filter ( 'the_content ' , 'do_shortcode ' , 9 );
151- add_filter ( 'the_content ' , 'do_shortcode_after_formatting ' , 11 );
133+ add_filter ('the_content ' , 'do_shortcode ' , 11 ); // AFTER wpautop()
152134
153135?>
0 commit comments