contact from 7 data

PHOTO EMBED

Thu Dec 19 2024 23:42:17 GMT+0000 (Coordinated Universal Time)

Saved by @BilalRaza12

add_action('wpcf7_mail_sent', 'save_cf7_form_data');

function save_cf7_form_data($contact_form) {
    global $wpdb;

    $form_id = $contact_form->id();
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $form_data = $submission->get_posted_data();
        $table_name = 'wpyy_cf7_submissions'; // Use your custom table name directly

        $wpdb->insert(
            $table_name,
            [
                'form_id' => $form_id,
                'form_data' => maybe_serialize($form_data),
            ],
            [
                '%d',
                '%s'
            ]
        );
    }
}


add_action('wpcf7_mail_sent', 'add_submission_to_layout');


function add_submission_to_layout($contact_form) {
    global $wpdb;

    // Get form data
    $submission = WPCF7_Submission::get_instance();
    if ($submission) {
        $data = $submission->get_posted_data();

        // Define variables for all fields
        $name = isset($data['Full-name']) ? $data['Full-name'] : 'Unknown';
        $sport = isset($data['Sport']) ? $data['Sport'] : 'Unknown';
        $email_address = isset($data['Email-address']) ? $data['Email-address'] : 'Unknown';
        $phone_Number = isset($data['Phone-Number']) ? $data['Phone-Number'] : 'Unknown';
        $nick_name = isset($data['Nick-name']) ? $data['Nick-name'] : 'Unknown';
        $player_number = isset($data['Player-Number']) ? $data['Player-Number'] : 'Unknown';
        $graduation_year = isset($data['Graduation-year']) ? $data['Graduation-year'] : 'Unknown';
        $team_club = isset($data['Team-club']) ? $data['Team-club'] : 'Unknown';
        $years_playing = isset($data['Years-playing']) ? $data['Years-playing'] : 'Unknown';
        $stats = isset($data['Stats']) ? $data['Stats'] : 'Unknown';
        $positions = isset($data['Positions']) ? $data['Positions'] : 'Unknown';
        $awards_achievements = isset($data['Awards-Achievements']) ? $data['Awards-Achievements'] : 'Unknown';
        $tiktok_link = isset($data['Tiktok-link']) ? $data['Tiktok-link'] : 'Unknown';
        $instagram_link = isset($data['Instagram-link']) ? $data['Instagram-link'] : 'Unknown';  
        $twitter_link = isset($data['Twitter-link']) ? $data['Twitter-link'] : 'Unknown';
        $imlca_link = isset($data['IMLCA-link']) ? $data['IMLCA-link'] : 'Unknown';
        $youtube_link = isset($data['YouTube-link']) ? $data['YouTube-link'] : 'Unknown';
        $file_id = isset($data['file-upload']) ? $data['file-upload'] : '';
        $dominant_hand = isset($data['hand-dominance']) ? $data['hand-dominance'] : 'Unknown'; 
        if (isset($_POST['hand-dominance'])) {
        $dominant_hand = sanitize_text_field($_POST['hand-dominance']); // Sanitize the input
        }
        $file_url = 'https://sportmeid.com/wp-content/uploads/2024/12/player-profile.webp'; 
        if (!empty($_FILES['file-upload']['name'])) {
            $file = $_FILES['file-upload'];
            $upload_dir = wp_upload_dir();
            $file_path = $upload_dir['path'] . '/' . basename($file['name']);
            move_uploaded_file($file['tmp_name'], $file_path);

            $attachment = array(
                'guid' => $upload_dir['url'] . '/' . basename($file['name']),
                'post_mime_type' => mime_content_type($file_path),
                'post_title' => preg_replace('/\.[^.]+$/', '', basename($file['name'])),
                'post_content' => '',
                'post_status' => 'inherit'
            );

            $attachment_id = wp_insert_attachment($attachment, $file_path);
            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $attachment_metadata = wp_generate_attachment_metadata($attachment_id, $file_path);
            wp_update_attachment_metadata($attachment_id, $attachment_metadata);

            $file_url = wp_get_attachment_url($attachment_id);
        }

        $player_id = uniqid();

        $new_entry = '<a href="' . site_url('/player-detail?id=' . $player_id) . '" >';
        $new_entry .= '<div class="player-card" data-name="' . esc_attr($name) . '" data-sport="' . esc_attr($sport) . '">';
        $new_entry .= '<div class="player-image">';
        $new_entry .= '<img src="' . esc_url($file_url) . '" alt="' . esc_attr($name) . '" class="player-image">';
        $new_entry .= '</div>'; 
        $new_entry .= '<div class="player-card-name">';
        $new_entry .= '<p>Name: ' . esc_html($name) . '</p>';
        $new_entry .= '<p>Sport: ' . esc_html($sport) . '</p>';
        $new_entry .= '<div class="player-image-button">';
        $new_entry .= '</div>';
        $new_entry .= '</div>';
        $new_entry .= '</div>';
        $new_entry .= '</a>';

        $existing_data = get_option('players_data', []);
        $existing_data[$player_id] = array(
            'name' => $name,
            'sport' => $sport,
            'email_address' => $email_address,
            'phone_Number' => $phone_Number,
            'nick_name' => $nick_name,
            'player_number' => $player_number,
            'graduation_year' => $graduation_year,
            'team_club' => $team_club,
            'years_playing' => $years_playing,
            'positions' => $positions,
            'dominant_hand' => $dominant_hand,
            'stats' => $stats,
            'awards_achievements' => $awards_achievements,
            'tiktok_link' => $tiktok_link,
            'instagram_link' => $instagram_link,
            'twitter_link' => $twitter_link,
            'youtube_link' =>  $youtube_link,
            'imlca_link' =>   $imlca_link,
            'file_url' => $file_url
        );

        update_option('players_data', $existing_data);

        $existing_layout = get_option('players_layout', []);
        $existing_layout[] = $new_entry;
        update_option('players_layout', $existing_layout);
    }
}


function render_players_layout() {
    $layout = get_option('players_layout', []);

    if (!empty($layout)) {
        $output = '<div class="players-pof-col">';
        $counter = 0;

        foreach ($layout as $entry) {
            $output .= $entry;

            $counter++;
            if ($counter % -1 === 0) {
                $output .= '</div><div class="players-pof-col">';
            }
        }

        $output .= '</div>';
        echo $output;
    } else {
        echo '<p>No players data found.</p>';
    }
}
function delete_form_submission() {
    if (isset($_GET['delete_submission']) && isset($_GET['entry_id'])) {
        $submission_id = intval($_GET['entry_id']);
        if (is_user_logged_in() && user_can(current_user(), 'delete_posts')) {
            global $wpdb;

            $wpdb->delete($wpdb->prefix . 'flamingo_inbound_messages', array('id' => $submission_id));
        }
    }
}
add_action('wp', 'delete_form_submission');



add_shortcode('players_layout', 'render_players_layout');


add_action('template_redirect', 'handle_player_detail_page');

function handle_player_detail_page() {
    if (isset($_GET['id']) && is_page('player-detail')) {
        $player_id = sanitize_text_field($_GET['id']);
        $players_data = get_option('players_data', []);

        if (isset($players_data[$player_id])) {
            $player = $players_data[$player_id];

            // Display player detail page
            include get_template_directory() . '/player-detail-template.php';
            exit; // Prevent further processing
        } else {
            wp_die('Player not found.');
        }
    }
}


add_filter('wpcf7_form_tag', 'set_default_dropdown_value', 10, 2);

function set_default_dropdown_value($tag, $unused) {
    if ($tag['name'] === 'hand-dominance') {
        $submitted_value = isset($_POST['hand-dominance']) ? $_POST['hand-dominance'] : '';
        foreach ($tag['raw_values'] as &$value) {
            if ($value === $submitted_value) {
                $value = $value . ' default:1';
            }
        }
    }
    return $tag;
}


function sports_textarea_field() {
    ob_start();
    ?>
    <div id="sports-wrapper" class="text-fild">
        <textarea id="sports-textarea" name="Sport" class="auto-height" placeholder="Sports will be shown here..." readonly></textarea>
        <div id="sports-input-wrapper" class="add-text-input" style="display: none;">
            <input type="text" id="sports-input" placeholder="Enter sport here..." />
        </div>
        <p id="sports-warning-message" style="color: blue; display: none; margin-top: 10px;"></p> <!-- Warning message -->
        <div class="add-buttons">
            <button type="button" id="sports-add-save-button">Add</button>
            <button type="button" id="sports-delete-last-button" style="display: none;">Delete Last</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const textarea = document.getElementById('sports-textarea');
            const addSaveButton = document.getElementById('sports-add-save-button');
            const deleteButton = document.getElementById('sports-delete-last-button');
            const inputWrapper = document.getElementById('sports-input-wrapper');
            const sportsInput = document.getElementById('sports-input');
            const warningMessage = document.getElementById('sports-warning-message');
            let sportsCounter = 1; 

            function toggleDeleteButton() {
                if (textarea.value.trim() === '') {
                    deleteButton.style.display = 'none';
                } else {
                    deleteButton.style.display = 'block';
                }
            }

            function showWarning(message) {
                warningMessage.textContent = message;
                warningMessage.style.display = 'block';
            }

            function hideWarning() {
                warningMessage.textContent = '';
                warningMessage.style.display = 'none';
            }

            function autoGrowTextarea() {
                textarea.style.height = 'auto'; 
                textarea.style.height = textarea.scrollHeight + 'px'; // Corrected height adjustment
            }

            addSaveButton.addEventListener('click', function () {
                hideWarning(); 
                if (addSaveButton.textContent === 'Add') {
                    inputWrapper.style.display = 'block';
                    sportsInput.focus();
                    addSaveButton.textContent = 'Save';
                } else if (addSaveButton.textContent === 'Save') {
                    const newSport = sportsInput.value.trim();
                    if (newSport) {
                        const currentValue = textarea.value;
                        const newSportText = `Sport ${sportsCounter}: ${newSport}`;
                        textarea.value = currentValue
                            ? currentValue + '\n' + newSportText
                            : newSportText;
                        sportsInput.value = ''; 
                        sportsCounter++; 
                        inputWrapper.style.display = 'none'; 
                        addSaveButton.textContent = 'Add'; 
                        toggleDeleteButton(); 
                        autoGrowTextarea(); // Adjust height after adding new content
                    } else {
                        showWarning("Please enter a sport before saving.");
                    }
                }
            });

            deleteButton.addEventListener('click', function () {
                hideWarning(); 
                const sports = textarea.value.split('\n');
                if (sports.length === 0 || textarea.value.trim() === '') {
                    showWarning("No sports to delete.");
                    return;
                }
                sports.pop(); 
                textarea.value = sports.join('\n'); 
                sportsCounter--; 
                toggleDeleteButton(); 
                autoGrowTextarea(); // Adjust height after deleting content
            });

            textarea.addEventListener('input', autoGrowTextarea); // Adjust height on user input

            toggleDeleteButton();
            autoGrowTextarea(); // Initialize height adjustment
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('sports_field', 'sports_textarea_field');


function positions_textarea_field() {
    ob_start();
    ?>
    <div id="positions-wrapper" class="text-fild">
        <textarea id="positions-textarea" name="Positions" class="auto-height" placeholder="Positions will be shown here..." readonly></textarea>
        <div id="positions-input-wrapper" class="add-text-input" style="display: none;">
            <input type="text" id="positions-input" placeholder="Enter position here..." />
        </div>
        <p id="positions-warning-message" style="color: red; display: none; margin-top: 10px;"></p> <!-- Warning message -->
        <div class="add-buttons">
            <button type="button" id="positions-add-save-button">Add</button>
            <button type="button" id="positions-delete-last-button" style="display: none;">Delete Last</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const textarea = document.getElementById('positions-textarea');
            const addSaveButton = document.getElementById('positions-add-save-button');
            const deleteButton = document.getElementById('positions-delete-last-button');
            const inputWrapper = document.getElementById('positions-input-wrapper');
            const positionInput = document.getElementById('positions-input');
            const warningMessage = document.getElementById('positions-warning-message');
            let positionCounter = 1; 

            function toggleDeleteButton() {
                if (textarea.value.trim() === '') {
                    deleteButton.style.display = 'none';
                } else {
                    deleteButton.style.display = 'block';
                }
            }

            function showWarning(message) {
                warningMessage.textContent = message;
                warningMessage.style.display = 'block';
            }

            function hideWarning() {
                warningMessage.textContent = '';
                warningMessage.style.display = 'none';
            }

            function autoGrowTextarea() {
                textarea.style.height = 'auto'; // Reset height to calculate new scrollHeight
                textarea.style.height = textarea.scrollHeight + 'px';
            }

            addSaveButton.addEventListener('click', function () {
                hideWarning(); 
                if (addSaveButton.textContent === 'Add') {
                    inputWrapper.style.display = 'block';
                    positionInput.focus();
                    addSaveButton.textContent = 'Save';
                } else if (addSaveButton.textContent === 'Save') {
                    const newPosition = positionInput.value.trim();
                    if (newPosition) {
                        const currentValue = textarea.value;
                        const newPositionText = `Position ${positionCounter}: ${newPosition}`;
                        textarea.value = currentValue
                            ? currentValue + '\n' + newPositionText
                            : newPositionText;
                        positionInput.value = ''; 
                        positionCounter++; 
                        inputWrapper.style.display = 'none'; 
                        addSaveButton.textContent = 'Add'; 
                        toggleDeleteButton(); 
                        autoGrowTextarea(); // Adjust height after adding new content
                    } else {
                        showWarning("Please enter a position before saving.");
                    }
                }
            });

            deleteButton.addEventListener('click', function () {
                hideWarning(); 
                const positions = textarea.value.split('\n');
                if (positions.length === 0 || textarea.value.trim() === '') {
                    showWarning("No positions to delete.");
                    return;
                }
                positions.pop(); 
                textarea.value = positions.join('\n'); 
                positionCounter--; 
                toggleDeleteButton(); 
                autoGrowTextarea(); // Adjust height after deleting content
            });

            textarea.addEventListener('input', autoGrowTextarea); // Adjust height on user input

            toggleDeleteButton();
            autoGrowTextarea(); // Initialize height adjustment
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('positions_field', 'positions_textarea_field');

function stats_textarea_field() {
    ob_start();
    ?>
    <div id="stats-wrapper" class="text-fild">
        <textarea id="stats-textarea" name="Stats" placeholder="Stats will be shown here..." readonly></textarea>
        <div id="input-wrapper" class="add-text-input" style="display: none;">
            <input type="text" id="stats-input" placeholder="Enter stats here..." />
        </div>
        <p id="warning-message" style="color: #fff; display: none; margin-top: 10px;"></p> <!-- Warning message -->
        <div class="add-buttons">
            <button type="button" id="add-save-stats">Add</button>
            <button type="button" id="delete-last-stats" style="display: none;">Delete Last</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const textarea = document.getElementById('stats-textarea');
            const addSaveButton = document.getElementById('add-save-stats');
            const deleteButton = document.getElementById('delete-last-stats');
            const inputWrapper = document.getElementById('input-wrapper');
            const statsInput = document.getElementById('stats-input');
            const warningMessage = document.getElementById('warning-message');
            let statsCounter = 1; 
            
            function toggleDeleteButton() {
                if (textarea.value.trim() === '') {
                    deleteButton.style.display = 'none';
                } else {
                    deleteButton.style.display = 'block';
                }
            }

            function showWarning(message) {
                warningMessage.textContent = message;
                warningMessage.style.display = 'block';
            }

            function hideWarning() {
                warningMessage.textContent = '';
                warningMessage.style.display = 'none';
            }

            function autoGrowTextarea() {
                textarea.style.height = 'auto'; // Reset height to calculate new scrollHeight
                textarea.style.height = textarea.scrollHeight + 'px';
            }

            addSaveButton.addEventListener('click', function () {
                hideWarning(); 
                if (addSaveButton.textContent === 'Add') {
                    inputWrapper.style.display = 'block';
                    statsInput.focus();
                    addSaveButton.textContent = 'Save';
                } else if (addSaveButton.textContent === 'Save') {
                    const newStats = statsInput.value.trim();
                    if (newStats) {
                        const currentValue = textarea.value;
                        const newStatsText = `Stats ${statsCounter}: ${newStats}`;
                        textarea.value = currentValue
                            ? currentValue + '\n' + newStatsText
                            : newStatsText;
                        statsInput.value = ''; 
                        statsCounter++; 
                        inputWrapper.style.display = 'none'; 
                        addSaveButton.textContent = 'Add'; 
                        toggleDeleteButton(); 
                        autoGrowTextarea(); // Adjust height after adding new content
                    } else {
                        showWarning("Please enter stats before saving.");
                    }
                }
            });

            deleteButton.addEventListener('click', function () {
                hideWarning(); 
                const stats = textarea.value.split('\n');
                if (stats.length === 0 || textarea.value.trim() === '') {
                    showWarning("No stats to delete.");
                    return;
                }
                stats.pop(); 
                textarea.value = stats.join('\n'); 
                statsCounter--; 
                toggleDeleteButton(); 
                autoGrowTextarea(); // Adjust height after deleting content
            });

            textarea.addEventListener('input', autoGrowTextarea); // Adjust height on user input

            toggleDeleteButton();
            autoGrowTextarea(); // Initialize height adjustment
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('stats_field', 'stats_textarea_field');

function team_level_club_affiliation_field() {
    ob_start();
    ?>
    <div id="team-level-wrapper" class="text-fild">
        <textarea id="team-level-textarea" name="Team-club" class="auto-height" placeholder="Team Level & Club Affiliation will be shown here..." readonly></textarea>
        <div id="team-level-input-wrapper" class="add-text-input" style="display: none;">
            <input type="text" id="team-level-input" placeholder="Enter team level or club affiliation here..." />
        </div>
        <p id="team-level-warning-message" style="color: green; display: none; margin-top: 10px;"></p>
        <div class="add-buttons">
            <button type="button" id="team-level-add-save-button">Add</button>
            <button type="button" id="team-level-delete-last-button" style="display: none;">Delete Last</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const textarea = document.getElementById('team-level-textarea');
            const addSaveButton = document.getElementById('team-level-add-save-button');
            const deleteButton = document.getElementById('team-level-delete-last-button');
            const inputWrapper = document.getElementById('team-level-input-wrapper');
            const teamLevelInput = document.getElementById('team-level-input');
            const warningMessage = document.getElementById('team-level-warning-message');

            function adjustTextareaHeight() {
                // Adjust the height of the textarea based on its scrollHeight
                textarea.style.height = 'auto'; // Reset height first
                textarea.style.height = textarea.scrollHeight + 'px'; // Set height to scrollHeight
            }

            function toggleDeleteButton() {
                deleteButton.style.display = textarea.value.trim() === '' ? 'none' : 'block';
            }

            function showWarning(message) {
                warningMessage.textContent = message;
                warningMessage.style.display = 'block';
            }

            function hideWarning() {
                warningMessage.style.display = 'none';
            }

            addSaveButton.addEventListener('click', function () {
                hideWarning();
                if (addSaveButton.textContent === 'Add') {
                    inputWrapper.style.display = 'block';
                    teamLevelInput.focus();
                    addSaveButton.textContent = 'Save';
                } else if (addSaveButton.textContent === 'Save') {
                    const newEntry = teamLevelInput.value.trim();
                    if (newEntry) {
                        const currentValue = textarea.value;
                        const newText = newEntry; // Correct string interpolation
                        textarea.value = currentValue ? currentValue + "\n" + newText : newText; // Concatenate new text
                        teamLevelInput.value = '';
                        inputWrapper.style.display = 'none';
                        addSaveButton.textContent = 'Add';
                        toggleDeleteButton();
                        adjustTextareaHeight(); // Adjust height after adding new content
                    } else {
                        showWarning("Please enter a value before saving.");
                    }
                }
            });

            deleteButton.addEventListener('click', function () {
                hideWarning();
                const entries = textarea.value.split('\n');
                if (entries.length === 0 || textarea.value.trim() === '') {
                    showWarning("No entries to delete.");
                    return;
                }
                entries.pop();
                textarea.value = entries.join('\n');
                toggleDeleteButton();
                adjustTextareaHeight(); // Adjust height after deleting content
            });

            // Adjust height on initial page load and when textarea content changes
            adjustTextareaHeight();
            textarea.addEventListener('input', adjustTextareaHeight);

            toggleDeleteButton();
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('team_level_club_field', 'team_level_club_affiliation_field');

function player_number_field() {
    ob_start();
    ?>
    <div id="player-number-wrapper" class="text-fild">
        <textarea id="player-number-textarea" name="Player-Number" class="auto-height" placeholder="Player Numbers will be shown here..." readonly></textarea>
        <div id="player-number-input-wrapper" class="add-text-input" style="display: none;">
            <input type="text" id="player-number-input" placeholder="Enter player number here..." />
        </div>
        <p id="player-number-warning-message" style="color: blue; display: none; margin-top: 10px;"></p>
        <div class="add-buttons">
            <button type="button" id="player-number-add-save-button">Add</button>
            <button type="button" id="player-number-delete-last-button" style="display: none;">Delete Last</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const textarea = document.getElementById('player-number-textarea');
            const addSaveButton = document.getElementById('player-number-add-save-button');
            const deleteButton = document.getElementById('player-number-delete-last-button');
            const inputWrapper = document.getElementById('player-number-input-wrapper');
            const playerNumberInput = document.getElementById('player-number-input');
            const warningMessage = document.getElementById('player-number-warning-message');

            function adjustTextareaHeight() {
                // Adjust the height of the textarea based on its scrollHeight
                textarea.style.height = 'auto'; // Reset height first
                textarea.style.height = textarea.scrollHeight + 'px'; // Set height to scrollHeight
            }

            function toggleDeleteButton() {
                deleteButton.style.display = textarea.value.trim() === '' ? 'none' : 'block';
            }

            function showWarning(message) {
                warningMessage.textContent = message;
                warningMessage.style.display = 'block';
            }

            function hideWarning() {
                warningMessage.style.display = 'none';
            }

            addSaveButton.addEventListener('click', function () {
                hideWarning();
                if (addSaveButton.textContent === 'Add') {
                    inputWrapper.style.display = 'block';
                    playerNumberInput.focus();
                    addSaveButton.textContent = 'Save';
                } else if (addSaveButton.textContent === 'Save') {
                    const newEntry = playerNumberInput.value.trim();
                    if (newEntry) {
                        const currentValue = textarea.value;
                        const newText = newEntry; // Correct string concatenation
                        textarea.value = currentValue ? currentValue + "\n" + newText : newText; // Concatenate new text
                        playerNumberInput.value = '';
                        inputWrapper.style.display = 'none';
                        addSaveButton.textContent = 'Add';
                        toggleDeleteButton();
                        adjustTextareaHeight(); // Adjust height after adding new content
                    } else {
                        showWarning("Please enter a value before saving.");
                    }
                }
            });

            deleteButton.addEventListener('click', function () {
                hideWarning();
                const entries = textarea.value.split('\n');
                if (entries.length === 0 || textarea.value.trim() === '') {
                    showWarning("No entries to delete.");
                    return;
                }
                entries.pop();
                textarea.value = entries.join('\n');
                toggleDeleteButton();
                adjustTextareaHeight(); // Adjust height after deleting content
            });

            // Adjust height on initial page load and when textarea content changes
            adjustTextareaHeight();
            textarea.addEventListener('input', adjustTextareaHeight);

            toggleDeleteButton();
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('player_number_field', 'player_number_field');

function awards_achievements_field() {
    ob_start();
    ?>
    <div id="awards-achievements-wrapper" class="text-fild">
        <textarea id="awards-achievements-textarea" name="Awards-Achievements" class="auto-height" placeholder="Awards and Achievements will be shown here..." readonly></textarea>
        <div id="awards-achievements-input-wrapper" class="add-text-input" style="display: none;">
            <input type="text" id="awards-achievements-input" placeholder="Enter award or achievement here..." />
        </div>
        <p id="awards-achievements-warning-message" style="color: purple; display: none; margin-top: 10px;"></p>
        <div class="add-buttons">
            <button type="button" id="awards-achievements-add-save-button">Add</button>
            <button type="button" id="awards-achievements-delete-last-button" style="display: none;">Delete Last</button>
        </div>
    </div>
    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const textarea = document.getElementById('awards-achievements-textarea');
            const addSaveButton = document.getElementById('awards-achievements-add-save-button');
            const deleteButton = document.getElementById('awards-achievements-delete-last-button');
            const inputWrapper = document.getElementById('awards-achievements-input-wrapper');
            const awardsAchievementsInput = document.getElementById('awards-achievements-input');
            const warningMessage = document.getElementById('awards-achievements-warning-message');

            function adjustTextareaHeight() {
                // Adjust the height of the textarea based on its scrollHeight
                textarea.style.height = 'auto'; // Reset height first
                textarea.style.height = textarea.scrollHeight + 'px'; // Set height to scrollHeight
            }

            function toggleDeleteButton() {
                deleteButton.style.display = textarea.value.trim() === '' ? 'none' : 'block';
            }

            function showWarning(message) {
                warningMessage.textContent = message;
                warningMessage.style.display = 'block';
            }

            function hideWarning() {
                warningMessage.style.display = 'none';
            }

            addSaveButton.addEventListener('click', function () {
                hideWarning();
                if (addSaveButton.textContent === 'Add') {
                    inputWrapper.style.display = 'block';
                    awardsAchievementsInput.focus();
                    addSaveButton.textContent = 'Save';
                } else if (addSaveButton.textContent === 'Save') {
                    const newEntry = awardsAchievementsInput.value.trim();
                    if (newEntry) {
                        const currentValue = textarea.value;
                        const newText = newEntry;
                        textarea.value = currentValue ? currentValue + "\n" + newText : newText; // Corrected concatenation
                        awardsAchievementsInput.value = '';
                        inputWrapper.style.display = 'none';
                        addSaveButton.textContent = 'Add';
                        toggleDeleteButton();
                        adjustTextareaHeight(); // Adjust height after adding new content
                    } else {
                        showWarning("Please enter a value before saving.");
                    }
                }
            });

            deleteButton.addEventListener('click', function () {
                hideWarning();
                const entries = textarea.value.split('\n');
                if (entries.length === 0 || textarea.value.trim() === '') {
                    showWarning("No entries to delete.");
                    return;
                }
                entries.pop();
                textarea.value = entries.join('\n');
                toggleDeleteButton();
                adjustTextareaHeight(); // Adjust height after deleting content
            });

            // Adjust height on initial page load and when textarea content changes
            adjustTextareaHeight();
            textarea.addEventListener('input', adjustTextareaHeight);

            toggleDeleteButton();
        });
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('awards_achievements_field', 'awards_achievements_field');


<script>
document.addEventListener('DOMContentLoaded', () => {
    const fileInput = document.querySelector('input[type="file"]');
    if (fileInput) {
        fileInput.addEventListener('change', (e) => {
            let file = e.target.files[0];

            if (file) {
                let split_name = file.name.split('.');
                let randomString = Math.random().toString(36).substring(2, 8);
                let name = `playerprofileimg${randomString}.` + split_name[split_name.length - 1];
                let blob = file.slice(0, file.size, file.type);
                let new_file = new File([blob], name, { type: file.type });
                const data_transfer = new DataTransfer();
                data_transfer.items.add(new_file);
                e.target.files = data_transfer.files;
            }
        });
    } else {
        console.error("No input[type='file'] found in the DOM.");
    }
});


</script>
<?php
if (!defined('ABSPATH')) {
    exit;
}

$player = $players_data[$player_id];

get_header(); ?>


<style>
header#masthead {
  display: none;
}

footer {
  display: none;
}
</style>

<div class="back-button">
    <a href="https://sportmeid.com/view-profile/"><span><img
                src="https://sportmeid.com/wp-content/uploads/2024/12/arrow.svg"></span> Back</a>
</div>
<div class="player-detail">
    <div class="player-main-img">
            <div class="player-wrapper-img">
        <img src="<?php echo esc_url($player['file_url']); ?>" alt="<?php echo esc_attr($player['name']); ?>" />
     </div>
    </div>
    <div class="profile-container">
        <h1>Player Profile</h1>
        <table>
            <tr>
                <td>Full Name:</td>
                <td><?php echo esc_html(strtolower($player['name'])); ?></td>
            </tr>
            <tr>
                <td>Sport:</td>
                <td><?php echo nl2br(esc_html(strtolower($player['sport']))); ?></td>
            </tr>
            <tr>
                <td>Email Address:</td>
                <td><?php echo esc_html(strtolower($player['email_address'])); ?></td>
            </tr>
             <tr>
                <td>Phone Number:</td>
                <td><?php echo esc_html(strtolower($player['phone_Number'])); ?></td>
            </tr>
            <tr>
                <td>Nickname:</td>
                <td><?php echo esc_html(strtolower($player['nick_name'])); ?></td>
            </tr>
            <tr>
                <td>Player Number:</td>
                <td><?php echo nl2br(esc_html(strtolower($player['player_number']))); ?></td>
            </tr>
            <tr>
                <td>Graduation Year:</td>
                <td><?php echo esc_html(strtolower($player['graduation_year'])); ?></td>
            </tr>
            <tr>
                <td>Team Level & Team/Club Affiliation:</td>
                <td><?php echo nl2br(esc_html(strtolower($player['team_club']))); ?></td>
            </tr>
            <tr>
                <td>Years Playing/Experience:</td>
                <td><?php echo esc_html(strtolower($player['years_playing'])); ?></td>
            </tr>
            <tr>
                <td>Dominant Hand:</td>
                <td><?php echo esc_html($player['dominant_hand']); ?></td>
            </tr>
            <tr>
                <td>Stats:</td>
                <td><?php echo nl2br(esc_html(strtolower($player['stats']))); ?></td>
            </tr>
            <tr>
                <td>Positions:</td>
                <td><?php echo nl2br(esc_html(strtolower($player['positions']))); ?></td>
            </tr>
            <tr>
                <td>Sports Awards/Achievements:</td>
                <td><?php echo nl2br(esc_html(strtolower($player['awards_achievements']))); ?></td>
            </tr>
            <tr>
                <td>Social Media Links:</td>
                <td class="social-media">
                    <a href="<?php echo esc_html(strtolower($player['tiktok_link'])); ?>"><img src="https://sportmeid.com/wp-content/uploads/2024/12/tiktok.svg"></a>
                    <a href="<?php echo esc_html(strtolower($player['instagram_link'])); ?>"><img src="https://sportmeid.com/wp-content/uploads/2024/12/instagram.svg"></a>
                    <a href="<?php echo esc_html(strtolower($player['twitter_link'])); ?>"><img src="https://sportmeid.com/wp-content/uploads/2024/12/twitter.svg"></a>
                    <a href="<?php echo esc_html(strtolower($player['youtube_link'])); ?>"><img src="https://sportmeid.com/wp-content/uploads/2024/12/youtube.svg"></a> 
                    <a href="<?php echo esc_html(strtolower($player['imlca_link'])); ?>"><img src="https://sportmeid.mmcgbl.ae/wp-content/uploads/2024/12/imlca-icon.png"></a>   
                </td>
            </tr>
        </table>
    </div>
</div>
<script>
  document.addEventListener("DOMContentLoaded", () => {
    const socialLinks = document.querySelectorAll("td.social-media a");

    socialLinks.forEach(link => {
        if (!link.getAttribute("href").trim()) {
            link.style.display = "none";
        }
    });
});
</script>


function delete_players_layout_data() {
    // Delete the 'players_layout' option from the database
    delete_option('players_layout');
}

function remove_players_shortcode() {
    // Replace 'your_shortcode_name' with the actual shortcode name
    remove_shortcode('your_shortcode_name');
}

add_action('init', 'delete_players_layout_data');
add_action('init', 'remove_players_shortcode');

  
function remove_specific_player_data() {
    // The specific player ID to remove
    $player_id_to_remove = '676c0c99aab75';

    // Retrieve the existing data
    $players_data = get_option('players_data', []);
    $players_layout = get_option('players_layout', []);

    // Remove the player data with the specific ID
    if (isset($players_data[$player_id_to_remove])) {
        unset($players_data[$player_id_to_remove]);
        update_option('players_data', $players_data);
    }

    // Filter the players layout to remove the entry with the specific ID
    if (!empty($players_layout)) {
        $players_layout = array_filter($players_layout, function ($entry) use ($player_id_to_remove) {
            return strpos($entry, $player_id_to_remove) === false;
        });
        update_option('players_layout', $players_layout);
    }
}

// Hook the function to an admin action
add_action('admin_init', 'remove_specific_player_data');
content_copyCOPY