Hi Antoine,
Here is the hide-zero-predictions.php file i have installed. I would appreciate your help when you can. Thanks.
<?php
/**
* Plugin Name: Football Pool Match Predictions Extension
* Description: Order match predictions by score and don’t show users without predictions.
* Version: 1.0
* Author: Antoine Hurkmans
* Author URI: mailto:wordpressfootballpool@gmail.com
* License: MIT
*/
// Save this plugin in the wp-content/plugins folder and activate it //
class FootballPoolExtensionMatchPredictions {
public static function init_extension() {
if ( ! is_admin() ) {
add_filter( ‘footballpool_statistics_matchpredictions’, array( __CLASS__, ‘change_matchpredictions’ ), null, 2 );
}
}
public static function change_matchpredictions( $predictions, $match_info ) {
// add score
array_walk( $predictions, array( __CLASS__, ‘add_score’ ), $match_info );
// remove users without predictions
$predictions = array_filter( $predictions, array( __CLASS__, ‘remove_inactive_users’ ) );
// sort by score
usort( $predictions, array( __CLASS__, ‘sort_table’ ) );
return $predictions;
}
public static function add_score( &$prediction, $key, $match_info ) {
$pool = new Football_Pool_Pool;
$prediction[‘score’] = $pool->calc_score(
$match_info[‘home_score’],
$match_info[‘away_score’],
$prediction[‘home_score’],
$prediction[‘away_score’],
$prediction[‘has_joker’]
);
}
public static function remove_inactive_users( $prediction ) {
return ! is_null( $prediction[‘home_score’] ) && ! is_null( $prediction[‘away_score’] );
}
public static function sort_table( $a, $b ) {
if ( $a[‘score’] == $b[‘score’] ) return 0;
return ( $a[‘score’] < $b[‘score’] ) ? 1 : -1;
}
}
add_filter( ‘plugins_loaded’, array( ‘FootballPoolExtensionMatchPredictions’, ‘init_extension’ ) );