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
<?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' );
@kadimi
kadimi / sp_event_players_2d_positions.php
Last active February 6, 2019 08:01
Display event team players in a two dimensions matrix based on positions
<?php
/**
* Example Usage.
*/
add_action( 'sportspress_after_event_template', function( $elements ) {
$elements['performance']['action'] = function() {
sp_event_players_2d_positions(
[ 'team-1', 'team-2', 'team-3', 'team-4' ],
[ 'lead', 'second', 'third', 'skipper' ],
@kadimi
kadimi / wc_bookings_is_bookeable_product.php
Created December 5, 2018 10:49
WooCommere Bookings - Check if current page is a bookable product
<?php
/**
* WooCommere Bookings - Check if current page is a bookable product.
* @return boolean True for bookable products, false otherwise
*/
function is_bookable_product() {
return is_product() && wc_get_product() instanceof WC_Product_Booking;
}
@kadimi
kadimi / wc_bookings_get_booking_ids_by_product_id.php
Created December 4, 2018 14:56
WooCommerce Bookings - Get Bookings for Product
<?php
/**
* WooCommerce Bookings - Get Bookings for Product.
* @param int $product_id Product ID.
* @return array Bookings IDs.
*/
function wc_bookings_get_booking_ids_by_product_id( $product_id ) {
return WC_Booking_Data_Store::get_booking_ids_by( [
'object_id' => $product_id,
@kadimi
kadimi / video-to-animation.sh
Created November 30, 2018 09:42
Video (.mp4) to animation (.gif)
#!/bin/sh
## Cleanup
rm -f palette.png video.gif
## Make palette
# --ss stop at seconds
# --t duration
ffmpeg -ss 10 -t 4 -i video.mp4 -vf fps=15,scale=800:-1:flags=lanczos,palettegen palette.png
@kadimi
kadimi / ebay-filter-low-rated-sellers.js
Created September 5, 2018 19:42
Remove low rated sellers from ebay search with seller info
jQuery('.s-item__seller-info-text')
.filter(function() {
let s = $(this).text();
let re = /\((.*)\) (.*)%/g;
do {
m = re.exec(s);
if (m) {
feedback_score = parseInt(m[1].replace(',', ''));
positive_feedback = parseFloat(m[2]);
@kadimi
kadimi / sportspress-fix-offense-defense-stats.php
Last active October 14, 2022 14:34
Fix SportsPress player stats (offense/defense)
<?php
add_filter( 'sportspress_player_data_event_args', function( $args ) {
foreach ( $args[ 'meta_query' ] as &$m ) {
if ( true
&& is_array( $m )
&& array_key_exists( 'key', $m )
&& in_array($m[ 'key' ], [ 'sp_offense', 'sp_defense' ] )
) {
$m = null;
@kadimi
kadimi / bp-sportspress-label.php
Created June 23, 2018 10:12
BuddyPress Label for SportsPress
<?php
/*
Plugin Name: BuddyPress Label for SportsPress
Plugin URI: https://www.themeboy.com/sportspress-extensions/buddypress/
Description: Plugin allows changing the label of SportPress within BuddyPress pages, go to "SportsPress > Settings > Text" then scroll down to the latest option "SportsPress (BuddyPress)" and fill it with your choice.
Author: Nabil Kadimi - Support Engineer at ThemeBoy
Version: 1.0.0
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html