# insert-html-snippet/1.3.8/shortcode-handler.php

Insert Html Snippet, version 1.3.8. 58 lines.

- Page: https://pluginprobe.com/plugins/insert-html-snippet/1.3.8/code/shortcode-handler.php
- Raw: https://pluginprobe.com/plugins/insert-html-snippet/1.3.8/raw/shortcode-handler.php
- Modified: 2024-12-04T13:02:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/insert-html-snippet/1.3.8/code/shortcode-handler.php#L10-L20`.

```php
<?php 
if ( ! defined( 'ABSPATH' ) ) 
	exit;
	
global $wpdb;

add_shortcode('xyz-ihs','xyz_ihs_display_content');		

function xyz_ihs_display_content($xyz_snippet_name){
	global $wpdb;
	$xyz_ihs_exec_in_editor = get_option('xyz_ihs_exec_in_editor');
    if ( $xyz_ihs_exec_in_editor ) {
        // Page Builder checks (Elementor, WPBakery, Divi, Beaver Builder)
        if ( wp_doing_ajax() ) {
            $builder_actions = ['elementor_preview', 'wpb_pb_preview', 'et_pb_preview'];
            // Check for Elementor, WPBakery, Divi actions
            if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $builder_actions, true ) ) {
                // Allow shortcode execution in page builder previews
            }
        // Beaver Builder detection using URL parameters
        if ( isset( $_REQUEST['fl_builder'] ) && isset( $_REQUEST['fl_builder'] ) ) {
            // Allow execution for Beaver Builder preview
            }
        }
        // Classic Editor or Gutenberg Editor check (editing posts)
        if ( is_admin() && isset( $_GET['post'] ) && 'edit' === $_GET['action'] ) {
            // Allow shortcode execution in Classic Editor or Gutenberg (when editing posts)
        }
    } elseif ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
        return ''; // Do not execute shortcode in other admin areas or REST API requests
	}
	if(is_array($xyz_snippet_name)&& isset($xyz_snippet_name['snippet'])){
	   
		$snippet_name = $xyz_snippet_name['snippet'];
		
		$query = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title=%s" ,$snippet_name));
		
		if(!empty($query))//if(count($query)>0)
		{
			foreach ($query as $sippetdetails){
			if($sippetdetails->status==1)
				return do_shortcode($sippetdetails->content) ;
			else 
				return '';
				break;
			}
			
		}else{

			return '';		
		}
		
	}
}


add_filter('widget_text', 'do_shortcode'); // to run shortcodes in text widgets

```
