PluginProbe
Insert Html Snippet / trunk
Insert Html Snippet vtrunk
1.4.6 trunk 1.0 1.0.1 1.1 1.1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3 1.3.1 1.3.2 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 All 27 releases
← All changes | shortcode-handler.php +113 -21 1.0trunk View file →
@@ -1,28 +1,126 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
4 +
2 5 global $wpdb;
3 6
4 -// $totalDetails = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE status='1'" );
5 -// if(count($totalDetails)>0){
6 -// foreach ($totalDetails as $total){
7 - add_shortcode('xyz-ihs','xyz_ihs_display_content');
8 -// }
9 -// }
7 +include_once 'admin/constants.php';
8 +add_shortcode('xyz-ihs','xyz_ihs_display_content');
9 +$table_name = $wpdb->prefix . 'xyz_ihs_short_code';
10 +$snippets = $wpdb->get_results("SELECT * FROM $table_name WHERE insertionMethod = 1 AND status = 1");
10 11
12 +
13 +foreach ($snippets as $snippet) {
14 +
15 + switch ($snippet->insertionLocation) {
16 +
17 +
18 + case XYZ_IHS_INSERTION_LOCATION['ADMIN_RUN_ON_HEADER']:
19 + if (is_admin()) {
20 + add_action('admin_head', function() use ($snippet) {
21 + echo xyz_execute_ihs_snippet($snippet);
22 + }, 10);
23 + }
24 +
25 + break;
26 + case XYZ_IHS_INSERTION_LOCATION['ADMIN_RUN_ON_FOOTER']:
27 + if (is_admin()) {
28 +
29 +
30 + add_action('admin_footer', function() use ($snippet) {
31 + echo xyz_execute_ihs_snippet($snippet);
32 + }, 10);
33 + }
34 +
35 + break;
36 +
37 +
38 +
39 + case XYZ_IHS_INSERTION_LOCATION['FRONTEND_RUN_ON_HEADER']:
40 + if (!is_admin()) {
41 + add_action('wp_head', function() use ($snippet) {
42 + echo xyz_execute_ihs_snippet($snippet);
43 + }, 10);
44 + }
45 +
46 + break;
47 +
48 + case XYZ_IHS_INSERTION_LOCATION['FRONTEND_RUN_ON_FOOTER']:
49 + if (!is_admin()) {
50 +
51 +
52 + add_action('wp_footer', function() use ($snippet) {
53 +
54 + echo xyz_execute_ihs_snippet($snippet);
55 +
56 + }, 10);
57 + }
58 +
59 + break;
60 +
61 +
62 +
63 +
64 +
65 +
66 + }
67 +}
68 +
69 +function xyz_execute_ihs_snippet($sippetdetails)
70 +{
71 +
72 +if($sippetdetails->status==1){
73 + $xyz_ihs_content=$sippetdetails->content;
74 + if (!empty($xyz_ihs_content)) {
75 + return $xyz_ihs_content;
76 + } else {
77 + return '';
78 + }
79 +
80 + }
81 + else{
82 + return '';
83 + }
84 +
85 +
86 +}
87 +/* customization ends */
88 +
11 89 function xyz_ihs_display_content($xyz_snippet_name){
12 90 global $wpdb;
13 -
14 - if(is_array($xyz_snippet_name)){
91 + $xyz_ihs_exec_in_editor = get_option('xyz_ihs_exec_in_editor');
92 + if ( $xyz_ihs_exec_in_editor ) {
93 + // Page Builder checks (Elementor, WPBakery, Divi, Beaver Builder)
94 + if ( wp_doing_ajax() ) {
95 + $builder_actions = ['elementor_preview', 'wpb_pb_preview', 'et_pb_preview'];
96 + // Check for Elementor, WPBakery, Divi actions
97 + if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $builder_actions, true ) ) {
98 + // Allow shortcode execution in page builder previews
99 + }
100 + // Beaver Builder detection using URL parameters
101 + if ( isset( $_REQUEST['fl_builder'] ) && isset( $_REQUEST['fl_builder'] ) ) {
102 + // Allow execution for Beaver Builder preview
103 + }
104 + }
105 + // Classic Editor or Gutenberg Editor check (editing posts)
106 + if ( is_admin() && isset( $_GET['post'] ) && 'edit' === $_GET['action'] ) {
107 + // Allow shortcode execution in Classic Editor or Gutenberg (when editing posts)
108 + }
109 + } elseif ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
110 + return ''; // Do not execute shortcode in other admin areas or REST API requests
111 + }
112 + if(is_array($xyz_snippet_name)&& isset($xyz_snippet_name['snippet'])){
113 +
15 114 $snippet_name = $xyz_snippet_name['snippet'];
16 115
17 - $query = $wpdb->get_results( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title='$snippet_name'" );
116 + $query = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title=%s" ,$snippet_name));
18 117
19 - if(count($query)>0){
20 -
118 + if(!empty($query))//if(count($query)>0)
119 + {
21 120 foreach ($query as $sippetdetails){
22 -// return stripslashes($sippetdetails->content);
23 121 if($sippetdetails->status==1)
24 - return $sippetdetails->content;
122 + return do_shortcode($sippetdetails->content) ;
25 123 else
26 124 return '';
27 125 break;
28 126 }
@@ -28,15 +126,9 @@
28 126 }
29 127
30 128 }else{
31 129
32 - return "<div style='padding:20px; font-size:16px; color:#FA5A6A; width:93%;text-align:center;background:lightyellow;border:1px solid #3FAFE3; margin:20px 0 20px 0'>
33 -
34 - Please use a valid short code to call snippet.
35 -
36 -
37 - </div>";
38 -
130 + return '';
39 131 }
40 132
41 133 }
42 134 }
@@ -41,5 +133,5 @@
41 133 }
42 134 }
43 135
44 136
45 -add_filter('widget_text', 'do_shortcode');
137 +add_filter('widget_text', 'do_shortcode'); // to run shortcodes in text widgets