Skip to content

Instantly share code, notes, and snippets.

View kadimi's full-sized avatar
I love programming...

Nabil Kadimi kadimi

I love programming...
View GitHub Profile
@kadimi
kadimi / sp_hide_event_forms.php
Created February 25, 2020 17:43
Do not show user results and user scores forms if the main result is set
<?
/**
* Do not show user results and user scores forms if the main result is set.
*/
add_filter( 'sportspress_event_templates', function( $templates ) {
if ( sp_get_main_results( get_the_ID() ) ) {
unset( $templates[ 'user_results' ] );
unset( $templates[ 'user_scores' ] );
}
@kadimi
kadimi / showing-venue-without-events.php
Last active January 29, 2020 21:04
Force showing venue without events
<?php
/**
* Force showing venue without events.
*/
add_action( 'loop_no_results', function( $q ) {
/**
* Only once.
*/
@kadimi
kadimi / sp_create_player_lists.php
Last active December 4, 2019 10:46
Auto-create player lists in SportsPress
<?php
/**
* Auto-create player lists in SportsPress.
*
* This code will generate player lists for teams without one.
* It's useful if your SportsPress site has a lot of teams and you don't
* want to create player lists one by one.
*
* The code will only work when the parameter `sp_create_player_lists` is
@kadimi
kadimi / taxonomy-venue.php
Created August 29, 2019 15:29
Venue archive template
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
@kadimi
kadimi / archive-sp_event.php
Last active July 13, 2019 17:32
SportsPress events archive template using event blocks
<?php
/**
* The template for displaying archive pages.
*
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package Rookie
*/
get_header(); ?>
@kadimi
kadimi / playlist-dl.sh
Last active May 17, 2019 18:57
Download Playlist
youtube-dl -o '%(uploader)s - %(playlist)s/%(playlist_index)s - %(title)s.%(ext)s'
@kadimi
kadimi / sp_players_import_all__teams_current.php
Last active February 22, 2019 16:41
SportsPress - Make all teams current when importing players
<?php
/**
* Add this code to your website, I recommend adding it using the plugin Code Snippets.
* Disable or delete the snippet as soon as you finish importing players.
* `$treshold_in_seconds` should be a little higher than the import duration in seconds.
*
* @author Nabil Kadimi
* @link https://themeboy.com
*/
<?php
/**
* Get player performance for event.
*
* @param int $player_id Player ID.
* @param int $team_id Team ID.
* @param int $event_id Event ID.
* @return array|false Array of player performance or false
* if one of the parameters is not valid.
<?php
// Add this code to your custom template event-results.php, after $data has been filled
$orderBy = 'goals';
$order = 'ASC'; // Or DESC
uasort( $data, function( $a, $b ) use ( $orderBy, $order ) {
return $order === 'DESC'
? $a[ $orderBy ] < $b [ $orderBy ]
@kadimi
kadimi / sp_event_list_players_by_position.php
Last active December 17, 2018 16:22
Add a column in event lists showing players by position
<?php
/**
* Example Usage.
*/
sp_event_list_players_by_position( 'team-1', 'Team 1' );
sp_event_list_players_by_position( 'team-2', 'Team 2' );
sp_event_list_players_by_position( 'team-3', 'Team 3' );
sp_event_list_players_by_position( 'team-4', 'Team 4' );