PluginProbe
YayMail – WooCommerce Email Customizer / 4.3.4
YayMail – WooCommerce Email Customizer v4.3.4
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Shortcodes / ShortcodesExecutor.php

ShortcodesExecutor.php in YayMail – WooCommerce Email Customizer 4.3.4, at src/Shortcodes/ShortcodesExecutor.php

75 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Shortcodes;
4
5 /**
6 * Class declaration
7 */
8 class ShortcodesExecutor {
9
10 private $shortcodes = [];
11
12 private $data = [
13 'is_sample' => true,
14 ];
15
16 public function __construct( $shortcodes = [], $data = [] ) {
17 if ( ! isset( $shortcodes ) || ! is_array( $shortcodes ) ) {
18 return;
19 }
20
21 /**
22 * Extra shortcodes: order meta...
23 */
24 $this->shortcodes = apply_filters( 'yaymail_extra_shortcodes', $shortcodes, $data );
25
26 if ( isset( $data ) && is_array( $data ) ) {
27 $this->data = $data;
28 }
29
30 $this->initialize_shortcodes();
31 }
32
33 public function initialize_shortcodes() {
34 if ( empty( $this->shortcodes ) ) {
35 return;
36 }
37
38 foreach ( $this->shortcodes as $shortcode_information ) {
39 $callback = isset( $shortcode_information['callback'] ) ? $shortcode_information['callback'] : '';
40 $callback_args = isset( $shortcode_information['callback_args'] ) ? $shortcode_information['callback_args'] : '';
41
42 $data = ! empty( $callback_args ) && is_array( $callback_args ) ? array_merge( $this->data, $callback_args ) : $this->data;
43
44 if ( is_callable( $callback ) ) {
45 add_shortcode(
46 $shortcode_information['name'],
47 function( $shortcode_atts ) use ( $callback, $data ) {
48 return call_user_func( $callback, $data, $shortcode_atts );
49 }
50 );
51 }
52 }
53 }
54
55 public function get_shortcodes_content() {
56 if ( empty( $this->shortcodes ) ) {
57 return [];
58 }
59
60 $result = [];
61
62 foreach ( $this->shortcodes as $shortcode_information ) {
63 $shortcode_name = '[' . $shortcode_information['name'] . ']';
64 $result[] = array_merge(
65 $shortcode_information,
66 [
67 'content' => do_shortcode( $shortcode_name ),
68 ]
69 );
70 }
71
72 return $result;
73 }
74 }
75