| 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 |
if (is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST )) |
| 12 |
{ |
| 13 |
return ''; // Do not execute the shortcode in the admin area |
| 14 |
} |
| 15 |
if(is_array($xyz_snippet_name)&& isset($xyz_snippet_name['snippet'])){ |
| 16 |
|
| 17 |
$snippet_name = $xyz_snippet_name['snippet']; |
| 18 |
|
| 19 |
$query = $wpdb->get_results($wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."xyz_ihs_short_code WHERE title=%s" ,$snippet_name)); |
| 20 |
|
| 21 |
if(!empty($query))//if(count($query)>0) |
| 22 |
{ |
| 23 |
foreach ($query as $sippetdetails){ |
| 24 |
if($sippetdetails->status==1) |
| 25 |
return do_shortcode($sippetdetails->content) ; |
| 26 |
else |
| 27 |
return ''; |
| 28 |
break; |
| 29 |
} |
| 30 |
|
| 31 |
}else{ |
| 32 |
|
| 33 |
return ''; |
| 34 |
} |
| 35 |
|
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
add_filter('widget_text', 'do_shortcode'); // to run shortcodes in text widgets |
| 41 |
|