| 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 |
.wp-block-group.is-layout-flex:has(.wp-block-post-author-name):has(.taxonomy-category) { |
| 135 |
display: none !important; |
| 136 |
} |
| 137 |
#wp--skip-link--target { |
| 138 |
margin-top: 0 !important; |
| 139 |
} |
| 140 |
/* Cible le bloc groupe qui est en pleine largeur et contraint, et annule le padding-top. */ |
| 141 |
.wp-block-group.alignfull.has-global-padding.is-layout-constrained { |
| 142 |
padding-top: 0 !important; |
| 143 |
} |
| 144 |
|
| 145 |
/* Elementor */ |
| 146 |
body.elementor-page .elementor-page-title, |
| 147 |
body.elementor-page .elementor-post__title, |
| 148 |
body.elementor-page .entry-title, |
| 149 |
body.elementor-page .post-title, |
| 150 |
body.elementor-page .elementor-post-info, |
| 151 |
body.elementor-page .elementor-post__meta-data { |
| 152 |
display: none !important; |
| 153 |
visibility: hidden !important; |
| 154 |
height: 0 !important; |
| 155 |
margin: 0 !important; |
| 156 |
padding: 0 !important; |
| 157 |
overflow: hidden !important; |
| 158 |
} |
| 159 |
|
| 160 |
/* GeneratePress */ |
| 161 |
body .entry-header, |
| 162 |
body .entry-title, |
| 163 |
body .entry-meta, |
| 164 |
body .posted-on, |
| 165 |
body .byline, |
| 166 |
body .cat-links, |
| 167 |
body .tags-links { |
| 168 |
display: none !important; |
| 169 |
visibility: hidden !important; |
| 170 |
height: 0 !important; |
| 171 |
margin: 0 !important; |
| 172 |
padding: 0 !important; |
| 173 |
overflow: hidden !important; |
| 174 |
} |
| 175 |
|
| 176 |
/* OceanWP */ |
| 177 |
body .page-header, |
| 178 |
body .entry-header, |
| 179 |
body .entry-title, |
| 180 |
body .entry-meta, |
| 181 |
body .meta-date, |
| 182 |
body .meta-author, |
| 183 |
body .meta-cat { |
| 184 |
display: none !important; |
| 185 |
visibility: hidden !important; |
| 186 |
height: 0 !important; |
| 187 |
margin: 0 !important; |
| 188 |
padding: 0 !important; |
| 189 |
overflow: hidden !important; |
| 190 |
} |
| 191 |
|
| 192 |
/* Neve Theme */ |
| 193 |
body .nv-page-title-wrap, |
| 194 |
body .nv-page-title, |
| 195 |
body .nv-single-post-wrap .entry-title, |
| 196 |
body .nv-meta-list, |
| 197 |
body .nv-post-navigation { |
| 198 |
display: none !important; |
| 199 |
visibility: hidden !important; |
| 200 |
height: 0 !important; |
| 201 |
margin: 0 !important; |
| 202 |
padding: 0 !important; |
| 203 |
overflow: hidden !important; |
| 204 |
} |
| 205 |
|
| 206 |
/* Kadence Theme */ |
| 207 |
body .entry-header, |
| 208 |
body .entry-title, |
| 209 |
body .entry-meta, |
| 210 |
body .post-meta { |
| 211 |
display: none !important; |
| 212 |
visibility: hidden !important; |
| 213 |
height: 0 !important; |
| 214 |
margin: 0 !important; |
| 215 |
padding: 0 !important; |
| 216 |
overflow: hidden !important; |
| 217 |
} |
| 218 |
|
| 219 |
/* Envato Theme */ |
| 220 |
body .single-title, |
| 221 |
body .article-meta { |
| 222 |
display: none !important; |
| 223 |
visibility: hidden !important; |
| 224 |
height: 0 !important; |
| 225 |
margin: 0 !important; |
| 226 |
padding: 0 !important; |
| 227 |
} |
| 228 |
|
| 229 |
/* Blocksy Theme */ |
| 230 |
body .entry-header, |
| 231 |
body .entry-title, |
| 232 |
body .entry-meta { |
| 233 |
display: none !important; |
| 234 |
visibility: hidden !important; |
| 235 |
height: 0 !important; |
| 236 |
margin: 0 !important; |
| 237 |
padding: 0 !important; |
| 238 |
overflow: hidden !important; |
| 239 |
} |
| 240 |
|
| 241 |
/* Sélecteurs génériques universels */ |
| 242 |
body.single-<?php echo esc_attr($post_type); ?> .entry-header, |
| 243 |
body.page-id-<?php echo esc_attr($post_id); ?> .entry-header, |
| 244 |
body.post-id-<?php echo esc_attr($post_id); ?> .entry-header, |
| 245 |
body.single-<?php echo esc_attr($post_type); ?> .entry-title, |
| 246 |
body.page-id-<?php echo esc_attr($post_id); ?> .entry-title, |
| 247 |
body.post-id-<?php echo esc_attr($post_id); ?> .entry-title, |
| 248 |
body.single-<?php echo esc_attr($post_type); ?> .entry-meta, |
| 249 |
body.page-id-<?php echo esc_attr($post_id); ?> .entry-meta, |
| 250 |
body.post-id-<?php echo esc_attr($post_id); ?> .entry-meta, |
| 251 |
body.single-<?php echo esc_attr($post_type); ?> .byline, |
| 252 |
body.page-id-<?php echo esc_attr($post_id); ?> .byline, |
| 253 |
body.post-id-<?php echo esc_attr($post_id); ?> .byline, |
| 254 |
body.single-<?php echo esc_attr($post_type); ?> .posted-on, |
| 255 |
body.page-id-<?php echo esc_attr($post_id); ?> .posted-on, |
| 256 |
body.post-id-<?php echo esc_attr($post_id); ?> .posted-on, |
| 257 |
body.single-<?php echo esc_attr($post_type); ?> .cat-links, |
| 258 |
body.page-id-<?php echo esc_attr($post_id); ?> .cat-links, |
| 259 |
body.post-id-<?php echo esc_attr($post_id); ?> .cat-links, |
| 260 |
body.single-<?php echo esc_attr($post_type); ?> .tags-links, |
| 261 |
body.page-id-<?php echo esc_attr($post_id); ?> .tags-links, |
| 262 |
body.post-id-<?php echo esc_attr($post_id); ?> .tags-links { |
| 263 |
display: none !important; |
| 264 |
visibility: hidden !important; |
| 265 |
height: 0 !important; |
| 266 |
margin: 0 !important; |
| 267 |
padding: 0 !important; |
| 268 |
overflow: hidden !important; |
| 269 |
} |
| 270 |
|
| 271 |
/* Ajuster les marges/paddings pour supprimer l'espace entre header et contenu */ |
| 272 |
body.single-<?php echo esc_attr($post_type); ?> .entry-content, |
| 273 |
body.page-id-<?php echo esc_attr($post_id); ?> .entry-content, |
| 274 |
body.post-id-<?php echo esc_attr($post_id); ?> .entry-content, |
| 275 |
body.single-<?php echo esc_attr($post_type); ?> article, |
| 276 |
body.page-id-<?php echo esc_attr($post_id); ?> article, |
| 277 |
body.post-id-<?php echo esc_attr($post_id); ?> article, |
| 278 |
body.single-<?php echo esc_attr($post_type); ?> .post-content, |
| 279 |
body.page-id-<?php echo esc_attr($post_id); ?> .post-content, |
| 280 |
body.post-id-<?php echo esc_attr($post_id); ?> .post-content { |
| 281 |
margin-top: 0 !important; |
| 282 |
padding-top: 0 !important; |
| 283 |
} |
| 284 |
|
| 285 |
/* Pour Astra spécifiquement */ |
| 286 |
body.ast-single-post .entry-content, |
| 287 |
body.ast-page .entry-content { |
| 288 |
margin-top: 0 !important; |
| 289 |
padding-top: 0 !important; |
| 290 |
} |
| 291 |
|
| 292 |
/* Pour Elementor */ |
| 293 |
body.elementor-page .elementor-post__content { |
| 294 |
margin-top: 0 !important; |
| 295 |
padding-top: 0 !important; |
| 296 |
} |
| 297 |
</style> |
| 298 |
<?php |
| 299 |
} |
| 300 |
|
| 301 |
/** |
| 302 |
* Ajouter le CSS pour masquer le titre dans l'admin (Gutenberg) |
| 303 |
*/ |
| 304 |
public function add_ai_created_admin_css() |
| 305 |
{ |
| 306 |
// Vérifier si on est dans l'éditeur |
| 307 |
$screen = get_current_screen(); |
| 308 |
if (!$screen || ($screen->base !== 'post' && $screen->base !== 'page')) { |
| 309 |
return; |
| 310 |
} |
| 311 |
|
| 312 |
// Obtenir l'ID du post |
| 313 |
$post_id = null; |
| 314 |
if (isset($_GET['post'])) { |
| 315 |
$post_id = intval($_GET['post']); |
| 316 |
} elseif (isset($GLOBALS['post_ID'])) { |
| 317 |
$post_id = $GLOBALS['post_ID']; |
| 318 |
} elseif (isset($_POST['post_ID'])) { |
| 319 |
$post_id = intval($_POST['post_ID']); |
| 320 |
} |
| 321 |
|
| 322 |
// Vérifier si c'est une page créée via IA |
| 323 |
if (!$post_id || !$this->is_ai_created($post_id)) { |
| 324 |
return; |
| 325 |
} |
| 326 |
|
| 327 |
?> |
| 328 |
<style id="aibui-hide-ai-title-admin" type="text/css"> |
| 329 |
/* ============================================ |
| 330 |
CSS pour masquer le titre dans l'éditeur |
| 331 |
Pages créées via IA - Admin (Gutenberg) |
| 332 |
============================================ */ |
| 333 |
|
| 334 |
/* Masquer le titre dans l'éditeur Gutenberg */ |
| 335 |
.editor-post-title, |
| 336 |
.editor-post-title__input, |
| 337 |
.edit-post-visual-editor__post-title-wrapper, |
| 338 |
.editor-post-title__block, |
| 339 |
.wp-block[data-type="core/post-title"], |
| 340 |
.block-editor-block-list__block[data-type="core/post-title"], |
| 341 |
.wp-block-post-title.editor-post-title__block { |
| 342 |
display: none !important; |
| 343 |
visibility: hidden !important; |
| 344 |
height: 0 !important; |
| 345 |
margin: 0 !important; |
| 346 |
padding: 0 !important; |
| 347 |
overflow: hidden !important; |
| 348 |
opacity: 0 !important; |
| 349 |
} |
| 350 |
|
| 351 |
/* Masquer également le wrapper du titre */ |
| 352 |
.edit-post-visual-editor__post-title-wrapper { |
| 353 |
display: none !important; |
| 354 |
visibility: hidden !important; |
| 355 |
height: 0 !important; |
| 356 |
margin: 0 !important; |
| 357 |
padding: 0 !important; |
| 358 |
overflow: hidden !important; |
| 359 |
} |
| 360 |
</style> |
| 361 |
<?php |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
new AIBUI_CSS_Handler(); |
| 366 |
|