| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) |
| 4 |
exit; // Exit if accessed directly |
| 5 |
|
| 6 |
class AIBUI_JS_Handler |
| 7 |
{ |
| 8 |
public function __construct() |
| 9 |
{ |
| 10 |
// Ajouter le JS personnalisé sur le frontend |
| 11 |
add_action('wp_footer', array($this, 'add_custom_js')); |
| 12 |
} |
| 13 |
|
| 14 |
public function add_custom_js() |
| 15 |
{ |
| 16 |
// Récupérer l'ID du post actuel |
| 17 |
$post_id = get_the_ID(); |
| 18 |
|
| 19 |
if (!$post_id) { |
| 20 |
return; |
| 21 |
} |
| 22 |
|
| 23 |
// Récupérer le JS personnalisé depuis les meta du post |
| 24 |
$js_content = get_post_meta($post_id, 'ai_builder_js_content', true); |
| 25 |
|
| 26 |
if (!empty($js_content)) { |
| 27 |
echo '<script id="ai-builder-frontend-js" type="text/javascript">' . $js_content . '</script>'; |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
new AIBUI_JS_Handler(); |
| 33 |
|