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 / sportspress_filter_player_profile_events.php
Created April 30, 2024 14:16
SportsPress: on player profiles, show current season and league events only
<?php
add_filter( 'sp_player_events_list_args', function( $args ) {
$args[ 'league' ] = get_option( 'sportspress_league', false );
$args[ 'season' ] = get_option( 'sportspress_season', false );
return $args;
} );
@kadimi
kadimi / sportspress_fix_ical_line_breaks.php
Last active April 28, 2024 18:57
SportsPress: Replace line breaks with `\n` in iCal feeds
<?php
add_filter('posts_results', function($posts, $query) {
if (empty($_GET['feed']) || $_GET['feed'] !== 'sp-ical') {
return $posts;
}
foreach ($posts as &$post) {
$post->post_content = preg_replace("/\r?\n/", "\\n", $post->post_content);
}
return $posts;
@kadimi
kadimi / sportspress_regenerate_event_titles.php
Last active March 18, 2024 01:58
SportsPress: Regenerate Event Titles
<?php
/**
* Add bulk action to re-assign SportsPress events titles.
*/
add_filter('bulk_actions-edit-sp_event', fn ($actions) => $actions + ['sp_regenerate_title' => 'Regenerate Title']);
add_filter('handle_bulk_actions-edit-sp_event', function ($redirect_to, $action, $post_ids) {
if ($action !== 'sp_regenerate_title') {
return $redirect_to;
@kadimi
kadimi / sportspress_duplicated_variables.php
Last active March 24, 2024 21:58
SportsPress: Find duplicated variable/key instances
<?php
if (!empty($_GET['sportspress_debug'])) {
add_action('init', function () {
$all = [];
foreach ([
'sp_outcome',
'sp_result',
'sp_performance',
@kadimi
kadimi / event-timeline-vertical.php
Created November 12, 2023 23:22
SportsPress - Timeline Fix
<?php
/**
* Custom sorting function for timeline elements.
*
*
* ## The Problem
*
* When many timeline elements have the same minute(e.g, a goal and an assist
* both at 33'), they're thrown on the timeline in a random order are sorted.
@kadimi
kadimi / sp_get_event_tournaments_with_example.php
Created April 15, 2023 00:16
Add links to tournaments on events
<?php
function sp_get_event_tournaments($event_id)
{
return get_posts([
'post_type' => 'sp_tournament',
'posts_per_page' => -1,
'meta_query' => [
[
'key' => 'sp_event',
@kadimi
kadimi / sp_get_players_by_team.php
Created April 11, 2023 17:46
SportsPress - Get Players by Team
<?php
function sp_get_players_by_team($team, $current_or_past_or_all = 'all')
{
switch ($current_or_past_or_all) {
case 'current':
$team_key = 'sp_current_team';
break;
case 'past':
$team_key = 'sp_past_team';
@kadimi
kadimi / sportspress-add-player-list-automatically.php
Last active March 24, 2023 13:16
For SportsPress - Add a player list on the fly to the current team.
<?php
/**
* Add a player list on the fly to the current team.
*/
add_action(
'init',
function () {
/**
@kadimi
kadimi / sportspress-custom-past-events-list-columns.php
Created January 29, 2023 18:49
SportsPress - Customize past events list columns
<?php
/**
* Customize past events list columns.
*/
add_action( 'init', function() {
/**
* Desired columns.
*
@kadimi
kadimi / sportspress-translate-read-more.php
Created October 5, 2022 13:44
SportsPress - Translate "Read more..."
<?php
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
if ( 'mega-slider' === $domain ) {
if ( 'Read more...' === $text ) {
return 'YOUR TEXT HERE';
}
}
return $translated_text;
}, 10, 3 );