-
Notifications
You must be signed in to change notification settings - Fork 0
/
aeris-team.php
513 lines (447 loc) · 20.7 KB
/
aeris-team.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
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<?php
/**
* Plugin Name: Aeris Team Manager
* Plugin URI : https://github.com/aeris-data/aeris-wppl-team
* Description: Plugin pour gérer les membres et les équipes
* Text Domain: aeris-wppl-team-manager
* Domain Path: /languages
* Author: Pierre VERT & Elisabeth Pointal
* Version: 1.4.1
* GitHub Plugin URI: aeris-data/aeris-wppl-team
* GitHub Branch: master
*/
include 'inc/commons.php';
function aeris_team_manager_plugin_init(){
/* Gestion de la dépendance de ACF */
if ( ! function_exists('get_field') && current_user_can( 'activate_plugins' ) ) {
add_action( 'admin_init', 'sb_plugin_deactivate');
add_action( 'admin_notices', 'sb_plugin_admin_notice');
//Désactiver le plugin
function sb_plugin_deactivate () {
deactivate_plugins( plugin_basename( __FILE__ ) );
}
// Alerter pour expliquer pourquoi il ne s'est pas activé
function sb_plugin_admin_notice () {
echo '<div class="error">Le plugin "Aeris Team Member" requiert ACF Pro pour fonctionner <br><strong>Activez ACF Pro ci-dessous</strong> ou <a href=https://wordpress.org/plugins/advanced-custom-fields/> Téléchargez ACF Pro »</a><br></div>';
if ( isset( $_GET['activate'] ) )
unset( $_GET['activate'] );
}
} else {
// Le plugin est activé
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* FLUSH REWRITE RULE
*
* !!! WARNING !!! SEULEMENT à L'ACTIVATION/DESACTIVATION DU PLUGIN !!!
*
* source : https://codex.wordpress.org/Function_Reference/flush_rewrite_rules
*/
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
register_activation_hook( __FILE__, 'aeris_team_manager_flush_rewrites' );
function aeris_team_manager_flush_rewrites() {
// call your CPT registration function here (it should also be hooked into 'init')
aeris_team_manager_cpt();
flush_rewrite_rules();
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/*
* LOAD TEXT DOMAIN FOR TEXT TRANSLATIONS
*/
function aeris_team_manager_load_plugin_textdomain() {
$domain = 'aeris-wppl-team-manager';
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
// wp-content/languages/plugin-name/plugin-name-fr_FR.mo
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
// wp-content/plugins/plugin-name/languages/plugin-name-fr_FR.mo
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'init', 'aeris_team_manager_load_plugin_textdomain' );
//---------------------------------------------------------------------------------------------------------------------------------------------------------
// LOAD ACF CONFIG FILE & custom functions for ACF
function load_acf_config() {
require_once 'inc/acf-config.php';
}
add_action('init', 'load_acf_config');
// LOAD CSS & SCRIPTS
function aeris_team_manager_scripts() {
wp_register_style( 'aeris-team-style', plugins_url('css/aeris-team-manager.css', __FILE__) );
wp_enqueue_style( 'aeris-team-style' );
}
add_action('wp_enqueue_scripts','aeris_team_manager_scripts');
// @author epointal
// LOAD CSS & SCRIPTS FOR GUTENBERG EDITOR
function aeris_team_gutenberg_enqueue_block_editor_assets() {
wp_enqueue_script(
'aeris-team-block-js', // Unique handle.
plugins_url('js/team-block.js', __FILE__),
array( 'wp-blocks', 'wp-i18n', 'wp-element' )
);
// write teams list for js script
wp_localize_script( 'aeris-team-block-js', 'aerisTeamOptions', get_teams_options() );
}
add_action( 'enqueue_block_editor_assets', 'aeris_team_gutenberg_enqueue_block_editor_assets');
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* CREATE CUSTOM MENU
*
* source : http://imtiazrayhan.com/multiple-custom-post-types-menu-section/
*/
/*
* Adding a menu to contain the custom post types for frontpage
*/
function aeris_team_manager_admin_menu() {
add_menu_page(
'Teams manager',
'Teams manager',
'read',
'aeris_team_manager_admin_menu',
'',
'dashicons-groups',
20
);
}
add_action( 'admin_menu', 'aeris_team_manager_admin_menu' );
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/**
* Création des custom post type (cpt)
*/
add_action('init', 'aeris_team_manager_cpt');
function aeris_team_manager_cpt() {
// CPT EQUIPE
register_post_type(
'aeris-team',
array(
'label' => __('Team', 'aeris-wppl-team-manager'),
'labels' => array(
'name' => __('Teams', 'aeris-wppl-team-manager'),
'singular-name' => __('Team', 'aeris-wppl-team-manager'),
'all_items' => __('Manage teams', 'aeris-wppl-team-manager'),
'add_new_item' => __('Add team', 'aeris-wppl-team-manager'),
'edit_item' => __('Edit team', 'aeris-wppl-team-manager'),
'new_item' => __('New team', 'aeris-wppl-team-manager'),
'view_item' => __('See team', 'aeris-wppl-team-manager'),
'search_item' => __('Search team', 'aeris-wppl-team-manager'),
'not_found' => __('No team found', 'aeris-wppl-team-manager'),
'not_found_in_trash' => __('No team found in trash', 'aeris-wppl-team-manager')
),
'public' => true,
'show_in_rest' => true,
'capability_type' => 'post',
// Show in this admin menu
'show_in_menu' => 'aeris_team_manager_admin_menu',
// rewrite URL
'rewrite' => array( 'slug' => 'teams' ),
'supports' => array(
'title',
'editor'
),
'has_archive' => true,
// Url vers une icone ou à choisir parmi celles de WP : https://developer.wordpress.org/resource/dashicons/.
'menu_icon' => 'dashicons-groups',
)
);
// MEMBRES
register_post_type(
'aeris-member',
array(
'label' => __('Member', 'aeris-wppl-team-manager'),
'labels' => array(
'name' => __('Members', 'aeris-wppl-team-manager'),
'singular-name' => __('Member', 'aeris-wppl-team-manager'),
'all_items' => __('Manage members', 'aeris-wppl-team-manager'),
'add_new_item' => __('Add member', 'aeris-wppl-team-manager'),
'edit_item' => __('Edit member', 'aeris-wppl-team-manager'),
'new_item' => __('New member', 'aeris-wppl-team-manager'),
'view_item' => __('See member', 'aeris-wppl-team-manager'),
'search_item' => __('Search member', 'aeris-wppl-team-manager'),
'not_found' => __('No member found', 'aeris-wppl-team-manager'),
'not_found_in_trash' => __('No member found in trash', 'aeris-wppl-team-manager')
),
'public' => true,
'show_in_rest' => true,
'capability_type' => 'post',
// Show in this admin menu
'show_in_menu' => 'aeris_team_manager_admin_menu',
// rewrite URL
'rewrite' => array( 'slug' => 'members' ),
// 'supports' => array(
// 'title',
// 'author',
// 'editor'
// ),
'supports' => false,
'has_archive' => true,
// Url vers une icone ou à choisir parmi celles de WP : https://developer.wordpress.org/resource/dashicons/.
'menu_icon' => 'dashicons-admin-users',
)
);
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/*
* REGISTER TPL SINGLE TEAM
*/
add_filter ( 'single_template', 'aeris_team_manager_single' );
function aeris_team_manager_single($single_template) {
global $post;
if ($post->post_type == 'aeris-team') {
$single_template = plugin_dir_path ( __FILE__ ) . 'single-aeris-team.php';
}
return $single_template;
}
/*
* REGISTER TPL SINGLE MEMBER
*/
add_filter ( 'single_template', 'aeris_member_manager_single' );
function aeris_member_manager_single($single_template) {
global $post;
if ($post->post_type == 'aeris-member') {
$single_template = plugin_dir_path ( __FILE__ ) . 'single-aeris-member.php';
}
return $single_template;
}
/* Add image size for team logo
* https://developer.wordpress.org/reference/functions/add_image_size/
*/
function aeris_team_manager_images_setup() {
add_image_size( 'team-logo', 200, 200, false );
add_image_size( 'member-photo', 150, 150, true );
}
add_action( 'after_setup_theme', 'aeris_team_manager_images_setup' );
//--------------------------------------------------------------------------------------------------------------------------------
/**
* SEARCH TEAMS
***************/
/* @author epointal
* Return array of teams
* ie array of couple (value, label) where value is the ID, and label the name of team
*/
function get_teams_options () {
$args = array( 'post_type' => 'aeris-team', 'posts_per_page' => 200 , 'order' => 'desc');
$teams = new WP_Query( $args );
$values = array();
foreach($teams->posts as $post){
array_push($values, array('value' => $post->ID, 'label' =>$post->post_title));
}
return $values;
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/****************************************************************************************************
* SHORTCODES
*/
function aeris_team_manager_register_shortcodes(){
add_shortcode('aeris_team', 'aeris_team_manager_team_shortcode');
add_shortcode('aeris_member', 'aeris_team_manager_member_shortcode');
// @author epointal
// Gutenberg team block like <!-- wp:aeris-wppl-team/team-block {"id":607} /-->
// is interpreted like [aeris_team id=607]
if (function_exists('register_block_type')) {
register_block_type( 'aeris-wppl-team/team-block', array(
'render_callback' => 'aeris_team_manager_team_shortcode'
) );
}
}
/*************************************************************************
* SHORTCODE FOR INSERT TEAM
*/
// Team Shortcode output
function aeris_team_manager_team_shortcode($atts) {
global $post;
$atts = shortcode_atts([
'id' => null,
], $atts, 'aeris_team');
if (!$atts['id']) {
return;
}
$_post = get_post($atts['id']);
if (!$_post || 'publish' !== $_post->post_status) {
return;
}
$post = $_post;
setup_postdata($post);
ob_start();
?>
<div class="aeris_team_manager_shortcode_team_display">
<h2><?php the_title();?></h2>
<?php
include( 'template-parts/aeris-team-showteam.php' );
?>
</div>
<?php
$out = ob_get_clean();
wp_reset_postdata();
return $out;
}
/** ********************************************************************
*
* Show Team Shortcode in admin page
*/
/** *******************************************
* 1 . Ajout de la colonne Shortcode pour les CPT aeris-team
*
*/
function aeris_team_manager_team_shortcode_columns($column) {
$column['shortcode'] = 'Shortcode';
return $column;
}
add_filter('manage_aeris-team_posts_columns', 'aeris_team_manager_team_shortcode_columns');
/** ********************************************************************
* 2 . Html à afficher dans les lignes de la colonne Shortcode
* pour les CPT aeris-team
*/
function aeris_team_manager_team_shortcode_rows($column, $post_id) {
switch ($column) {
case 'shortcode':
echo "[aeris_team id=" . $post_id . "]";
break;
default:
break;
}
}
add_action('manage_aeris-team_posts_custom_column', 'aeris_team_manager_team_shortcode_rows', 10, 2);
/**
* 3 . Adds a box to the main column on the Aeris-team edit screens.
*/
function aeris_team_manager_team_shortcode_metabox() {
add_meta_box(
'aeris_team_manager_team_metabox_id',
__('Shortcode integration', 'aeris-wppl-team-manager'),
'aeris_team_manager_team_shortcode_metabox_callback', 'aeris-team', 'side'
);
}
add_action('add_meta_boxes', 'aeris_team_manager_team_shortcode_metabox');
/**
* 4 . Render meta box content for CPT aeris-team
*/
function aeris_team_manager_team_shortcode_metabox_callback($post) {
echo '<p style="font-size:1.5rem;color:#4765a0;">[aeris_team id="' . $post->ID . '"]</p>';
}
/*************************************************************************
* SHORTCODE FOR INSERT MEMBER
*/
// Member Shortcode output **********************************
function aeris_team_manager_member_shortcode($atts) {
global $post;
$atts = shortcode_atts([
'id' => null,
], $atts, 'aeris_member');
if (!$atts['id']) {
return;
}
$_post = get_post($atts['id']);
if (!$_post || 'publish' !== $_post->post_status) {
return;
}
$post = $_post;
setup_postdata($post);
ob_start();
?>
<div class="aeris_team_manager_shortcode_member_display">
<?php
include( 'template-parts/aeris-team-showmember.php' );
?>
</div>
<?php
$out = ob_get_clean();
wp_reset_postdata();
return $out;
}
// hook in wordpress
add_action( 'init', 'aeris_team_manager_register_shortcodes');
/** ********************************************************************
*
* Show Member Shortcode in admin page
*/
/** *******************************************
* 1 . Ajout de la colonne Shortcode pour les CPT aeris-member
*
*/
function aeris_team_manager_member_shortcode_columns($column) {
$column['shortcode'] = 'Shortcode';
return $column;
}
add_filter('manage_aeris-member_posts_columns', 'aeris_team_manager_member_shortcode_columns');
/** *******************************************
* 2 . Html à afficher dans les lignes de la colonne Shortcode
* pour les CPT aeris-member
*/
function aeris_team_manager_member_shortcode_rows($column, $post_id) {
switch ($column) {
case 'shortcode':
echo "[aeris_member id=" . $post_id . "]";
break;
default:
break;
}
}
add_action('manage_aeris-member_posts_custom_column', 'aeris_team_manager_member_shortcode_rows', 10, 2);
/** ********************************************************************
* 3 . Adds a box to the main column on the
* aeris-member edit screens.
*/
function aeris_team_manager_member_shortcode_metabox() {
add_meta_box(
'aeris_team_manager_member_metabox_id',
__('Shortcode integration', 'aeris-wppl-team-manager'),
'aeris_team_manager_member_shortcode_metabox_callback', 'aeris-member', 'side'
);
}
add_action('add_meta_boxes', 'aeris_team_manager_member_shortcode_metabox');
/** ******************************************
* 4 . Render meta box content for CPT aeris-member
*/
function aeris_team_manager_member_shortcode_metabox_callback($post) {
echo '<p style="font-size:1.3rem;color:#4765a0;">[aeris_member id="' . $post->ID . '"]</p>';
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
/*
* Custom CSS FOR AERIS THEME
*/
function aeris_team_manager_customCSS() {
?>
<style>
<?php
// if theme Aeris
if (get_theme_mod('theme_aeris_main_color') == "custom" ) {
$code_color = get_theme_mod( 'theme_aeris_color_code' );
?>
:root {
--theme-color:<?php echo $code_color;?>;
--hover-text-color:<?php echo $hover_text_color;?>;
}
<?php
}
else {
$code_color = get_theme_mod( 'theme_aeris_main_color' );
?>
:root {
--theme-color:<?php echo $code_color;?>;
--hover-text-color:<?php echo $hover_text_color;?>;
}
<?php
}
?>
input[id^="aeris_team_manager_member_info"]:checked ~ header,
.aeris_team_manager_memberSingle > header {
background: var(--theme-color);
}
label[for^="aeris_team_manager_member_info"] {
background: var(--theme-color);
color:#FFF;
}
.aeris_team_manager_membersEmbed > header:hover label[for^="aeris_team_manager_member_info"] {
background:<?php echo get_theme_mod('theme_aeris_second_color_code' );?>
}
input[id^="aeris_team_manager_member_info"]:checked ~ header label {
background:#EEE;
color:var(--theme-color);
}
</style>
<?php
}
// add_action('wp_head', 'aeris_team_manager_customCSS');
remove_filter( 'the_content', 'wpautop' );
//---------------------------------------------------------------------------------------------------------------------------------------------------------
} // end test plugin ACF
}
add_action('plugins_loaded', 'aeris_team_manager_plugin_init');
?>