PluginProbe
AI Builder – Generate pages, blocks, images & translate with AI / 2.1.0
AI Builder – Generate pages, blocks, images & translate with AI v2.1.0
2.7.10 2.7.9 2.7.8 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.10 All 122 releases
ai-builder / includes / class-css-handler.php

class-css-handler.php in AI Builder – Generate pages, blocks, images & translate with AI 2.1.0, at includes/class-css-handler.php

346 lines 12.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH'))
4 exit; // Exit if accessed directly
5
6 class AIBUI_CSS_Handler
7 {
8 public function __construct()
9 {
10 // Ajouter le CSS personnalisé sur le frontend
11 add_action('wp_head', array($this, 'add_custom_css'));
12 // Ajouter le CSS pour masquer titre/métadonnées sur le frontend
13 add_action('wp_head', array($this, 'add_ai_created_hide_title_css'), 999);
14 // Ajouter le CSS pour masquer le titre dans l'admin
15 add_action('admin_head', array($this, 'add_ai_created_admin_css'));
16 }
17
18 public function add_custom_css()
19 {
20 // Récupérer l'ID du post actuel
21 $post_id = get_the_ID();
22
23 if (!$post_id) {
24 return;
25 }
26
27 // Récupérer le CSS personnalisé depuis les meta du post
28 $css_content = get_post_meta($post_id, 'ai_builder_css_content', true);
29
30 if (!empty($css_content)) {
31 echo '<style id="ai-builder-frontend-css" type="text/css">' . $css_content . '</style>';
32 }
33 }
34
35 /**
36 * Vérifier si une page a été créée via IA
37 */
38 private function is_ai_created($post_id = null)
39 {
40 if (!$post_id) {
41 $post_id = get_the_ID();
42 }
43
44 if (!$post_id) {
45 return false;
46 }
47
48 return get_post_meta($post_id, '_aibui_created_by_ai', true) === '1';
49 }
50
51 /**
52 * Ajouter le CSS pour masquer titre/métadonnées sur le frontend
53 */
54 public function add_ai_created_hide_title_css()
55 {
56 if (!is_singular()) {
57 return;
58 }
59
60 $post_id = get_the_ID();
61 if (!$this->is_ai_created($post_id)) {
62 return;
63 }
64
65 $post_type = get_post_type($post_id);
66 $type_class = ($post_type === 'page') ? 'page' : 'post';
67
68 ?>
69 <style id="aibui-hide-ai-title-metadata" type="text/css">
70 /* ============================================
71 CSS pour masquer titre et métadonnées
72 Pages créées via IA - Frontend
73 Compatible avec les thèmes populaires
74 ============================================ */
75
76 /* Twenty Twenty Five */
77 body.single-<?php echo esc_attr($post_type); ?> .wp-site-blocks .wp-block-post-title,
78 body.page-id-<?php echo esc_attr($post_id); ?> .wp-site-blocks .wp-block-post-title,
79 body.post-id-<?php echo esc_attr($post_id); ?> .wp-site-blocks .wp-block-post-title {
80 display: none !important;
81 visibility: hidden !important;
82 height: 0 !important;
83 margin: 0 !important;
84 padding: 0 !important;
85 overflow: hidden !important;
86 }
87
88 /* Twenty Twenty Four */
89 body .wp-block-post-title,
90 body .entry-title,
91 body .post-title,
92 body .page-title {
93 display: none !important;
94 visibility: hidden !important;
95 height: 0 !important;
96 margin: 0 !important;
97 padding: 0 !important;
98 overflow: hidden !important;
99 }
100
101 /* Twenty Twenty Three, Twenty Twenty Two */
102 body .wp-block-post-title,
103 body .entry-header .entry-title,
104 body .entry-header h1 {
105 display: none !important;
106 visibility: hidden !important;
107 height: 0 !important;
108 margin: 0 !important;
109 padding: 0 !important;
110 overflow: hidden !important;
111 }
112
113 /* Astra Theme */
114 body.ast-single-post .ast-single-post-order .entry-header,
115 body.ast-single-post .entry-title,
116 body.ast-page-title .entry-title,
117 body .ast-page-title,
118 body .ast-single-post .post-navigation,
119 body .ast-single-post .ast-posted-on,
120 body .ast-single-post .posted-on,
121 body .ast-single-post .cat-links,
122 body .ast-single-post .tags-links,
123 body .ast-single-post .byline,
124 body .ast-single-post .ast-posted-on,
125 body.page-id-<?php echo esc_attr($post_id); ?> .ast-page-title,
126 body.post-id-<?php echo esc_attr($post_id); ?> .entry-title {
127 display: none !important;
128 visibility: hidden !important;
129 height: 0 !important;
130 margin: 0 !important;
131 padding: 0 !important;
132 overflow: hidden !important;
133 }
134
135 /* Elementor */
136 body.elementor-page .elementor-page-title,
137 body.elementor-page .elementor-post__title,
138 body.elementor-page .entry-title,
139 body.elementor-page .post-title,
140 body.elementor-page .elementor-post-info,
141 body.elementor-page .elementor-post__meta-data {
142 display: none !important;
143 visibility: hidden !important;
144 height: 0 !important;
145 margin: 0 !important;
146 padding: 0 !important;
147 overflow: hidden !important;
148 }
149
150 /* GeneratePress */
151 body .entry-header,
152 body .entry-title,
153 body .entry-meta,
154 body .posted-on,
155 body .byline,
156 body .cat-links,
157 body .tags-links {
158 display: none !important;
159 visibility: hidden !important;
160 height: 0 !important;
161 margin: 0 !important;
162 padding: 0 !important;
163 overflow: hidden !important;
164 }
165
166 /* OceanWP */
167 body .page-header,
168 body .entry-header,
169 body .entry-title,
170 body .entry-meta,
171 body .meta-date,
172 body .meta-author,
173 body .meta-cat {
174 display: none !important;
175 visibility: hidden !important;
176 height: 0 !important;
177 margin: 0 !important;
178 padding: 0 !important;
179 overflow: hidden !important;
180 }
181
182 /* Neve Theme */
183 body .nv-page-title-wrap,
184 body .nv-page-title,
185 body .nv-single-post-wrap .entry-title,
186 body .nv-meta-list,
187 body .nv-post-navigation {
188 display: none !important;
189 visibility: hidden !important;
190 height: 0 !important;
191 margin: 0 !important;
192 padding: 0 !important;
193 overflow: hidden !important;
194 }
195
196 /* Kadence Theme */
197 body .entry-header,
198 body .entry-title,
199 body .entry-meta,
200 body .post-meta {
201 display: none !important;
202 visibility: hidden !important;
203 height: 0 !important;
204 margin: 0 !important;
205 padding: 0 !important;
206 overflow: hidden !important;
207 }
208
209 /* Blocksy Theme */
210 body .entry-header,
211 body .entry-title,
212 body .entry-meta {
213 display: none !important;
214 visibility: hidden !important;
215 height: 0 !important;
216 margin: 0 !important;
217 padding: 0 !important;
218 overflow: hidden !important;
219 }
220
221 /* Sélecteurs génériques universels */
222 body.single-<?php echo esc_attr($post_type); ?> .entry-header,
223 body.page-id-<?php echo esc_attr($post_id); ?> .entry-header,
224 body.post-id-<?php echo esc_attr($post_id); ?> .entry-header,
225 body.single-<?php echo esc_attr($post_type); ?> .entry-title,
226 body.page-id-<?php echo esc_attr($post_id); ?> .entry-title,
227 body.post-id-<?php echo esc_attr($post_id); ?> .entry-title,
228 body.single-<?php echo esc_attr($post_type); ?> .entry-meta,
229 body.page-id-<?php echo esc_attr($post_id); ?> .entry-meta,
230 body.post-id-<?php echo esc_attr($post_id); ?> .entry-meta,
231 body.single-<?php echo esc_attr($post_type); ?> .byline,
232 body.page-id-<?php echo esc_attr($post_id); ?> .byline,
233 body.post-id-<?php echo esc_attr($post_id); ?> .byline,
234 body.single-<?php echo esc_attr($post_type); ?> .posted-on,
235 body.page-id-<?php echo esc_attr($post_id); ?> .posted-on,
236 body.post-id-<?php echo esc_attr($post_id); ?> .posted-on,
237 body.single-<?php echo esc_attr($post_type); ?> .cat-links,
238 body.page-id-<?php echo esc_attr($post_id); ?> .cat-links,
239 body.post-id-<?php echo esc_attr($post_id); ?> .cat-links,
240 body.single-<?php echo esc_attr($post_type); ?> .tags-links,
241 body.page-id-<?php echo esc_attr($post_id); ?> .tags-links,
242 body.post-id-<?php echo esc_attr($post_id); ?> .tags-links {
243 display: none !important;
244 visibility: hidden !important;
245 height: 0 !important;
246 margin: 0 !important;
247 padding: 0 !important;
248 overflow: hidden !important;
249 }
250
251 /* Ajuster les marges/paddings pour supprimer l'espace entre header et contenu */
252 body.single-<?php echo esc_attr($post_type); ?> .entry-content,
253 body.page-id-<?php echo esc_attr($post_id); ?> .entry-content,
254 body.post-id-<?php echo esc_attr($post_id); ?> .entry-content,
255 body.single-<?php echo esc_attr($post_type); ?> article,
256 body.page-id-<?php echo esc_attr($post_id); ?> article,
257 body.post-id-<?php echo esc_attr($post_id); ?> article,
258 body.single-<?php echo esc_attr($post_type); ?> .post-content,
259 body.page-id-<?php echo esc_attr($post_id); ?> .post-content,
260 body.post-id-<?php echo esc_attr($post_id); ?> .post-content {
261 margin-top: 0 !important;
262 padding-top: 0 !important;
263 }
264
265 /* Pour Astra spécifiquement */
266 body.ast-single-post .entry-content,
267 body.ast-page .entry-content {
268 margin-top: 0 !important;
269 padding-top: 0 !important;
270 }
271
272 /* Pour Elementor */
273 body.elementor-page .elementor-post__content {
274 margin-top: 0 !important;
275 padding-top: 0 !important;
276 }
277 </style>
278 <?php
279 }
280
281 /**
282 * Ajouter le CSS pour masquer le titre dans l'admin (Gutenberg)
283 */
284 public function add_ai_created_admin_css()
285 {
286 // Vérifier si on est dans l'éditeur
287 $screen = get_current_screen();
288 if (!$screen || ($screen->base !== 'post' && $screen->base !== 'page')) {
289 return;
290 }
291
292 // Obtenir l'ID du post
293 $post_id = null;
294 if (isset($_GET['post'])) {
295 $post_id = intval($_GET['post']);
296 } elseif (isset($GLOBALS['post_ID'])) {
297 $post_id = $GLOBALS['post_ID'];
298 } elseif (isset($_POST['post_ID'])) {
299 $post_id = intval($_POST['post_ID']);
300 }
301
302 // Vérifier si c'est une page créée via IA
303 if (!$post_id || !$this->is_ai_created($post_id)) {
304 return;
305 }
306
307 ?>
308 <style id="aibui-hide-ai-title-admin" type="text/css">
309 /* ============================================
310 CSS pour masquer le titre dans l'éditeur
311 Pages créées via IA - Admin (Gutenberg)
312 ============================================ */
313
314 /* Masquer le titre dans l'éditeur Gutenberg */
315 .editor-post-title,
316 .editor-post-title__input,
317 .edit-post-visual-editor__post-title-wrapper,
318 .editor-post-title__block,
319 .wp-block[data-type="core/post-title"],
320 .block-editor-block-list__block[data-type="core/post-title"],
321 .wp-block-post-title.editor-post-title__block {
322 display: none !important;
323 visibility: hidden !important;
324 height: 0 !important;
325 margin: 0 !important;
326 padding: 0 !important;
327 overflow: hidden !important;
328 opacity: 0 !important;
329 }
330
331 /* Masquer également le wrapper du titre */
332 .edit-post-visual-editor__post-title-wrapper {
333 display: none !important;
334 visibility: hidden !important;
335 height: 0 !important;
336 margin: 0 !important;
337 padding: 0 !important;
338 overflow: hidden !important;
339 }
340 </style>
341 <?php
342 }
343 }
344
345 new AIBUI_CSS_Handler();
346