functions.php
6.95 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
<?php
/**
* Understrap Child Theme functions and definitions
*
* @package UnderstrapChild
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
@ini_set( 'upload_max_size' , '256M' );
@ini_set( 'post_max_size', '256M');
@ini_set( 'max_execution_time', '300' );
require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/inc/inc.php';
/**
* Removes the parent themes stylesheet and scripts from inc/enqueue.php
*/
function understrap_remove_scripts() {
wp_dequeue_style( 'understrap-styles' );
wp_deregister_style( 'understrap-styles' );
wp_dequeue_script( 'understrap-scripts' );
wp_deregister_script( 'understrap-scripts' );
}
add_action( 'wp_enqueue_scripts', 'understrap_remove_scripts', 20 );
/**
* Enqueue our stylesheet and javascript file
*/
function theme_enqueue_styles() {
// Get the theme data.
$the_theme = wp_get_theme();
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
// Grab asset urls.
$theme_styles = "/css/child-theme{$suffix}.css";
$theme_scripts = "/js/child-theme{$suffix}.js";
wp_enqueue_style( 'child-understrap-styles', get_stylesheet_directory_uri() . $theme_styles, array(), $the_theme->get( 'Version' ) );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'child-understrap-scripts', get_stylesheet_directory_uri() . $theme_scripts, array(), $the_theme->get( 'Version' ), true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
// wp_enqueue_script( 'msf-globe-main', get_stylesheet_directory_uri() . '/blocks/react-app/build/static/js/main.a7bb4a96.chunk.js?v=1.222', array(), false, true );
// wp_enqueue_script( 'msf-globe-runtime', get_stylesheet_directory_uri() . '/blocks/react-app/build/static/js/2.c3c99db9.chunk.js?v=2.222', array(), false, true );
// wp_enqueue_script( 'msf-globe-chunk', get_stylesheet_directory_uri() . '/blocks/react-app/build/static/js/runtime-main.a933fda7.js?v=2.22', array(), false, true );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
/**
* Load the child theme's text domain
*/
function add_child_theme_textdomain() {
load_child_theme_textdomain( 'understrap-child', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'add_child_theme_textdomain' );
/**
* Overrides the theme_mod to default to Bootstrap 5
*
* This function uses the `theme_mod_{$name}` hook and
* can be duplicated to override other theme settings.
*
* @return string
*/
function understrap_default_bootstrap_version() {
return 'bootstrap5';
}
add_filter( 'theme_mod_understrap_bootstrap_version', 'understrap_default_bootstrap_version', 20 );
/**
* Loads javascript for showing customizer warning dialog.
*/
function understrap_child_customize_controls_js() {
wp_enqueue_script(
'understrap_child_customizer',
get_stylesheet_directory_uri() . '/js/customizer-controls.js',
array( 'customize-preview' ),
'20130508',
true
);
}
add_action( 'customize_controls_enqueue_scripts', 'understrap_child_customize_controls_js' );
function megamenu_override_default_theme($value) {
// change 'primary' to your menu location ID
if ( !isset($value['primary']['theme']) ) {
$value['primary']['theme'] = 'msf'; // change my_custom_theme_key to the ID of your exported theme
}
return $value;
}
add_filter('default_option_megamenu_settings', 'megamenu_override_default_theme');
function fixUlisting() {
$the_theme = wp_get_theme();
// wp_deregister_script( 'megamenu' );
// wp_dequeue_script( 'megamenu' );
// wp_enqueue_script( 'megamenu', get_stylesheet_directory_uri().'/js/maxmegamenu.js', array(), $the_theme->get( 'Version' ), true );
wp_deregister_script( 'search-filter-plugin-build' );
wp_dequeue_script( 'search-filter-plugin-build' );
wp_register_script( 'search-filter-plugin-build', get_stylesheet_directory_uri().'/js/search-filter-build.js', array('jquery'), $the_theme->get( 'Version' ), true );
$js_data = array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'home_url' => home_url( '/' ),
'extensions' => apply_filters( 'search_filter_extensions', array() ),
);
wp_localize_script( 'search-filter-plugin-build', 'SF_LDATA', $js_data );
wp_enqueue_script('search-filter-plugin-build');
wp_deregister_style( 'pojo-a11y' );
wp_dequeue_style( 'pojo-a11y' );
wp_register_style('pojo-a11y', get_stylesheet_directory_uri() . '/css/pojo-a11y.css', array(),'2.0.0');
wp_enqueue_style('pojo-a11y');
}
add_action( 'wp_enqueue_scripts', 'fixUlisting', 100 );
add_post_type_support( 'page', 'excerpt' );
function getName() {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
$n=10;
for ($i = 0; $i < $n; $i++) {
$index = rand(0, strlen($characters) - 1);
$randomString .= $characters[$index];
}
return $randomString;
}
function en_fr_date($date)
{
error_log($date);
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
if($my_current_lang == 'fr'){
return convert_date_fr(date('j F Y', $date), 'j F Y');
} else {
return date('F j, Y', $date);
}
}
function convert_date_fr($date, $format_in = 'j F Y') {
$months = array(
'january' => 'janvier',
'february' => 'février',
'march' => 'mars',
'april' => 'avril',
'may' => 'mai' ,
'june' => 'juin' ,
'july' => 'juillet',
'august' => 'août',
'september' => 'septembre',
'october' => 'octobre',
'november' => 'novembre',
'december' => 'décembre',
);
// List of available formats for date
$formats_list = array('d','D','j','l','N','S','w','z','S','W','M','F','m','M','n','t','A','L','o','Y','y','H','a','A','B','g','G','h','H','i','s','u','v','F','e','I','O','P','T','Z','D','c','r','U');
// We get separators between elements in $date, based on $format_in
$split = str_split($format_in);
$separators = array();
$_continue = false;
foreach($split as $k => $s) {
if($_continue) {
$_continue = false;
continue;
}
// For escaped chars (like "\h")
if($s == '\\' && isset($split[$k+1])) {
$separators[] = '\\' . $split[$k+1];
$_continue = true;
continue;
}
if(!in_array($s, $formats_list)) {
$separators[] = $s;
}
}
// Translate month name
$tmp = preg_split('/('.implode('|', array_map(function($v) {
if($v == '/') {
return '\/';
}
return str_replace('\\', '\\\\', $v);
}, $separators)).')/', $date);
foreach($tmp as $k => $v) {
$v = mb_strtolower($v, 'UTF-8');
if(isset($months[$v])) {
$tmp[$k] = $months[$v];
}
}
// Re-construct the date
$imploded = '';
foreach($tmp as $k => $v) {
$imploded .= $v . (isset($separators[$k]) ? str_replace('\\', '', $separators[$k]) : '');
}
return $imploded;
}