1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Games Collector |
4
|
|
|
* |
5
|
|
|
* @package GC\GamesCollector |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace GC\GamesCollector; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Hook all the things. |
12
|
|
|
* |
13
|
|
|
* @since 0.1 |
14
|
|
|
*/ |
15
|
|
|
function bootstrap() { |
16
|
|
|
// Add all your plugin hooks here. |
17
|
|
|
add_action( 'cmb2_init', __NAMESPACE__ . '\\Game\\fields' ); |
18
|
|
|
add_action( 'init', __NAMESPACE__ . '\\Game\\register_cpt' ); |
19
|
|
|
add_action( 'init', __NAMESPACE__ . '\\Attributes\\register_taxonomy' ); |
20
|
|
|
add_action( 'admin_init', __NAMESPACE__ . '\\Attributes\\create_default_attributes' ); |
21
|
|
|
add_action( 'add_meta_boxes', __NAMESPACE__ . '\\Attributes\\metabox' ); |
22
|
|
|
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\Attributes\\enqueue_scripts' ); |
23
|
|
|
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\Display\\enqueue_scripts' ); |
24
|
|
|
add_action( 'register_shortcode_ui', __NAMESPACE__ . '\\Shortcode\\register_all_games_shortcode' ); |
25
|
|
|
add_action( 'register_shortcode_ui', __NAMESPACE__ . '\\Shortcode\\register_individual_games_shortcode' ); |
26
|
|
|
add_filter( 'rest_prepare_gc_game', __NAMESPACE__ . '\\Api\\filter_games_json', 10, 2 ); |
27
|
|
|
add_filter( 'gc_filter_players', __NAMESPACE__ . '\\numbers_of_players', 10, 3 ); |
28
|
|
|
add_shortcode( 'games-collector', __NAMESPACE__ . '\\Shortcode\\shortcode' ); |
29
|
|
|
add_shortcode( 'games-collector-list', __NAMESPACE__ . '\\Shortcode\\shortcode' ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Create a new page with the games-collector shortcode in it on activation if a Games page doesn't already exist. |
34
|
|
|
* |
35
|
|
|
* @since 1.1.0 |
36
|
|
|
*/ |
37
|
|
|
function activate() { |
38
|
1 |
|
if ( ! get_page_by_title( esc_html__( 'Games', 'games-collector' ) ) ) { |
39
|
1 |
|
wp_insert_post([ |
40
|
1 |
|
'post_type' => 'page', |
41
|
1 |
|
'post_title' => esc_html__( 'Games', 'games-collector' ), |
42
|
1 |
|
'post_content' => '[games-collector]', |
43
|
1 |
|
'post_status' => 'publish', |
44
|
|
|
] ); |
45
|
|
|
} |
46
|
1 |
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Update the number of players. |
50
|
|
|
* |
51
|
|
|
* Adds conditions for games with specific number of players only (e.g. 1 player, 2 players) or an indeterminate or very large number of players (e.g. 2+, 2-99 players). |
52
|
|
|
* |
53
|
|
|
* @since 1.2.0 |
54
|
|
|
* @param int $game_id The game's post ID. |
55
|
|
|
* @param array $players_min_max The minimum and maximum number of players. |
56
|
|
|
* @param string $output The player output. |
57
|
|
|
* @return string The filtered output. |
58
|
|
|
*/ |
59
|
|
|
function numbers_of_players( $game_id, $players_min_max, $output ) { |
|
|
|
|
60
|
|
|
|
61
|
|
|
// Deal with max number of players matching min number of players. |
62
|
3 |
View Code Duplication |
if ( absint( $players_min_max['min'] ) === absint( $players_min_max['max'] ) ) { |
|
|
|
|
63
|
1 |
|
return esc_attr( sprintf( |
64
|
|
|
// Translators: %d is the number of players. |
65
|
1 |
|
_n( '%d player', '%d players', absint( $players_min_max['min'] ), 'games-collector' ), |
66
|
1 |
|
absint( $players_min_max['min'] ) |
67
|
|
|
) ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// Deal with indeterminate or large number of max players. |
71
|
3 |
View Code Duplication |
if ( 0 === absint( $players_min_max['max'] ) || 20 <= absint( $players_min_max['max'] ) ) { |
|
|
|
|
72
|
1 |
|
return esc_attr( sprintf( |
73
|
|
|
// Translators: %d is the minimum number players. |
74
|
1 |
|
__( '%d+ players', 'games-collector' ), |
75
|
1 |
|
absint( $players_min_max['min'] ) |
76
|
|
|
) ); |
77
|
|
|
} |
78
|
|
|
|
79
|
2 |
|
return $output; |
80
|
|
|
} |
81
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.