Recently we are doing a project that's including Wordpress as platform, and LeagueManager plugin for displaying league/season/team info and management. One of the problems that surfaced along the way was not enough custom fields in the team info screen. So after combing the internet for solution, we decided to edit the plugin so it can accept some more info than intended originally.In this attempt we will be introducing one new field labeled 'Test' in the Team screen.

So, first thing what we need to do is to add new text input tag to leaguemanager/admin/team.php. I’ve decided to have ‘Test’ field be placed directly bellow the ‘Coach’ input, so here’s the code from team.php file.

[html title=“Starting from line 80″]
<input id=“coach“ type=“text“ name=“coach“ value=“<?php echo $team->coach ?>“ size=“40″ />
<!– this is what we inserted –>
<input id=“test“ type=“text“ name=“test“ value=“<?php echo $team->test ?>“ size=“40″ />
<!– /this is what we inserted –>
<input type=“text“ name=“stadium“ value=“<?php echo $team->stadium ?>“ size=“50″ />

Notice the PHP code in the input‘s value attribute? That line fetch’s the current value in the database and places it in there, if it is generally set.
So, next thing – this form submits somewhere, and data needs to be processed. If you refer to form’s action attribute, you can learn that it will send data via POST method, but there is some info sent via GET as well. So, after little research, we should edit the show-league.php file, and alter line 14 to have it pick up our data from ‘Test’ field. To achieve that, we add $_POST['test'], so the code corresponds:

[php title=“Line 14 of the show-league.php file“]
$this->editTeam( $_POST[‘team_id’], $_POST[‘team’], $_POST[‘website’], $_POST[‘coach’], $_POST[‘test’], $_POST[‘stadium’], $home, $group, $roster, $custom, $_POST[‘logo_db’], $del_logo, $overwrite_image );

After this, we need to edit the editTeam() method that is part of the LeagueManager class. Along with that, there are few more methods that need to be altered: addTeam() and addTeamFromDB().

First things first, lets edit admin.php line 718, so we introduce our field to the SQL query that’s being built:

[php title=“Line 718 of the admin.php file“]
$wpdb->query( $wpdb->prepare ( „UPDATE {$wpdb->leaguemanager_teams} SET `title` = ‘%s’, `website` = ‘%s’, `coach` = ‘%s’, `test`=’%s’, `stadium` = ‘%s’, `logo` = ‘%s’, `home` = ‘%d’, `group` = ‘%s’, `roster`= ‘%s’, `custom` = ‘%s’ WHERE `id` = %d“, $title, $website, $coach, $test, $stadium, $logo, $home, $group, maybe_serialize($roster), maybe_serialize($custom), $team_id ) );

and after that on line 690

$team = $wpdb->get_results( „SELECT `league_id`, `title`, `website`, `coach`, `test`, `stadium`, `home`, `group`, `roster`, `logo`, `custom` FROM {$wpdb->leaguemanager_teams} WHERE `id` = {$team_id}“ );

and finally on line 659

$sql = „INSERT INTO {$wpdb->leaguemanager_teams} (`title`, `website`, `coach`, `test`, `stadium`, `home`, `group`, `roster`, `season`, `custom`, `logo`, `league_id`) VALUES (‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%d’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%s’, ‘%d’)“;
$wpdb->query( $wpdb->prepare ( $sql, $title, $website, $coach, $test, $stadium, $home, $group, maybe_serialize($roster), $season, maybe_serialize($custom), $logo, $league_id ) );

By now, we’ve covered the insertation of the fields. If you need any tweaks for displaying, you should address the core.php‘s methods: getTeam(), getTeams()

Jovan Ivezic

E-business and internet marketing specialist.