# WordPress Plugin Debugging Guide

## Common Issues & Solutions

### 1. Button Not Responding

**Check if jQuery is loaded:**
- Open browser DevTools (F12)
- Go to Console tab
- Type: `jQuery` and press Enter
- Should show: `function(e,t){return new S.fn.init(e,t)}`
- If it shows "undefined", jQuery is not loaded

**Check if script is loaded:**
- In DevTools Console, type: `pluginScope`
- Should show an object with: `ajaxUrl`, `config_id`, `nonce`, `userRef`, `currentUser`
- If undefined, the script didn't load

### 2. Check Plugin Settings

Go to WordPress Admin → Prembly → Settings

Verify:
- **Public API Key**: `your_api_key_here`
- **SDK Widget ID**: `your-widget-id-here`

### 3. Check Button HTML

Your button MUST have `id="idx_init"`:

```html
<button id="idx_init">Start Verification</button>
```

**Common mistakes:**
- ❌ `class="idx_init"` (wrong - should be id, not class)
- ❌ `id="idx-init"` (wrong - dash instead of underscore)
- ❌ Multiple buttons with same ID (only first one will work)

### 4. Check Browser Console for Errors

1. Open DevTools (F12)
2. Go to Console tab
3. Click the button
4. Look for errors in red

**Common errors:**
- "pluginScope is not defined" → Script not loaded
- "$ is not a function" → jQuery not loaded
- AJAX error → Check Network tab

### 5. Check Network Tab

1. Open DevTools (F12)
2. Go to Network tab
3. Click the button
4. Look for request to `admin-ajax.php`

**What to check:**
- Request Payload should have: `action: prembly_initialize_sdk`
- Response should have: `{"success":true,"data":{"widget_id":"..."}}`

### 6. Enable WordPress Debug Logging

Add to `wp-config.php`:

```php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
```

Then check `/wp-content/debug.log` for errors.

### 7. Test Button Manually

Add this to your page temporarily to test:

```html
<script>
jQuery(document).ready(function($) {
    console.log('jQuery loaded:', typeof jQuery);
    console.log('pluginScope:', pluginScope);
    console.log('Button exists:', $('#idx_init').length);
    
    $('#idx_init').on('click', function() {
        console.log('Button clicked!');
    });
});
</script>

<button id="idx_init" style="padding: 15px 30px; background: #2D9B9B; color: white; border: none; border-radius: 8px; cursor: pointer;">
    Start Verification
</button>
```

### 8. Check if Plugin is Active

- Go to WordPress Admin → Plugins
- Make sure "Prembly Identity Checkout" is **Active**
- Try deactivating and reactivating

### 9. Clear Cache

- Clear browser cache (Ctrl+Shift+Delete)
- Clear WordPress cache (if using caching plugin)
- Try in Incognito/Private mode

### 10. Test with Default User Data

If you're not logged in, the plugin uses placeholder data:
- First Name: "User"
- Last Name: "Guest"
- Email: "user@example.com"

This should still work for testing.

## Quick Test Checklist

- [ ] Plugin is activated
- [ ] Settings are saved (API Key + Widget ID)
- [ ] Button has `id="idx_init"` (not class)
- [ ] jQuery is loaded (check console)
- [ ] No JavaScript errors in console
- [ ] Browser cache is cleared

## Still Not Working?

Share the following information:
1. Browser console errors (screenshot)
2. Network tab showing the AJAX request (screenshot)
3. WordPress debug.log contents
4. What happens when you click the button (nothing? error message?)
