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_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 / 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 / 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 / wp-cli-install.sh
Last active October 29, 2023 06:46
Install WordPress with WP-CLI (for Scotch Box)
# CD to the document root.
cd /var/www/public/
# Update WP-CLI if needed.
sudo wp cli update --allow-root --yes
# Download WordPress if needed.
wp core download
# Create configuration file.
@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 / detect_remote_change.js
Last active August 7, 2023 14:33
Sometimes I need the "change" event to be triggered even when elements that are not changed directly by the user, this works good so far.
var t = 200; // The interval at which new change ares detected
jQuery( document ).ready( function() {
// Detect remote change
$( 'input, textarea' ).each( function() {
var $this = $( this );
$this.data( 'value', $this.val() );
setInterval( function() {
if( $this.val() !== $this.data( 'value' ) ) {
// Do not trigger if element does not have focus
@kadimi
kadimi / toggle-attr.js
Last active August 7, 2023 14:33 — forked from mathiasbynens/toggleAttr() jQuery plugin
Toggle checked, selected, disabled, checked, readonly, multiple, etc…
/**
* toggleAttr() jQuery Plugin
*
* Toggle checked, selected, disabled, checked, readonly, multiple, etc…
*/
jQuery.fn.toggleAttr = function (attr) {
return this.each(function () {
var $this = $(this);
if ($this.attr(attr)) {
$this.removeAttr(attr);
@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;
}