add_action('rest_api_init', function () {
    register_rest_route('leostar/v1', '/unlock', array(
        'methods' => 'POST',
        'callback' => 'leostar_unlock_user',
        'permission_callback' => '__return_true'
    ));
});

function leostar_unlock_user($request) {

    $email = sanitize_text_field($request['email']);
    $action = sanitize_text_field($request['action']);

    if (!$email || !$action) {
        return ['status' => 'error', 'message' => 'Missing data'];
    }

    $user = get_user_by('email', $email);

    if (!$user) {
        return ['status' => 'error', 'message' => 'User not found'];
    }

    $user_id = $user->ID;

    // 🔥 MAP SYSTEM ACTION → MEMBERPRESS ID
    $map = [
        'Unlock ETM 1' => 2050,
        'Unlock ETM 2' => 2051,
        'Unlock ETM 3' => 2052,
    ];

    if (!isset($map[$action])) {
        return ['status' => 'error', 'message' => 'Invalid action'];
    }

    $membership_id = $map[$action];

    // Grant access
    if (class_exists('MeprUser')) {
        $mepr_user = new MeprUser($user_id);
        $mepr_user->add_product($membership_id);
    }

    return ['status' => 'success', 'message' => 'Access granted'];
}



<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://leostarpresents.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://leostarpresents.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://leostarpresents.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://leostarpresents.com/wp-sitemap-posts-memberpressproduct-1.xml</loc></sitemap><sitemap><loc>https://leostarpresents.com/wp-sitemap-posts-mpcs-course-1.xml</loc></sitemap><sitemap><loc>https://leostarpresents.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://leostarpresents.com/wp-sitemap-taxonomies-mpcs-course-categories-1.xml</loc></sitemap></sitemapindex>
