1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Game Collector Template Tags |
4
|
|
|
* |
5
|
|
|
* Public helper functions to use in themes and add-ons. |
6
|
|
|
* |
7
|
|
|
* @package GC\GamesCollector |
8
|
|
|
* @since 0.2 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use \GC\GamesCollector\Game; |
12
|
|
|
use \GC\GamesCollector\Shortcode; |
13
|
|
|
use \GC\GamesCollector\Attributes; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Returns the difficulty for a game. |
17
|
|
|
* |
18
|
|
|
* @since 0.2 |
19
|
|
|
* @param integer $post_id The ID for the game to get the difficulty for. |
20
|
|
|
* @return string The human-readable difficulty level (not the meta value saved). |
21
|
|
|
*/ |
22
|
|
|
function gc_get_difficulty( $post_id = 0 ) { |
23
|
1 |
|
return Game\get_difficulty( $post_id ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Echoes the difficulty for the current game. Must be used inside the Loop. |
28
|
|
|
* |
29
|
|
|
* @since 0.2 |
30
|
|
|
*/ |
31
|
|
|
function gc_the_difficulty() { |
32
|
|
|
echo esc_html( Game\get_difficulty() ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns the age range (e.g. 11+) for a game. |
37
|
|
|
* |
38
|
|
|
* @since 0.2 |
39
|
|
|
* @param int $post_id The Post ID to retrieve the minimum age for. |
40
|
|
|
* @return string The age range for the game. |
41
|
|
|
*/ |
42
|
|
|
function gc_get_age( $post_id = 0 ) { |
43
|
1 |
|
return Game\get_age( $post_id ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Echoes the age range (e.g. 11+) for the current game. Must be used inside the Loop. |
48
|
|
|
* |
49
|
|
|
* @since 0.2 |
50
|
|
|
*/ |
51
|
|
|
function gc_the_age() { |
52
|
|
|
echo esc_html( Game\get_age() ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the number of players (min to max) for a game. |
57
|
|
|
* |
58
|
|
|
* @since 0.2 |
59
|
|
|
* @param int $post_id The Post ID to retrieve the number of players for. |
60
|
|
|
* @return string The number of players for the game. |
61
|
|
|
*/ |
62
|
|
|
function gc_get_number_of_players( $post_id = 0 ) { |
63
|
1 |
|
return Game\get_number_of_players( $post_id ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Echoes the number of players (min to max) for the current game. Must be used inside the Loop. |
68
|
|
|
* |
69
|
|
|
* @since 0.2 |
70
|
|
|
*/ |
71
|
|
|
function gc_the_number_of_players() { |
72
|
|
|
echo esc_html( Game\get_number_of_players() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the min and max number of players for a game. |
77
|
|
|
* |
78
|
|
|
* @since 0.2 |
79
|
|
|
* @param integer $post_id The ID of the game to get the number of players from. |
80
|
|
|
* @return array An array containing the minimum and maximum number of players for the game. |
81
|
|
|
*/ |
82
|
|
|
function gc_get_players_min_max( $post_id = 0 ) { |
83
|
|
|
return Game\get_players_min_max( $post_id ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns a list of all games. |
88
|
|
|
* |
89
|
|
|
* @since 0.2 |
90
|
|
|
* @return string All the games in formatted HTML. |
91
|
|
|
*/ |
92
|
|
|
function gc_get_games() { |
93
|
1 |
|
return Shortcode\shortcode( [] ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Echoes a list of all games. |
98
|
|
|
* |
99
|
|
|
* @since 0.2 |
100
|
|
|
*/ |
101
|
|
|
function gc_the_games() { |
102
|
|
|
echo Shortcode\shortcode( [] ); // WPCS: XSS ok. Already sanitized. |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Return a game or a list of games. |
107
|
|
|
* |
108
|
|
|
* @since 1.1.0 |
109
|
|
|
* @param mixed $post_ids Can be a valid game post ID, an array of games, or a comma-separated list of games. |
110
|
|
|
* @return string The requested games in formatted HTML. |
111
|
|
|
*/ |
112
|
|
|
function gc_get_game( $post_ids = '' ) { |
113
|
|
|
// If nothing was passed, just use gc_get_games. |
114
|
1 |
|
if ( '' === $post_ids ) { |
115
|
|
|
return gc_get_games(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
// If an array was passed, implode the array and pass a comma-separated list of IDs to the shortcode. |
119
|
1 |
|
if ( is_array( $post_ids ) ) { |
120
|
1 |
|
return Shortcode\shortcode( [ 'gc_game' => $post_ids ] ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// If there's a comma, we'll assume comma-separated values, so deal with normally. |
124
|
1 |
|
if ( false !== strpos( (string) $post_ids, ',' ) ) { |
125
|
1 |
|
return Shortcode\shortcode( [ 'gc_game' => $post_ids ] ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// If an integer was passed, and it's a valid, non-zero integer, pass that to the shortcode atts. |
129
|
1 |
|
if ( 0 !== absint( $post_ids ) && is_int( absint( $post_ids ) ) ) { |
130
|
1 |
|
return Shortcode\shortcode( [ 'gc_game' => $post_ids ] ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
// For all other cases, handle normally. We'll catch the issues later. |
134
|
|
|
return Shortcode\shortcode( [ 'gc_game' => $post_ids ] ); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Echoes a game or list of games. |
139
|
|
|
* |
140
|
|
|
* @since 1.1.0 |
141
|
|
|
* @param mixed $post_ids Can be a valid game post ID, an array of games, or a comma-separated list of games. |
142
|
|
|
*/ |
143
|
|
|
function gc_the_game( $post_ids = '' ) { |
144
|
|
|
echo gc_get_game( $post_ids ); // WPCS: XSS ok, already sanitized. |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get a list of attributes for the given post. Use instead of get_term_list. |
149
|
|
|
* |
150
|
|
|
* @since 1.0.0 |
151
|
|
|
* @param integer $post_id The post ID. If none is given, will attempt to grab one from the WP_Post object. |
152
|
|
|
* @param string $before Anything before the list of attributes. |
153
|
|
|
* @param string $seperator Seperator between attributes (default is ", "). |
154
|
|
|
* @param string $after Anything after the list of attributes. |
155
|
|
|
* @return string The sanitized list of attributes. |
156
|
|
|
*/ |
157
|
|
|
function gc_get_the_attribute_list( $post_id = 0, $before = '', $seperator = ', ', $after = '' ) { |
158
|
|
|
return Attributes\get_the_attribute_list( $post_id, $before, $seperator, $after ); |
159
|
|
|
} |
160
|
|
|
|