-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.php
236 lines (196 loc) · 9.83 KB
/
functions.php
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
<?php
/*
All the functions are in the PHP pages in the `functions/` folder.
*/
require_once get_stylesheet_directory() . '/functions/cleanup.php';
require_once get_stylesheet_directory() . '/functions/setup.php';
require_once get_stylesheet_directory() . '/functions/enqueues.php';
require_once get_stylesheet_directory() . '/functions/navbar.php';
require_once get_stylesheet_directory() . '/functions/widgets.php';
require_once get_stylesheet_directory() . '/functions/search-widget.php';
require_once get_stylesheet_directory() . '/functions/index-pagination.php';
require_once get_stylesheet_directory() . '/functions/split-post-pagination.php';
require_once get_stylesheet_directory() . '/functions/feedback.php';
require_once get_stylesheet_directory() . '/functions/remove-query-string.php';
require_once get_stylesheet_directory() . '/lib/plugin-update-checker/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/ptibogxiv/ptibogxivtheme/',
__FILE__,
'ptibogxivtheme'
);
$myUpdateChecker->setBranch('master');
$myUpdateChecker->getVcsApi()->enableReleaseAssets();
//$myUpdateChecker->setAuthentication('your-token-here');
add_filter( 'superpwa_add_theme_color', '__return_false' );
function ptibogxivtheme_load_theme_textdomain() {
load_theme_textdomain( 'ptibogxivtheme', get_template_directory() . '/languages/' );
}
add_action( 'after_setup_theme', 'ptibogxivtheme_load_theme_textdomain' );
function ptibogxivtheme_slug_setup() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'ptibogxivtheme_slug_setup' );
add_theme_support( 'custom-background',array(
'default-color' => '',
'default-image' => '',
'default-repeat' => '',
'default-position-x' => '',
'default-attachment' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
) );
add_theme_support( 'custom-header', array(
'default-image' => '',
'random-default' => false,
'width' => 0,
'height' => 0,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => true,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
'video' => true,
'video-active-callback' => 'is_front_page',
) );
add_theme_support( 'custom-logo', array(
'height' => 80,
'width' => 200,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
) );
function theme_prefix_setup() {
add_theme_support( 'custom-logo', array(
'height' => 80,
'width' => 200,
'flex-width' => true,
) );
}
add_action( 'after_setup_theme', 'theme_prefix_setup' );
function custom_excerpt_length( $length ) {
return 25;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function wpc_show_admin_bar() {
global $current_user;
if ( current_user_can( 'edit_posts' ) && !get_theme_mod( 'ptibogxivtheme_adminbar') ) {
return false;
} elseif ( current_user_can( 'edit_posts' ) && is_user_logged_in() && $current_user->show_admin_bar_front == 'true' ) {
return true;
}
else {
return false;
}
}
add_filter('show_admin_bar' , 'wpc_show_admin_bar');
function ptibogxivtheme_social() {
global $post;
$return = "<div class='btn-group d-flex' role='group' aria-label='First group'>
<a href='#' class='btn btn-light disabled w-100' role='button' aria-disabled='true'><i class='fas fa-share-alt fa-fw'></i></a>
<a href='mailto:?subject=[".get_bloginfo('name')."] Informations intéressante&body=Bonjour, ".get_permalink($post->ID)."' role='button' class='btn btn-dark w-100' target='_blank'><i class='fas fa-envelope fa-fw'></i></a>";
//<script>//if (navigator.userAgent.match(/iPhone|Android/i)) {
//document.write('<a href='whatsapp://send?text=<?php echo get_permalink($post->ID);' data-action='share/whatsapp/share' role='button' class='btn btn-whatsapp' target='_blank'><i class='fab fa-whatsapp fa-fw'></i></a>');
//}</script>
$return .= "<a href='https://www.facebook.com/sharer/sharer.php?u=".get_permalink($post->ID)."&t=".get_the_title()."' role='button' class='btn btn-facebook w-100' target='_blank'><i class='fab fa-facebook-f fa-fw'></i></a>
<a href='https://twitter.com/intent/tweet?text=".get_the_title()."&url=".get_permalink($post->ID)."&via=".get_option('doliconnect_social_twitter')."' role='button' class='btn btn-twitter w-100' target='_blank'><i class='fab fa-twitter fa-fw'></i></a>
<a href='https://www.linkedin.com/shareArticle?mini=true&url=url=".get_permalink($post->ID)."&title=".get_the_title()."&source=".get_option('doliconnect_social_linkedin')."' role='button' class='btn btn-linkedin w-100' target='_blank'><i class='fab fa-linkedin-in fa-fw'></i></a>
<a href='https://pinterest.com/pin/create/button/?url=".get_permalink($post->ID)."&media=&description=".get_the_title()."' role='button' class='btn btn-pinterest w-100' target='_blank'><i class='fab fa-pinterest fa-fw'></i></a>
</div>";
return $return;
}
function ptibogxiv_alert() {
if ( is_user_logged_in() && function_exists('callAPI') ){
$time = current_time( 'timestamp',1);
if ( get_site_option('doliconnect_mode')=='one' && function_exists('switch_to_blog') ) {
switch_to_blog(1);
}
if ( constant("DOLIBARR_MEMBER") > 0 ) {
$adherent = callDoliApi("GET", "/adherentsplus/".constant("DOLIBARR_MEMBER"), null, dolidelay( DAY_IN_SECONDS, esc_attr(isset($_GET["refresh"]) ? $_GET["refresh"] : null)));
if ( $time>$adherent->datefin && $adherent->statut == '1' && !empty($adherent->datefin) ) {
$alert = "<br><div class='card text-white bg-info'><div class='card-body'>Il semble que votre adhésion a expiré le ".date_i18n('d/m/Y', $adherent->datefin).". Afin de ne pas perdre vos avantages, renouvelez <a href='".esc_url( add_query_arg( 'module', 'membership', doliconnecturl('doliaccount')) )."' class='alert-link'>en cliquant -ici-</a>.</div></div>";
} elseif ( $time>$adherent->datefin && $adherent->statut == '1' && empty($adherent->datefin!=null) ) {
$alert = "<br><div class='card text-white bg-info'><div class='card-body'>Il semble que vous n'avez pas encore réglé votre adhésion. Afin de bénéficier de vos avantages, finalisez <a href='".esc_url( add_query_arg( 'module', 'membership', doliconnecturl('doliaccount')) )."' class='alert-link'>en cliquant -ici-</a>.</div></div>";
} elseif ( $time>$adherent->next_subscription_renew && $time<$adherent->datefin && $adherent->statut == '1' ) {
$alert = "<BR><div class='card text-white bg-info'><div class='card-body'>Il semble que votre adhésion expire le ".date_i18n('d/m/Y', $adherent->datefin).". Afin de ne pas perdre vos avantages, renouvelez <a href='".esc_url( add_query_arg( 'module', 'membership', doliconnecturl('doliaccount')) )."' class='alert-link'>en cliquant -ici-</a>.</div></div>";
} else {
$alert = null;
}
}
if ( get_site_option('doliconnect_mode')=='one' && function_exists('switch_to_blog') ) {
restore_current_blog();
}
} else {
$alert = null;
}
return $alert;
}
function ptibogxivtheme_gradient() {
return "backdrop-filter: blur(5px);-webkit-backdrop-filter: blur(5px);background-color: rgba(255, 255, 255, 0.55);";
}
add_action('add_meta_boxes','caroussel_metabox');
function caroussel_metabox(){
add_meta_box('url_crea', 'Caroussel', 'url_crea', 'post', 'side');
}
function url_crea($post){
$url = get_post_meta($post->ID,'_displaycaroussel',true);
echo '<label for="url_meta">Afficher dans le carrousel</label>';
echo '<input id="url_meta" type="text" name="url_site" value="'.$url.'" />';
}
add_action('save_post','save_metabox');
function save_metabox($post_id){
if(isset($_POST['url_site']))
update_post_meta($post_id, '_url_crea', esc_url($_POST['url_site']));
}
function ptibogxivtheme_time_ago() {
global $post;
$date = get_post_time('G', true, $post);
if ($post->post_type == 'post') {
// Array of time period chunks
$chunks = array(
array( 60 * 60 * 24 * 365 , __( 'year', 'ptibogxivtheme' ), __( 'years', 'ptibogxivtheme' ) ),
array( 60 * 60 * 24 * 30 , __( 'month', 'ptibogxivtheme' ), __( 'months', 'ptibogxivtheme' ) ),
array( 60 * 60 * 24 * 7, __( 'week', 'ptibogxivtheme' ), __( 'weeks', 'ptibogxivtheme' ) ),
array( 60 * 60 * 24 , __( 'day', 'ptibogxivtheme' ), __( 'days', 'ptibogxivtheme' ) ),
array( 60 * 60 , __( 'hour', 'ptibogxivtheme' ), __( 'hours', 'ptibogxivtheme' ) ),
array( 60 , __( 'minute', 'ptibogxivtheme' ), __( 'minutes', 'ptibogxivtheme' ) ),
array( 1, __( 'second', 'ptibogxivtheme' ), __( 'seconds', 'ptibogxivtheme' ) )
);
if ( !is_numeric( $date ) ) {
$time_chunks = explode( ':', str_replace( ' ', ':', $date ) );
$date_chunks = explode( '-', str_replace( ' ', '-', $date ) );
$date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );
}
$current_time = current_time( 'mysql', $gmt = 0 );
$newer_date = strtotime( $current_time );
// Difference in seconds
$since = $newer_date - $date;
// Something went wrong with date calculation and we ended up with a negative date.
if ( 0 > $since )
return __( 'sometime', 'ptibogxivtheme' );
/**
* We only want to output one chunks of time here, eg:
* x years
* xx months
* so there's only one bit of calculation below:
*/
//Step one: the first chunk
for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
$seconds = $chunks[$i][0];
// Finding the biggest chunk (if the chunk fits, break)
if ( ( $count = floor($since / $seconds) ) != 0 )
break;
}
// Set output var
$duration = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
if ( !(int)trim($duration) ){
$duration = '0 ' . __( 'seconds', 'ptibogxivtheme' );
}
return sprintf( esc_html__( '%s ago', 'ptibogxivtheme' ), $duration);
}
}
// Filter our ptibogxivtheme_time_ago() function into WP's the_time() function
add_filter('the_time', 'ptibogxivtheme_time_ago');