| 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__ . '\\specific_number_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 if a game only allows a specific number. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  * @since  1.2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  * @param  int    $game_id         The game's post ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  * @param  array  $players_min_max The minimum and maximum number of players. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  * @param  string $output          The player output. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  * @return string                  The filtered output. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  |  */ | 
            
                                                        
            
                                    
            
            
                | 57 |  |  | function specific_number_of_players( $game_id, $players_min_max, $output ) { | 
            
                                                        
            
                                    
            
            
                | 58 | 3 |  | 	if ( absint( $players_min_max['min'] ) === absint( $players_min_max['max'] ) ) { | 
            
                                                        
            
                                    
            
            
                | 59 |  |  | 		ob_start(); ?> | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 61 |  |  | 		<span class="gc-icon icon-game-players"><?php Display\the_svg( 'players', false ); ?></span><span class="game-num-players" id="game-<?php echo absint( $game_id ); ?>-num-players"> | 
            
                                                        
            
                                    
            
            
                | 62 |  |  | 		<?php | 
            
                                                        
            
                                    
            
            
                | 63 | 1 |  | 		echo 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 | 1 |  | 		</span> | 
            
                                                        
            
                                    
            
            
                | 70 |  |  | 		<?php | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 72 | 1 |  | 		$output = ob_get_clean(); | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 75 | 3 |  | 	return $output; | 
            
                                                        
            
                                    
            
            
                | 76 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  |