# ai-builder/2.0.9/includes/class-css-handler.php

AI Builder – Generate pages, blocks, images &amp; translate with AI, version 2.0.9. 346 lines.

- Page: https://pluginprobe.com/plugins/ai-builder/2.0.9/code/includes/class-css-handler.php
- Raw: https://pluginprobe.com/plugins/ai-builder/2.0.9/raw/includes/class-css-handler.php
- Modified: 2025-11-25T11:36:12+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/ai-builder/2.0.9/code/includes/class-css-handler.php#L10-L20`.

```php
<?php

if (!defined('ABSPATH'))
    exit; // Exit if accessed directly

class AIBUI_CSS_Handler
{
    public function __construct()
    {
        // Ajouter le CSS personnalisé sur le frontend
        add_action('wp_head', array($this, 'add_custom_css'));
        // Ajouter le CSS pour masquer titre/métadonnées sur le frontend
        add_action('wp_head', array($this, 'add_ai_created_hide_title_css'), 999);
        // Ajouter le CSS pour masquer le titre dans l'admin
        add_action('admin_head', array($this, 'add_ai_created_admin_css'));
    }

    public function add_custom_css()
    {
        // Récupérer l'ID du post actuel
        $post_id = get_the_ID();

        if (!$post_id) {
            return;
        }

        // Récupérer le CSS personnalisé depuis les meta du post
        $css_content = get_post_meta($post_id, 'ai_builder_css_content', true);

        if (!empty($css_content)) {
            echo '<style id="ai-builder-frontend-css" type="text/css">' . $css_content . '</style>';
        }
    }

    /**
     * Vérifier si une page a été créée via IA
     */
    private function is_ai_created($post_id = null)
    {
        if (!$post_id) {
            $post_id = get_the_ID();
        }
        
        if (!$post_id) {
            return false;
        }
        
        return get_post_meta($post_id, '_aibui_created_by_ai', true) === '1';
    }

    /**
     * Ajouter le CSS pour masquer titre/métadonnées sur le frontend
     */
    public function add_ai_created_hide_title_css()
    {
        if (!is_singular()) {
            return;
        }

        $post_id = get_the_ID();
        if (!$this->is_ai_created($post_id)) {
            return;
        }

        $post_type = get_post_type($post_id);
        $type_class = ($post_type === 'page') ? 'page' : 'post';
        
        ?>
        <style id="aibui-hide-ai-title-metadata" type="text/css">
            /* ============================================
               CSS pour masquer titre et métadonnées
               Pages créées via IA - Frontend
               Compatible avec les thèmes populaires
               ============================================ */
            
            /* Twenty Twenty Five */
            body.single-<?php echo esc_attr($post_type); ?> .wp-site-blocks .wp-block-post-title,
            body.page-id-<?php echo esc_attr($post_id); ?> .wp-site-blocks .wp-block-post-title,
            body.post-id-<?php echo esc_attr($post_id); ?> .wp-site-blocks .wp-block-post-title {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Twenty Twenty Four */
            body .wp-block-post-title,
            body .entry-title,
            body .post-title,
            body .page-title {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Twenty Twenty Three, Twenty Twenty Two */
            body .wp-block-post-title,
            body .entry-header .entry-title,
            body .entry-header h1 {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Astra Theme */
            body.ast-single-post .ast-single-post-order .entry-header,
            body.ast-single-post .entry-title,
            body.ast-page-title .entry-title,
            body .ast-page-title,
            body .ast-single-post .post-navigation,
            body .ast-single-post .ast-posted-on,
            body .ast-single-post .posted-on,
            body .ast-single-post .cat-links,
            body .ast-single-post .tags-links,
            body .ast-single-post .byline,
            body .ast-single-post .ast-posted-on,
            body.page-id-<?php echo esc_attr($post_id); ?> .ast-page-title,
            body.post-id-<?php echo esc_attr($post_id); ?> .entry-title {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Elementor */
            body.elementor-page .elementor-page-title,
            body.elementor-page .elementor-post__title,
            body.elementor-page .entry-title,
            body.elementor-page .post-title,
            body.elementor-page .elementor-post-info,
            body.elementor-page .elementor-post__meta-data {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* GeneratePress */
            body .entry-header,
            body .entry-title,
            body .entry-meta,
            body .posted-on,
            body .byline,
            body .cat-links,
            body .tags-links {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* OceanWP */
            body .page-header,
            body .entry-header,
            body .entry-title,
            body .entry-meta,
            body .meta-date,
            body .meta-author,
            body .meta-cat {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Neve Theme */
            body .nv-page-title-wrap,
            body .nv-page-title,
            body .nv-single-post-wrap .entry-title,
            body .nv-meta-list,
            body .nv-post-navigation {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Kadence Theme */
            body .entry-header,
            body .entry-title,
            body .entry-meta,
            body .post-meta {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Blocksy Theme */
            body .entry-header,
            body .entry-title,
            body .entry-meta {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Sélecteurs génériques universels */
            body.single-<?php echo esc_attr($post_type); ?> .entry-header,
            body.page-id-<?php echo esc_attr($post_id); ?> .entry-header,
            body.post-id-<?php echo esc_attr($post_id); ?> .entry-header,
            body.single-<?php echo esc_attr($post_type); ?> .entry-title,
            body.page-id-<?php echo esc_attr($post_id); ?> .entry-title,
            body.post-id-<?php echo esc_attr($post_id); ?> .entry-title,
            body.single-<?php echo esc_attr($post_type); ?> .entry-meta,
            body.page-id-<?php echo esc_attr($post_id); ?> .entry-meta,
            body.post-id-<?php echo esc_attr($post_id); ?> .entry-meta,
            body.single-<?php echo esc_attr($post_type); ?> .byline,
            body.page-id-<?php echo esc_attr($post_id); ?> .byline,
            body.post-id-<?php echo esc_attr($post_id); ?> .byline,
            body.single-<?php echo esc_attr($post_type); ?> .posted-on,
            body.page-id-<?php echo esc_attr($post_id); ?> .posted-on,
            body.post-id-<?php echo esc_attr($post_id); ?> .posted-on,
            body.single-<?php echo esc_attr($post_type); ?> .cat-links,
            body.page-id-<?php echo esc_attr($post_id); ?> .cat-links,
            body.post-id-<?php echo esc_attr($post_id); ?> .cat-links,
            body.single-<?php echo esc_attr($post_type); ?> .tags-links,
            body.page-id-<?php echo esc_attr($post_id); ?> .tags-links,
            body.post-id-<?php echo esc_attr($post_id); ?> .tags-links {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }

            /* Ajuster les marges/paddings pour supprimer l'espace entre header et contenu */
            body.single-<?php echo esc_attr($post_type); ?> .entry-content,
            body.page-id-<?php echo esc_attr($post_id); ?> .entry-content,
            body.post-id-<?php echo esc_attr($post_id); ?> .entry-content,
            body.single-<?php echo esc_attr($post_type); ?> article,
            body.page-id-<?php echo esc_attr($post_id); ?> article,
            body.post-id-<?php echo esc_attr($post_id); ?> article,
            body.single-<?php echo esc_attr($post_type); ?> .post-content,
            body.page-id-<?php echo esc_attr($post_id); ?> .post-content,
            body.post-id-<?php echo esc_attr($post_id); ?> .post-content {
                margin-top: 0 !important;
                padding-top: 0 !important;
            }

            /* Pour Astra spécifiquement */
            body.ast-single-post .entry-content,
            body.ast-page .entry-content {
                margin-top: 0 !important;
                padding-top: 0 !important;
            }

            /* Pour Elementor */
            body.elementor-page .elementor-post__content {
                margin-top: 0 !important;
                padding-top: 0 !important;
            }
        </style>
        <?php
    }

    /**
     * Ajouter le CSS pour masquer le titre dans l'admin (Gutenberg)
     */
    public function add_ai_created_admin_css()
    {
        // Vérifier si on est dans l'éditeur
        $screen = get_current_screen();
        if (!$screen || ($screen->base !== 'post' && $screen->base !== 'page')) {
            return;
        }

        // Obtenir l'ID du post
        $post_id = null;
        if (isset($_GET['post'])) {
            $post_id = intval($_GET['post']);
        } elseif (isset($GLOBALS['post_ID'])) {
            $post_id = $GLOBALS['post_ID'];
        } elseif (isset($_POST['post_ID'])) {
            $post_id = intval($_POST['post_ID']);
        }

        // Vérifier si c'est une page créée via IA
        if (!$post_id || !$this->is_ai_created($post_id)) {
            return;
        }

        ?>
        <style id="aibui-hide-ai-title-admin" type="text/css">
            /* ============================================
               CSS pour masquer le titre dans l'éditeur
               Pages créées via IA - Admin (Gutenberg)
               ============================================ */
            
            /* Masquer le titre dans l'éditeur Gutenberg */
            .editor-post-title,
            .editor-post-title__input,
            .edit-post-visual-editor__post-title-wrapper,
            .editor-post-title__block,
            .wp-block[data-type="core/post-title"],
            .block-editor-block-list__block[data-type="core/post-title"],
            .wp-block-post-title.editor-post-title__block {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
                opacity: 0 !important;
            }

            /* Masquer également le wrapper du titre */
            .edit-post-visual-editor__post-title-wrapper {
                display: none !important;
                visibility: hidden !important;
                height: 0 !important;
                margin: 0 !important;
                padding: 0 !important;
                overflow: hidden !important;
            }
        </style>
        <?php
    }
}

new AIBUI_CSS_Handler();

```
