| @@ -287,9 +287,9 @@ | ||
| 287 | 287 | |
| 288 | 288 | return [ $name, $value ]; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - function run_non_fn_snippet( $id, $code = null, $test = false ) { | |
| 291 | + function run_non_fn_snippet( $id, $code = null, $test = false, $prefix = '' ) { | |
| 292 | 292 | // Retrieve the snippet code from the provided code or via the snippet ID. |
| 293 | 293 | if ( $code ) { |
| 294 | 294 | $snippet = [ 'code' => $code ]; |
| 295 | 295 | } else { |
| @@ -301,8 +301,12 @@ | ||
| 301 | 301 | |
| 302 | 302 | if ( $test ) { |
| 303 | 303 | $snippet['code'] = preg_replace( '/echo\s+(.+?);/s', 'echo $1 . "\n";', $snippet['code'] ); |
| 304 | 304 | } |
| 305 | + | |
| 306 | + if( $prefix ) { | |
| 307 | + $snippet['code'] = $prefix . "\n" . $snippet['code']; | |
| 308 | + } | |
| 305 | 309 | |
| 306 | 310 | $error = null; |
| 307 | 311 | $output = null; |
| 308 | 312 | |
| @@ -644,16 +648,26 @@ | ||
| 644 | 648 | |
| 645 | 649 | #endregion |
| 646 | 650 | |
| 647 | 651 | #region Shortcodes |
| 652 | + function separate_mwcode_atts( $atts ) { | |
| 648 | 653 | |
| 654 | + if( array_key_exists( 'id', $atts ) ) unset( $atts['id'] ); | |
| 655 | + if( array_key_exists( 'target', $atts ) ) unset( $atts['target'] ); | |
| 656 | + if( array_key_exists( 'code', $atts ) ) unset( $atts['code'] ); | |
| 657 | + | |
| 658 | + return $atts; | |
| 659 | + } | |
| 660 | + | |
| 649 | 661 | function content_shortcode( $atts ) { |
| 650 | 662 | |
| 663 | + $user_atts = $this->separate_mwcode_atts( $atts ); | |
| 664 | + | |
| 651 | 665 | $atts = shortcode_atts( array( |
| 652 | - 'id' => null, | |
| 653 | - 'target' => null, | |
| 654 | - 'code' => null, | |
| 655 | - ), $atts ); | |
| 666 | + 'id' => null, | |
| 667 | + 'target' => null, // js or php | |
| 668 | + 'code' => null, // For Guttenberg block usage | |
| 669 | + ), $atts, 'code-engine' ); | |
| 656 | 670 | |
| 657 | 671 | $id = $atts['id']; |
| 658 | 672 | $target = $atts['target']; |
| 659 | 673 | $code = $atts['code']; |
| @@ -736,9 +750,10 @@ | ||
| 736 | 750 | $output = '<script>' . $snippet['code'] . '</script>'; |
| 737 | 751 | } |
| 738 | 752 | |
| 739 | 753 | if ( $is_content_php ) { |
| 740 | - $output = $this->run_non_fn_snippet( $id ); | |
| 754 | + $prefix = "\$mwcode_atts = unserialize( '" . serialize( $user_atts ) . "' );"; | |
| 755 | + $output = $this->run_non_fn_snippet( $id, null, false, $prefix ); | |
| 741 | 756 | } |
| 742 | 757 | |
| 743 | 758 | return $output; |
| 744 | 759 | } |