PluginProbe
Insert PHP Code Snippet / 1.3.8
Insert PHP Code Snippet v1.3.8
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
insert-php-code-snippet / shortcode-handler.php

shortcode-handler.php in Insert PHP Code Snippet 1.3.8, at shortcode-handler.php

148 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4 global $wpdb;
5 add_shortcode('xyz-ips','xyz_ips_display_content');
6 function xyz_ips_display_content($xyz_snippet_name){
7 global $wpdb;
8 $xyz_ips_exec_in_editor = get_option('xyz_ips_exec_in_editor');
9 if ( $xyz_ips_exec_in_editor ) {
10 // Page Builder checks (Elementor, WPBakery, Divi, Beaver Builder)
11 if ( wp_doing_ajax() ) {
12 $builder_actions = ['elementor_preview', 'wpb_pb_preview', 'et_pb_preview'];
13 // Check for Elementor, WPBakery, Divi actions
14 if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $builder_actions, true ) ) {
15 // Allow shortcode execution in page builder previews
16 }
17 // Beaver Builder detection using URL parameters
18 if ( isset( $_REQUEST['fl_builder'] ) && isset( $_REQUEST['fl_builder'] ) ) {
19 // Allow execution for Beaver Builder preview
20 }
21 }
22 // Classic Editor or Gutenberg Editor check (editing posts)
23 if ( is_admin() && isset( $_GET['post'] ) && 'edit' === $_GET['action'] ) {
24 // Allow shortcode execution in Classic Editor or Gutenberg (when editing posts)
25 }
26 } elseif ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
27 return ''; // Do not execute shortcode in other admin areas or REST API requests
28 }
29 if(is_array($xyz_snippet_name)&& isset($xyz_snippet_name['snippet'])){
30 $snippet_name = $xyz_snippet_name['snippet'];
31 $query = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ips_short_code WHERE title=%s" ,$snippet_name));
32 if(!empty($query))//if(count($query)>0)
33 {
34 foreach ($query as $sippetdetails){
35 if($sippetdetails->status==1){
36 /* if(is_numeric(ini_get('output_buffering'))){
37 $tmp=ob_get_contents();
38 if(strlen($tmp)>0)
39 ob_clean();*/
40 ob_start();
41 $content_to_eval=$sippetdetails->content;
42
43 /***** to handle old codes : start *****/
44
45 if(get_option('xyz_ips_auto_insert')==1){
46 $xyz_ips_content_start='<?php';
47 $new_line="\r\n";
48 $xyz_ips_content_end='?>';
49
50 if (stripos($content_to_eval, '<?php') !== false)
51 $tag_start_position=stripos($content_to_eval,'<?php');
52 else
53 $tag_start_position="-1";
54
55 if (stripos($content_to_eval, '?>') !== false)
56 $tag_end_position=stripos($content_to_eval,'?>');
57 else
58 $tag_end_position="-1";
59
60 if(stripos($content_to_eval, '<?php') === false && stripos($content_to_eval, '?>') === false)
61 {
62 $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
63 }
64 else if(stripos($content_to_eval, '<?php') !== false)
65 {
66 if($tag_start_position>=0 && $tag_end_position>=0 && $tag_start_position>$tag_end_position)
67 {
68 $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
69 }
70 }
71 else if(stripos($content_to_eval, '<?php') === false)
72 {
73 if (stripos($content_to_eval, '?>') !== false)
74 {
75 $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
76 }
77 }
78 $content_to_eval='?>'.$content_to_eval;
79 }
80
81 /***** to handle old codes : end *****/
82 else{
83 if(substr(trim($content_to_eval), 0,5)=='<?php')
84 $content_to_eval='?>'.$content_to_eval;
85 }
86
87
88 $exception_occur=0;
89 $exception_msg="";
90
91 try {
92
93
94 eval($content_to_eval);
95 } catch (Throwable $e) { // For PHP 7 and later
96 $exception_occur = 1;
97 $exception_msg = $e->getMessage();
98 }
99 catch (Exception $e) { // For PHP 5
100 $exception_occur = 1;
101 $exception_msg = $e->getMessage();
102 }
103
104
105
106 if($exception_occur==1) {
107
108 // global $post;
109 // $post_slug = $post->post_name;
110
111 //if($post_slug!="xyz-ics-preview-page" && !is_customize_preview())
112 {
113
114 if(get_option('xyz_ips_exception_email')!="0" && get_option('xyz_ips_exception_email')!="" && get_option('xyz_ips_auto_exception')==1)
115 {
116 $email=get_option('xyz_ips_exception_email');
117 $headers= "Content-type: text/html";
118 $subject="Exception Report";
119 $message="Hi,<br>An exception occurred while running one of the snippet.The snippet name is ".$snippet_name;
120 $message.=".<br>Exception details are given below : <br>";
121 $message.=$exception_msg;
122 wp_mail($email, $subject, $message,$headers);
123 }
124 }
125 }
126
127 $xyz_em_content = ob_get_contents();
128 // ob_clean();
129 ob_end_clean();
130 return $xyz_em_content;
131 /* }
132 else{
133 eval($sippetdetails->content);
134 }*/
135 }
136 else{
137 return '';
138 }
139 break;
140 }
141 }
142 else{
143 return '';
144 }
145 }
146 }
147 add_filter('widget_text', 'do_shortcode'); // to run shortcodes in text widgets
148