Create a time stamping plugin that has the date, team member, start time and end time. The stamping button should have the start time, and once activated, it should automatically have the end time. The result between start time and end time should be

Home » Snippets » Create a time stamping plugin that has the date, team member, start time and end time. The stamping button should have the start time, and once activated, it should automatically have the end time. The result between start time and end time should be
0

Created with:

Visibility: 

public

Creator: info@webmasterseo.ch

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
/*
Plugin Name: Time Stamping Plugin
Description: Adds a time stamping feature to track team member's work hours.
Version: 1.0
Author: Your Name
Text Domain: wpturbo
*/

// Add a shortcode to display the time stamping button
function wpturbo_time_stamping_button_shortcode() {
    ob_start();
    ?>
    <button onclick="startTimestamp()">Start Time</button>
    <script>
        function startTimestamp() {
            var startTime = new Date().toLocaleTimeString();
            document.cookie = "startTime=" + startTime;
        }
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('time_stamping_button', 'wpturbo_time_stamping_button_shortcode');

// Add a custom page template to display the time stamping summary
function wpturbo_time_stamping_summary_template($template) {
    if (is_page('time-stamping-summary')) {
        return plugin_dir_path(__FILE__) . 'time-stamping-summary-template.php';
    }
    return $template;
}
add_filter('page_template', 'wpturbo_time_stamping_summary_template');

// Add a function to process the time stamping data and display the summary
function wpturbo_time_stamping_summary() {
    $startTime = isset($_COOKIE['startTime']) ? $_COOKIE['startTime'] : '';
    $endTime = date('h:i:s A');
    $hoursWorked = (strtotime($endTime) - strtotime($startTime)) / (60 * 60);

    $teamMember = 'John Doe'; // Replace with the actual team member name
    $workLocation = 'Office'; // Replace with the actual work location

    // Output the time stamping summary
    echo '<h2>Time Stamping Summary</h2>';
    echo '<p>Team Member: ' . $teamMember . '</p>';
    echo '<p>Work Location: ' . $workLocation . '</p>';
    echo '<p>Start Time: ' . $startTime . '</p>';
    echo '<p>End Time: ' . $endTime . '</p>';
    echo '<p>Hours Worked: ' . $hoursWorked . '</p>';
}

// Add a custom member page template
function wpturbo_member_page_template($template) {
    if (is_page('member')) {
        return plugin_dir_path(__FILE__) . 'member-page-template.php';
    }
    return $template;
}
add_filter('page_template', 'wpturbo_member_page_template');

// Add custom meta fields for member data
function wpturbo_member_meta_fields() {
    add_meta_box('member_meta', 'Member Details', 'wpturbo_member_meta_callback', 'page', 'normal', 'high');
}
add_action('add_meta_boxes', 'wpturbo_member_meta_fields');

// Render member meta fields
function wpturbo_member_meta_callback($post) {
    wp_nonce_field(basename(__FILE__), 'wpturbo_member_nonce');
    $member_data = get_post_meta($post->ID, 'wpturbo_member_data', true);

    $full_name = isset($member_data['full_name']) ? $member_data['full_name'] : '';
    $email = isset($member_data['email']) ? $member_data['email'] : '';
    $phone = isset($member_data['phone']) ? $member_data['phone'] : '';

    // Output the member meta fields
    ?>
    <label for="full_name">Full Name:</label>
    <input type="text" id="full_name" name="member_data[full_name]" value="<?php echo esc_attr($full_name); ?>" required>
    <br>
    <label for="email">Email:</label>
    <input type="email" id="email" name="member_data[email]" value="<?php echo esc_attr($email); ?>" required>
    <br>
    <label for="phone">Phone:</label>
    <input type="text" id="phone" name="member_data[phone]" value="<?php echo esc_attr($phone); ?>" required>
    <?php
}

// Save member meta fields
function wpturbo_save_member_meta_fields($post_id) {
    if (!isset($_POST['wpturbo_member_nonce']) || !wp_verify_nonce($_POST['wpturbo_member_nonce'], basename(__FILE__))) {
        return;
    }

    if (!current_user_can('edit_post', $post_id)) {
        return;
    }

    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }

    if (isset($_POST['member_data'])) {
        $member_data = $_POST['member_data'];
        update_post_meta($post_id, 'wpturbo_member_data', $member_data);
    }
}
add_action('save_post', 'wpturbo_save_member_meta_fields');
				

Explanation:

In this updated code, I have added functionality to create a custom member page with the following data fields: full name, email, phone, and photo.

First, I added a custom page template called member-page-template.php to display the member details. You can create this template file and design it according to your requirements.

Next, I added custom meta fields for the member data using the add_meta_box function. The member data is stored as post meta using the key wpturbo_member_data.

I also added two functions, wpturbo_member_meta_callback and wpturbo_save_member_meta_fields, to render and save the member meta fields, respectively. These functions are hooked into the appropriate actions to display and save the member data when the member page is edited.

To use this functionality, create a new page and set its template to "Member". Then, you can edit the page and fill in the member details in the meta fields.

Please note that you will need to create the member-page-template.php file and customize it to display the member photo and any other additional information you may require.

Remember to customize the placeholder values and styling to fit your specific needs.

I hope this helps you create the member page with the requested data! Let me know if you have any further questions.

Register an account to save your snippets or go Pro to get more features.