Page 1 of 1

Clubs, die nicht automatisch in Übereinstimmungen zugewiesen wurden, die von WPForms im Sportssprid -Plugin erstellt wur

Posted: 25 Jan 2025, 15:27
by Guest
Ich arbeite an einer WordPress -Site mit dem SportSpress -Plugin und dem WPForms. Ich habe ein Formular mit WPForms erstellt, das Kontrollkästchen enthält, die mit allen vorhandenen Clubs besiedelt sind, und ein Dropdown-Menü für die Anzahl der Beine (1-2). Wenn das Formular eingereicht wird, wird eine Round-Robin-Liga erstellt und für die Liga Spiele erzeugt. Hier ist der relevante Teil meiner Funktionen.php: < /p>

Code: Select all

function create_sportspress_club_for_new_user($user_id) {
// Get the user data
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
$profile_picture = get_user_meta($user_id, 'profile_photo', true);

// Create a new club in SportsPress
$club_id = wp_insert_post(array(
'post_title' => $username,
'post_type' => 'sp_team',
'post_status' => 'publish',
));

if (is_wp_error($club_id)) {
return;
}

if ($club_id) {
// Set the club profile picture
if ($profile_picture) {
$attachment_id = media_sideload_image($profile_picture, $club_id, null, 'id');
if (!is_wp_error($attachment_id)) {
set_post_thumbnail($club_id, $attachment_id);
}
}
// Assign the club to the user
update_user_meta($user_id, 'sp_team', $club_id);

// Assign the user to the club in SportsPress settings
update_post_meta($club_id, 'sp_team_manager', $user_id);

// Ensure the user is added to the correct taxonomy terms if needed
wp_set_object_terms($club_id, $user_id, 'sp_team_manager');

// Add the new club to the sportspress_league_menu_teams option
$teams = get_option('sportspress_league_menu_teams', array());
if (!is_array($teams)) {
$teams = array();
}
$teams[] = $club_id;
update_option('sportspress_league_menu_teams', $teams);
}
}

function create_matches_for_schedule($schedule) {
foreach ($schedule as $match) {
$home_club_id = intval($match[0]);
$away_club_id = intval($match[1]);

// Debugging: Log the IDs being used and their types
error_log("Home Club ID: $home_club_id (Type: " . gettype($home_club_id) . "), Away Club ID: $away_club_id (Type: " . gettype($away_club_id) . ")");

// Ensure the IDs are integers
if (!is_int($home_club_id) || !is_int($away_club_id)) {
error_log("Error: Club IDs are not integers. Home Club ID: $home_club_id, Away Club ID: $away_club_id");
continue;
}

// Fetch team names using their IDs
$home_club_name = get_the_title($home_club_id);
$away_club_name = get_the_title($away_club_id);

// Debugging: Ensure club names are correct
error_log("Home Club Name: $home_club_name, Away Club Name: $away_club_name");

// Check if the club names are valid
if (empty($home_club_name) || empty($away_club_name)) {
error_log("Error: Invalid club names. Home Club Name: $home_club_name, Away Club Name: $away_club_name");
continue;
}

// Create a new match in SportsPress
$match_id = wp_insert_post(array(
'post_title' => "$home_club_name vs $away_club_name",
'post_type' => 'sp_event',
'post_status' => 'publish',
'meta_input' => array(
'sp_team_home' => $home_club_id,
'sp_team_away' => $away_club_id,
),
));
}
}
< /code>
Hier ist mein Debugg.log: < /p>
[24-Jan-2025 07:17:59 UTC] Selected clubs: Array
(
[0] => mika
[1] => Yoyo FC
)

[24-Jan-2025 07:17:59 UTC] Number of legs: 1
[24-Jan-2025 07:17:59 UTC] Club IDs: Array
(
[0] => 1080
[1] => 329
)

[24-Jan-2025 07:17:59 UTC] Generated schedule: Array
(
[0] => Array
(
[0] => 1080
[1] => 329
)

)

[24-Jan-2025 07:17:59 UTC] Home Club ID: 1080 (Type: integer), Away Club ID: 329 (Type: integer)
[24-Jan-2025 07:17:59 UTC] Home Club Name: mika, Away Club Name: Yoyo FC

Die Formularübermittlung löst eine Funktion zum Erstellen von Spielen für die Liga aus. Das Problem besteht jedoch darin, dass der Vereinsbereich des „x vs y“-Spiels leer ist, obwohl ich die Vereine manuell über die wp-admin-Benutzeroberfläche zuweisen kann.
Wie kann ich Änderungen vornehmen? die Funktion, die ausgewählten Vereine automatisch den Spielen zuzuordnen, wenn sie erstellt werden?
Für Hinweise oder Vorschläge wären wir sehr dankbar. Danke!