| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) |
| 3 |
exit; |
| 4 |
|
| 5 |
global $wpdb; |
| 6 |
|
| 7 |
add_shortcode('xyz-ihs','xyz_ihs_display_content'); |
| 8 |
|
| 9 |
function xyz_ihs_display_content($xyz_snippet_name){ |
| 10 |
global $wpdb; |
| 11 |
$xyz_ihs_exec_in_editor = get_option('xyz_ihs_exec_in_editor'); |
| 12 |
if ( $xyz_ihs_exec_in_editor ) { |
| 13 |
// Page Builder checks (Elementor, WPBakery, Divi, Beaver Builder) |
| 14 |
if ( wp_doing_ajax() ) { |
| 15 |
$builder_actions = ['elementor_preview', 'wpb_pb_preview', 'et_pb_preview']; |
| 16 |
// Check for Elementor, WPBakery, Divi actions |
| 17 |
if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $builder_actions, true ) ) { |
| 18 |
// Allow shortcode execution in page builder previews |
| 19 |
} |
| 20 |
// Beaver Builder detection using URL parameters |
| 21 |
if ( isset( $_REQUEST['fl_builder'] ) && isset( $_REQUEST['fl_builder'] ) ) { |
| 22 |
// Allow execution for Beaver Builder preview |
| 23 |
} |
| 24 |
} |
| 25 |
// Classic Editor or Gutenberg Editor check (editing posts) |
| 26 |
if ( is_admin() && isset( $_GET['post'] ) && 'edit' === $_GET['action'] ) { |
| 27 |
// Allow shortcode execution in Classic Editor or Gutenberg (when editing posts) |
| 28 |
} |
| 29 |
} elseif ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { |
| 30 |
return ''; // Do not execute shortcode in other admin areas or REST API requests |
| 31 |
} |
| 32 |
if(is_array($xyz_snippet_name)&& isset($xyz_snippet_name['snippet'])){ |
| 33 |
|
| 34 |
$snippet_name = $xyz_snippet_name['snippet']; |
| 35 |
|
| 36 |
$query = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title=%s" ,$snippet_name)); |
| 37 |
|
| 38 |
if(!empty($query))//if(count($query)>0) |
| 39 |
{ |
| 40 |
foreach ($query as $sippetdetails){ |
| 41 |
if($sippetdetails->status==1) |
| 42 |
return do_shortcode($sippetdetails->content) ; |
| 43 |
else |
| 44 |
return ''; |
| 45 |
break; |
| 46 |
} |
| 47 |
|
| 48 |
}else{ |
| 49 |
|
| 50 |
return ''; |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
add_filter('widget_text', 'do_shortcode'); // to run shortcodes in text widgets |
| 58 |
|