-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
217 lines (178 loc) · 5.7 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
<?php
/**
* wp-gatsby-theme functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package wp-gatsby-theme
*/
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
function load_custom_wp_admin_style() {
wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/css/custom-admin-style.css', false, '20190507145010' );
wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );
function wp_gatsby_theme_status_toolbar() {
global $wp_admin_bar;
if ( ! is_super_admin() || ! is_admin_bar_showing() ) {
return;
}
$status_img = get_deploy_settings( 'status_image' );
$status_link = get_deploy_settings( 'status_link' );
if ( isset( $status_img ) ) {
$wp_admin_bar->add_node(
array(
'id' => 'site-status',
'title' => '<img src="' . $status_img . '" />',
'href' => $status_link,
'meta' => array(
'class' => 'site-status-toolbar',
'rel' => 'noopener noreferrer',
'target' => '_blank',
),
)
);
}
}
add_action( 'wp_before_admin_bar_render', 'wp_gatsby_theme_status_toolbar' );
// Fonction pour modifier l'adresse email de l'expéditeur
function wpm_email_from( $original_email_address ) {
$domain_name = substr( strrchr( $original_email_address, '@' ), 1 );
return 'no-reply@' . $domain_name;
}
add_filter( 'wp_mail_from', 'wpm_email_from' );
// Fonction pour changer le nom de l'expéditeur de l'email
function wpm_expediteur( $original_email_from ) {
return 'API Portfolio';
}
add_filter( 'wp_mail_from_name', 'wpm_expediteur' );
function activate_wp_gatsby_theme() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'jwt-authentication-for-wp-rest-api/jwt-auth.php' ) ) {
activate_jwt_auth();
}
register_cron_deploy();
}
add_action( 'after_switch_theme', 'activate_wp_gatsby_theme' );
function deactivate_wp_gatsby_theme() {
unregister_setting( 'theme-settings', 'wp_gatsby_theme_deploy_settings' );
unregister_setting( 'theme-settings', 'wp_gatsby_theme_jwt_settings' );
delete_option( 'wp_gatsby_theme_page_settings' );
delete_option( 'wp_gatsby_theme_social_settings' );
delete_option( 'wp_gatsby_theme_deploy_settings' );
delete_option( 'wp_gatsby_theme_jwt_settings' );
delete_option( 'update_deploy_cron' );
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'jwt-authentication-for-wp-rest-api/jwt-auth.php' ) ) {
deactivate_jwt_auth();
}
unregister_cron_deploy();
}
add_action( 'switch_theme', 'deactivate_wp_gatsby_theme' );
function activate_jwt_auth() {
$htaccess = array(
'<IfModule mod_rewrite.c>',
'RewriteEngine on',
'RewriteCond %{HTTP:Authorization} ^(.*)',
'RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]',
'</IfModule>',
);
$htaccess_status = wp_gatsby_theme_update_htaccess( $htaccess );
$secret_key = bin2hex( random_bytes( 32 ) );
$wp_config = array(
'/* JWT Auth settings for wp-gatsby-theme. */ ',
"define( 'JWT_AUTH_SECRET_KEY', '$secret_key' );",
"define( 'JWT_AUTH_CORS_ENABLE', false );",
);
$wp_config_status = wp_gatsby_theme_update_config( $wp_config );
if ( is_wp_error( $wp_config_status ) ) {
$wp_config_type = 'error';
} else {
$wp_config_type = 'success';
}
wp_gatsby_theme_add_notices(
array(
'type' => $wp_config_type,
'msg' => $wp_config_status,
)
);
if ( is_wp_error( $htaccess_status ) ) {
$htaccess_type = 'error';
} else {
$htaccess_type = 'success';
}
wp_gatsby_theme_add_notices(
array(
'type' => $htaccess_type,
'msg' => $htaccess_status,
)
);
}
register_activation_hook( 'jwt-authentication-for-wp-rest-api/jwt-auth.php', 'activate_jwt_auth' );
function deactivate_jwt_auth() {
$htaccess_status = wp_gatsby_theme_update_htaccess();
$wp_config_status = wp_gatsby_theme_update_config();
if ( is_wp_error( $wp_config_status ) ) {
$wp_config_type = 'error';
} else {
$wp_config_type = 'success';
}
wp_gatsby_theme_add_notices(
array(
'type' => $wp_config_type,
'msg' => $wp_config_status,
)
);
if ( is_wp_error( $htaccess_status ) ) {
$htaccess_type = 'error';
} else {
$htaccess_type = 'success';
}
wp_gatsby_theme_add_notices(
array(
'type' => $htaccess_type,
'msg' => $htaccess_status,
)
);
}
register_deactivation_hook( 'jwt-authentication-for-wp-rest-api/jwt-auth.php', 'deactivate_jwt_auth' );
function wp_gatsby_theme_admin_notices() {
if ( $notices = get_option( 'wp_gatsby_theme_notices' ) ) {
foreach ( $notices as $notice ) {
$class = "notice notice-{$notice['type']} is-dismissible";
$message = __( $notice['msg'], 'wp-gatsby-theme' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
delete_option( 'wp_gatsby_theme_notices' );
}
}
add_action( 'admin_notices', 'wp_gatsby_theme_admin_notices' );
// Load custom post types
require get_template_directory() . '/post-types/project.php';
// Load custom taxonomies display
require get_template_directory() . '/taxonomies/display.php';
// Load custom taxonomy
require get_template_directory() . '/taxonomies/filter.php';
// Load Rest API changes
require get_template_directory() . '/inc/api-changes.php';
// Load Settings page
require get_template_directory() . '/inc/settings.php';
// Load JWT Auth configuration
require get_template_directory() . '/inc/jwt-auth.php';
// Load Deploy configuration
require get_template_directory() . '/inc/deploy.php';
// Load Page configuration
require get_template_directory() . '/inc/theme_page.php';
// Load helpers function
require get_template_directory() . '/inc/helpers.php';