| @@ -3,9 +3,89 @@ | ||
| 3 | 3 | exit; |
| 4 | 4 | |
| 5 | 5 | global $wpdb; |
| 6 | 6 | |
| 7 | +include_once 'admin/constants.php'; | |
| 7 | 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"); | |
| 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 */ | |
| 8 | 88 | |
| 9 | 89 | function xyz_ihs_display_content($xyz_snippet_name){ |
| 10 | 90 | global $wpdb; |
| 11 | 91 | $xyz_ihs_exec_in_editor = get_option('xyz_ihs_exec_in_editor'); |