PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.5
WP Coder – Insert & Manage Code Snippets v4.5
4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 3.5.1 All 39 releases
← All changes | includes/class-wowp-public.php +71 -13 3.04.5 View file →
@@ -4,29 +4,28 @@
4 4
5 5 defined( 'ABSPATH' ) || exit;
6 6
7 7 use WPCoder\Dashboard\DBManager;
8 +use WPCoder\Dashboard\FolderManager;
9 +use WPCoder\Optimization\HTMLMinifier;
8 10 use WPCoder\Publisher\Conditions;
9 -use WPCoder\Publisher\Display;
10 11 use WPCoder\Publisher\EnqueueScript;
11 12 use WPCoder\Publisher\EnqueueStyle;
12 -use WPCoder\Publisher\PageTemplate;
13 -use WPCoder\Publisher\Shortcodes;
13 +use WPCoder\Publisher\PHPIncludes;
14 14 use WPCoder\Publisher\Singleton;
15 15
16 16 class WOWP_Public {
17 17
18 18 public function __construct() {
19 - add_shortcode( WOW_Plugin::SHORTCODE, [ $this, 'shortcode' ] );
19 + add_shortcode( 'WP-Coder', [ $this, 'shortcode' ] );
20 + add_shortcode( WPCoder::SHORTCODE, [ $this, 'shortcode' ] );
21 +
22 + add_action( 'wp_footer', [ $this, 'print_footer' ], 50 );
23 +
24 + new PHPIncludes;
20 25 }
21 26
22 - public function shortcode( $atts ) {
23 - $atts = shortcode_atts(
24 - [ 'id' => "", 'title' => '', ],
25 - $atts,
26 - WOW_Plugin::SHORTCODE
27 - );
28 -
27 + public function shortcode( $atts, $shortcode_content = null ) {
29 28 if ( ! empty( $atts['id'] ) ) {
30 29 $result = DBManager::get_data_by_id( $atts['id'] );
31 30 } elseif ( ! empty( $atts['title'] ) ) {
32 31 $result = DBManager::get_data_by_title( $atts['title'] );
@@ -37,14 +36,22 @@
37 36 if ( empty( $result ) ) {
38 37 return false;
39 38 }
40 39
40 + $default_atts = [ 'id' => "", 'title' => '' ];
41 + $add_atts = $this->get_shortcode_atts( $result );
42 + $filtered_new_atts = array_diff_key( $add_atts, $default_atts );
43 + $result_atts = array_merge( $default_atts, $filtered_new_atts );
44 +
45 + $attrs = shortcode_atts( $result_atts, $atts, WPCoder::SHORTCODE );
46 +
41 47 if ( Conditions::init( $result ) === false ) {
42 48 return false;
43 49 }
44 50
45 - $html_code = $result->html_code;
46 51
52 + $wp_coder_content_out = $this->get_content( $result, $shortcode_content, $attrs );
53 +
47 54 $singleton = Singleton::getInstance();
48 55 $singleton->setValue( $result->id, $result );
49 56
50 57 EnqueueStyle::init( $result );
@@ -49,8 +56,59 @@
49 56
50 57 EnqueueStyle::init( $result );
51 58 EnqueueScript::init( $result );
52 59
53 - return do_shortcode( $html_code );
60 + return $wp_coder_content_out;
61 + }
62 +
63 + private function get_shortcode_atts( $result ): array {
64 + $param = maybe_unserialize( $result->param );
65 + if ( empty( $param['shortcode_attribute'] ) || ! is_array( $param['shortcode_attribute'] ) ) {
66 + return array();
67 + }
68 +
69 + return array_fill_keys( $param['shortcode_attribute'], '' );
70 + }
71 +
72 +
73 + public function print_footer() {
74 + $singleton = Singleton::getInstance();
75 + $shortcodes = $singleton->getValue();
76 +
77 + foreach ( $shortcodes as $id => $result ) {
78 + EnqueueStyle::inline( $result );
79 + EnqueueScript::inline( $result );
80 + }
81 + }
82 +
83 + private function get_content( $result, $shortcode_content = null, $attrs = null ) {
84 + $shortcode_content = !empty($shortcode_content) ? do_shortcode( $shortcode_content ) : '';
85 + $wp_coder_content = !empty($result->html_code) ? do_shortcode( $result->html_code ) : '';
86 +
87 + if ( ! empty( $attrs ) ) {
88 + extract( $attrs, EXTR_PREFIX_SAME, "wpcp" );
89 + }
90 +
91 + if ( ! empty( $result->php_code ) ) {
92 + $path = FolderManager::code_path( $result );
93 + include $path;
94 + }
95 +
96 + if ( preg_match_all( '/\{\{(.*?)\}\}/', $wp_coder_content, $matches ) && is_array( $matches[1] ) ) {
97 + foreach ( $matches[1] as $match ) {
98 + $wpcoder_variable = str_replace( '$', '', $match );
99 + if ( isset( $$wpcoder_variable ) ) {
100 + $wp_coder_content = str_replace( '{{' . $match . '}}', $$wpcoder_variable, $wp_coder_content );
101 + }
102 + }
103 + }
104 +
105 + $param = ! empty( $result->param ) ? maybe_unserialize( $result->param ) : [];
106 + if ( ! empty( $param['minified_html'] ) ) {
107 + return HTMLMinifier::minify( $wp_coder_content );
108 + }
109 +
110 +
111 + return $wp_coder_content;
54 112 }
55 113
56 114 }