Actions & Filters

Several actions and filters are available to allow customization of a number of features as described in the following paragraphs.

mstw_lm_percent_calc

Win percentage is calculated by the fairly standard formula:

win_percent = ( wins + 0.5 * ties ) / games_played

This filter may be used to change this calculation. The skeleton of the required code is:

add_filter( 'mstw_lm_percent_calc', 'my_percent_calc', 10, 2 );

function my_percent_calc( $percent, $record ) {
   // $percent is the win percentage calculated with the formula above
   // $record is an array which includes the elements:
   // $record['wins'], $record['losses'], $record['ties'], $record['ot_wins'], $record['ot_losses']

   // $new_win_percent = your win percentage calculation (code defensively: check for existence, type, value!)
   
   // it is very important to return the new win percentage!!
   return $new_win_percent;
}

mstw_lm_points_calc

Points are calculated using the points rules defined in the plugin’s Settings admin screen based on the league’s sport (not the league).

This filter may be used to change this calculation. The skeleton of the required code is:

add_filter( 'mstw_lm_points_calc', 'my_points_calc', 10, 2 );

function my_points_calc( $points, $record ) {
   // $points is the points calculated from the sport's points rules
   // $record is an array which includes the elements:
   // $record['wins'], $record['losses'], $record['ties'], $record['ot_wins'], $record['ot_losses']

   // $new_points = your points calculation (code defensively: check for existence, type, value!)
   
   // it is very important to return the new points!!
   return $new_points;
}

mstw_lm_sports_list

The plugin provides an extensive list of American sports, but suppose a site simply must have Gaelic Hurling with its complex ranking system. What’s a site admin to do? Use the mstw_lm_sports_list filter to add Gaelic Hurling, or whatever sports are desired. The skeleton of the required code is:

add_filter( 'mstw_lm_sports_list', 'my_sports_list', 10, 1 );

function my_sports_list( $sports_list ) {
	
   $sports_list['hurling'] = 'Gaelic Hurling';

   natsort( $sports_list );
	
   return $sports_list;
	
}

Note that sports may also be removed from the list using this filter.

mstw_lm_sports_abbrevs

This filter is used to customize the short name of sports. It is useful when using schedule “tickers” to reduce the sports name sizes, and should be used in parallel with mstw_lm_sports_list whenever that filter is used. The skeleton of the required code is:

add_filter( 'mstw_lm_sports_abbrevs', 'my_sports_abbrevs', 10, 1 );

function my_sports_abbrevs( $abbrevs_list ) {
	
   'basketball-boys'  => 'Boys BB',
   'basketball-girls' => 'Girls BB',

   natsort( $abbrevs_list);
	
   return $abbrevs_list;
	
}

Abbrevs may be added when a sport is added.

mstw_lm_tbd_list

For games without a start time, the plugin provides a list of abbreviations for “To Be Determined” or “To Be Announced”. These abbreviations are “internationalized”. Should you wish to add additional abbreviations, the skeleton of the required code is provided below:

add_filter( 'mstw_lm_tbd_list', 'my_tbd_list', 10, 1 );

function my_tbd_list( $the_tbd_list ) {

   $the_tbd_list['XYZZY'] = 'xyzzy',	

   return $the_tbd_list;
	
}

Note that the the readable (displayed) name is the key, and the slug is the value.

mstw_lm_date_formats

The plugin provides a list of date formats, admittedly geared toward American formats. The list can be expanded or changed via this filter. The skeleton of the required code is:

add_filter( 'mstw_lm_date_formats', 'my_date_formats', 10, 1 );

function my_date_formats( $date_formats ) {

   // This crazy format is just an example
   $date_formats['Tuesday, 2013-04-07'] = 'l, Y-m-d',	

   return $sports_list;
	
}

Note that the array uses the readable (displayed) name as the key and the PHP date format string as the value. Any valid PHP date format should work. (I haven’t tested every possible string.)

mstw_lm_time_formats

The plugin provides a list of time formats, , admittedly geared toward American formats. The list can be expanded or changed via this filter. The skeleton of the required code is the same as shown for the mstw_lm_date_formats filter shown above.

mstw_lm_no_media_message

This filter is used to customize the the message when no media is found. It is useful to ‘re-purpose’ the Media column of Schedule Tables for other uses. The skeleton of the required code is:

add_filter( 'mstw_lm_no_media_message', 'my_message', 10, 1 );

function my_message( $message ) {
	
   return "My no media message";
	
}

mstw_lm_no_location_message

This filter is used to customize the the message when no location/venue is found for a game. The skeleton of the required code is:

add_filter( 'mstw_lm_no_location_message', 'my_message', 10, 1 );

function my_message( $message ) {
	
   return "My no location message";
	
}