// ثبت حضور کاربر
function save_user_attendance() {
    if (!is_user_logged_in() || !isset($_POST['attendance_action'])) {
        return;
    }

    $user_id = get_current_user_id();
    $current_time = current_time('Y-m-d H:i:s');
    update_user_meta($user_id, 'last_attendance', $current_time);

    wp_redirect($_SERVER['HTTP_REFERER']);
    exit;
}
add_action('init', 'save_user_attendance');

// نمایش دکمه حضور در پنل کاربری (با شورت‌کد)
function display_attendance_button() {
    if (!is_user_logged_in()) {
        return '<p>برای ثبت حضور، وارد حساب کاربری خود شوید.</p>';
    }

    $user_id = get_current_user_id();
    $last_attendance = get_user_meta($user_id, 'last_attendance', true);

    $output = '<form method="post" style="margin: 10px 0;">';
    $output .= '<input type="hidden" name="attendance_action" value="1">';
    $output .= '<button type="submit" style="padding: 10px 20px; background: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer;">✅ ثبت حضور</button>';
    $output .= '</form>';

    if ($last_attendance) {
        $output .= '<p style="margin-top: 5px;">🕒 آخرین حضور: ' . esc_html($last_attendance) . '</p>';
    }

    return $output;
}
add_shortcode('attendance_button', 'display_attendance_button');

// اضافه کردن منوی حضور و غیاب به پنل مدیریت
add_action('admin_menu', 'add_attendance_menu');
function add_attendance_menu() {
    add_menu_page(
        'حضور و غیاب',
        'حضور و غیاب',
        'manage_options',
        'attendance-list',
        'display_attendance_list',
        'dashicons-calendar-alt',
        25
    );
}

// نمایش لیست حضور کاربران در پنل مدیریت
function display_attendance_list() {
    $users = get_users(['fields' => ['ID', 'display_name']]);
    echo '<h1>لیست حضور کاربران</h1>';
    echo '<table border="1" cellpadding="10" style="width:100%; border-collapse: collapse; text-align: left;">';
    echo '<tr><th>نام کاربر</th><th>آخرین حضور</th></tr>';
    foreach ($users as $user) {
        $attendance = get_user_meta($user->ID, 'last_attendance', true);
        echo '<tr>';
        echo '<td>' . esc_html($user->display_name) . '</td>';
        echo '<td>' . ($attendance ? esc_html($attendance) : 'تاکنون حضور نداشته') . '</td>';
        echo '</tr>';
    }
    echo '</table>';
}
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//battstore.ir/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>http://battstore.ir/post-sitemap.xml</loc>
		<lastmod>2026-07-09T14:51:03+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/page-sitemap.xml</loc>
		<lastmod>2026-08-01T07:11:40+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/product-sitemap.xml</loc>
		<lastmod>2026-07-20T20:30:01+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/category-sitemap.xml</loc>
		<lastmod>2026-07-09T14:51:03+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/product_brand-sitemap.xml</loc>
		<lastmod>2026-07-20T20:30:01+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/product_cat-sitemap.xml</loc>
		<lastmod>2026-07-20T20:30:01+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/pa_amper-sitemap.xml</loc>
		<lastmod>2026-07-20T20:30:01+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/pa_brand-sitemap.xml</loc>
		<lastmod>2026-07-20T20:30:01+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>http://battstore.ir/author-sitemap.xml</loc>
		<lastmod>2026-07-09T06:36:56+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->