Repository navigation
Expand file tree
/
Copy pathfunctions.php
More file actions
369 lines (320 loc) · 12.7 KB
/
Copy pathfunctions.php
File metadata and controls
369 lines (320 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/**
* Fichier principal du thème
*
* Ce fichier charge tous les composants modulaires du thème
* pour une meilleure organisation et maintenabilité.
*
* @package AbyssEnergy
*/
// Empêcher l'accès direct au fichier
if (!defined('ABSPATH')) {
exit;
}
// Définir les constantes du thème
define('ABYSSENERGY_VERSION', '1.0.0');
define('ABYSSENERGY_DIR', get_template_directory());
define('ABYSSENERGY_URI', get_template_directory_uri());
/**
* Fonction pour charger les fichiers de modules du thème
*/
function abyssenergy_load_theme_modules()
{
$modules = [
'acf-safe-helpers.php', // Helpers sécurisés pour ACF
'inc/setup.php', // Configuration principale du thème
'inc/utils.php', // Fonctions utilitaires
'inc/enqueue.php', // Enregistrement des scripts et styles
'inc/admin.php', // Personnalisation de l'interface d'administration
'inc/blocks.php', // Blocs Gutenberg personnalisés
'inc/acf.php', // Intégration avec Advanced Custom Fields
'inc/jobs.php', // Fonctionnalités liées aux offres d'emploi
'inc/widgets.php', // Widgets personnalisés
'inc/shortcodes.php', // Shortcodes personnalisés
'inc/scss.php', // Compilation SCSS (si présent)
'inc/customizer.php', // Personnalisations du Customizer WordPress
'blocks/map/map-init.php', // Initialisation de la carte SVG
'blocks/map/global-map-init.php', // Initialisation du bloc carte globale ACF
'blocks/testimonials-slider/testimonials-slider-init.php', // Initialisation du slider de témoignages
'blocks/jobs-listing/jobs-listing-init.php', // Initialisation du bloc des offres d'emploi
'blocks/clients/clients-init.php', // Initialisation du bloc des clients
'blocks/google-reviews/google-reviews-init.php', // Initialisation du bloc d'avis Google
'blocks/project-showcase/project-showcase-init.php', // Initialisation du bloc des projets showcase
'blocks/features/features-init.php', // Initialisation du bloc des fonctionnalités
'blocks/metrics/metrics-init.php', // Initialisation du bloc des métriques
'blocks/fixed-jobs/fixed-jobs-init.php', // Initialisation du bloc des postes fixes
'blocks/card/card-init.php', // Initialisation du bloc carte simple
'blocks/timeline/timeline-init.php', // Initialisation du bloc timeline
'blocks/tabs/tabs-init.php', // Initialisation du bloc tabs
'blocks/sectors/sectors-init.php', // Initialisation du bloc sectors
'blocks/jobs-search/jobs-search-init.php', // Initialisation du bloc recherche d'emplois
'blocks/custom-buttons/custom-buttons-init.php', // Initialisation du bloc boutons personnalisés
'inc/dynamic-job-filters.php', // Filtres dynamiques pour les jobs
'inc/gravity-forms-optgroups.php', // Support des optgroups pour Gravity Forms
];
foreach ($modules as $module) {
if (file_exists(get_template_directory() . '/' . $module)) {
require_once get_template_directory() . '/' . $module;
}
}
}
// Charger tous les modules du thème
abyssenergy_load_theme_modules();
// Legacy code - sera migré progressivement vers l'architecture modulaire
//images
add_theme_support('post-thumbnails');
set_post_thumbnail_size(385, 288, true); //featured image - the true sets it to this size exactly, omitting this will scale longest side. Call by the_post_thumbnail();
//medium add_image_size( 'two-col-standard', 534, 313, true ); //repeat this for other thumbs. Call by the_post_thumbnail('blogfeatured');
add_image_size('barbers', 288, 360, true);
add_image_size('third-width', 377, 323, true);
add_image_size('page-header', 1440, 430, true);
// add menu support and fallback menu if menu doesn't exist
add_action('init', 'register_my_menus');
function register_my_menus()
{
register_nav_menus(
array(
'main-menu' => __('Main menu'),
'footer-menu1' => __('Footer menu col 1'),
'footer-menu2' => __('Footer menu col 2'),
'footer-menu3' => __('Footer menu col 3'),
'footer-menu4' => __('Footer menu col 4'),
'footer-menu5' => __('Footer menu col 5'),
'footer-menu6' => __('Footer menu col 6'),
)
);
}
//acf options page
if (function_exists('acf_add_options_page')) {
acf_add_options_page(array(
'page_title' => 'General Options',
'menu_title' => 'General Options',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}
// Filtre Gravity Forms pour désactiver les styles par défaut
add_filter('gform_disable_css', '__return_true');
/**
* Vider les règles de réécriture lors de l'initialisation du thème
*/
function abyssenergy_flush_rewrite_rules()
{
$flushed = get_option('abyssenergy_rewrite_rules_flushed');
// Si les règles n'ont pas encore été vidées, le faire maintenant
if (!$flushed) {
flush_rewrite_rules();
update_option('abyssenergy_rewrite_rules_flushed', true);
}
}
add_action('init', 'abyssenergy_flush_rewrite_rules', 20);
/**
* Ajouter automatiquement loading="lazy" aux images dans wp_get_attachment_image
*/
function abyssenergy_add_lazy_loading_to_images($attr, $attachment, $size)
{
// Ne pas ajouter loading="lazy" si déjà présent ou si c'est le logo dans le header
if (isset($attr['loading']) || (isset($attr['class']) && strpos($attr['class'], 'header__logo-image') !== false)) {
return $attr;
}
// Ajouter loading="lazy" par défaut
$attr['loading'] = 'lazy';
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'abyssenergy_add_lazy_loading_to_images', 10, 3);
/**
* Ajouter loading="lazy" aux images dans le contenu des posts
*/
function abyssenergy_add_lazy_loading_to_content_images($content)
{
// Utiliser une regex pour ajouter loading="lazy" aux images qui ne l'ont pas déjà
$content = preg_replace_callback(
'/<img([^>]*)>/i',
function ($matches) {
$img_tag = $matches[0];
// Si loading= est déjà présent, ne pas modifier
if (strpos($img_tag, 'loading=') !== false) {
return $img_tag;
}
// Si c'est le logo du header, ne pas ajouter loading="lazy"
if (strpos($img_tag, 'header__logo-image') !== false) {
return $img_tag;
}
// Ajouter loading="lazy" avant la fermeture du tag
return str_replace('>', ' loading="lazy">', $img_tag);
},
$content
);
return $content;
}
add_filter('the_content', 'abyssenergy_add_lazy_loading_to_content_images');
add_filter('widget_text_content', 'abyssenergy_add_lazy_loading_to_content_images');
/**
* Hook pour transmettre le post ID au plugin squarechilli-jobboard
* lors de la soumission de formulaires Gravity Forms
*/
function abyssenergy_set_post_context_for_gravity_forms()
{
// Vérifier si nous sommes dans une requête AJAX de Gravity Forms
if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] === 'gf_submit') {
// Récupérer le post_id depuis les données du formulaire
$post_id = null;
// Essayer différentes sources pour le post ID
if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
$post_id = intval($_POST['post_id']);
} elseif (isset($_POST['input_999']) && !empty($_POST['input_999'])) {
$post_id = intval($_POST['input_999']);
} elseif (isset($_POST['gform_fields']) && !empty($_POST['gform_fields'])) {
// Parser les champs pour trouver le post_id
$fields = json_decode(stripslashes($_POST['gform_fields']), true);
if (is_array($fields)) {
foreach ($fields as $field) {
if (isset($field['name']) && $field['name'] === 'post_id' && !empty($field['value'])) {
$post_id = intval($field['value']);
break;
}
}
}
}
if ($post_id && $post_id > 0) {
global $post;
$post = get_post($post_id);
// Définir la query globale pour que get_the_ID() fonctionne
if ($post) {
setup_postdata($post);
$GLOBALS['wp_query']->post = $post;
$GLOBALS['wp_query']->queried_object = $post;
$GLOBALS['wp_query']->queried_object_id = $post_id;
$GLOBALS['wp_query']->is_single = true;
$GLOBALS['wp_query']->is_singular = true;
// Ajouter le post ID aux superglobales pour être sûr
$_POST['current_post_id'] = $post_id;
$_GET['p'] = $post_id;
}
}
}
}
add_action('wp_ajax_gf_submit', 'abyssenergy_set_post_context_for_gravity_forms', 1);
add_action('wp_ajax_nopriv_gf_submit', 'abyssenergy_set_post_context_for_gravity_forms', 1);
/**
* Hook pour s'assurer que le post ID est disponible durant tout le processus
*/
function abyssenergy_set_post_context_early()
{
if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] === 'gf_submit') {
abyssenergy_set_post_context_for_gravity_forms();
}
}
add_action('init', 'abyssenergy_set_post_context_early', 1);
/**
* Ajouter le post ID comme variable dynamique dans Gravity Forms
*/
function abyssenergy_populate_post_id_field($value, $field, $name)
{
if ($name == 'post_id') {
global $post;
if ($post && $post->post_type === 'job') {
return $post->ID;
}
// Fallback: essayer de récupérer depuis get_the_ID()
$current_post_id = get_the_ID();
if ($current_post_id) {
return $current_post_id;
}
}
return $value;
}
add_filter('gform_field_value_post_id', 'abyssenergy_populate_post_id_field', 10, 3);
/**
* Hook Gravity Forms avant traitement pour définir le contexte post
*/
function abyssenergy_gform_pre_submission_handler($form, $entry)
{
if ($form['id'] == 1) { // Formulaire de candidature
// Debug: enregistrer les données reçues
error_log('GForm Pre-submission - POST data: ' . print_r($_POST, true));
// Récupérer le post ID depuis les données du formulaire
$post_id = null;
if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
$post_id = intval($_POST['post_id']);
} elseif (isset($_POST['input_999']) && !empty($_POST['input_999'])) {
$post_id = intval($_POST['input_999']);
}
if ($post_id && $post_id > 0) {
error_log('Setting up WordPress context for post ID: ' . $post_id);
global $post;
$post = get_post($post_id);
if ($post) {
setup_postdata($post);
$GLOBALS['wp_query']->post = $post;
$GLOBALS['wp_query']->queried_object = $post;
$GLOBALS['wp_query']->queried_object_id = $post_id;
$GLOBALS['wp_query']->is_single = true;
$GLOBALS['wp_query']->is_singular = true;
// Ajouter aux superglobales
$_GET['p'] = $post_id;
$_REQUEST['p'] = $post_id;
// Debug: vérifier le job_id du post
$job_id = get_field('job_id', $post_id);
error_log('WordPress context set successfully for post ID: ' . $post_id);
error_log('get_the_ID() now returns: ' . get_the_ID());
error_log('get_queried_object_id() now returns: ' . get_queried_object_id());
error_log('ACF job_id field value: ' . $job_id);
// Debug complet du JobOrder
abyssenergy_debug_job_order_issue($post_id, $job_id);
}
} else {
error_log('No post ID found in form submission data');
}
}
}
add_action('gform_pre_submission_1', 'abyssenergy_gform_pre_submission_handler', 5, 2);
/**
* Debug temporaire pour diagnostiquer le problème JobOrder
*/
function abyssenergy_debug_job_order_issue($post_id, $job_id)
{
if (!$post_id || !$job_id) return;
error_log("=== DEBUG JOB ORDER ===");
error_log("Post ID: " . $post_id);
error_log("Job ID (bullhorn_id): " . $job_id);
if (class_exists('\SquareChilli\Bullhorn\models\JobOrder')) {
// Chercher le job order exact
$jobOrder = \SquareChilli\Bullhorn\models\JobOrder::find()->where(['bullhorn_id' => $job_id])->one();
if ($jobOrder) {
error_log("JobOrder trouvé - ID: " . $jobOrder->id . ", Status: " . $jobOrder->status);
error_log("JobOrder date_updated: " . $jobOrder->date_updated);
// Vérifier les propriétés importantes
$reflection = new \ReflectionClass($jobOrder);
$properties = $reflection->getProperties();
foreach ($properties as $property) {
if ($property->isPublic()) {
$prop_name = $property->getName();
$prop_value = $jobOrder->$prop_name;
if (in_array($prop_name, ['status', 'is_open', 'date_end', 'date_start'])) {
error_log("JobOrder->{$prop_name}: " . $prop_value);
}
}
}
// Tester findOpen
$openJobOrder = \SquareChilli\Bullhorn\models\JobOrder::findOpen()->where(['bullhorn_id' => $job_id])->one();
if ($openJobOrder) {
error_log("JobOrder findOpen() trouve le job");
} else {
error_log("JobOrder findOpen() NE trouve PAS le job - status actuel: " . $jobOrder->status);
// Vérifier la méthode findOpen
error_log("Critères findOpen() probablement: status = 'Open' ou similaire");
}
} else {
error_log("Aucun JobOrder trouvé avec bullhorn_id: " . $job_id);
// Lister quelques jobs pour comparaison
$someJobs = \SquareChilli\Bullhorn\models\JobOrder::find()->limit(5)->all();
error_log("Exemples de JobOrders dans la DB:");
foreach ($someJobs as $job) {
error_log("- ID: " . $job->id . ", Bullhorn ID: " . $job->bullhorn_id . ", Status: " . $job->status);
}
}
}
error_log("=== FIN DEBUG JOB ORDER ===");
}