| 1 |
<?php |
| 2 |
|
| 3 |
namespace DebugLogViewer\Admin\Controllers; |
| 4 |
|
| 5 |
if (! defined('ABSPATH')) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
abstract class BaseController |
| 10 |
{ |
| 11 |
protected function verifyAjaxRequest($nonce_action = 'ajax_nonce', $capability = 'manage_options') |
| 12 |
{ |
| 13 |
$nonce = isset($_POST['wp_nonce']) ? sanitize_text_field(wp_unslash($_POST['wp_nonce'])) : ''; |
| 14 |
|
| 15 |
if (! wp_verify_nonce($nonce, $nonce_action)) { |
| 16 |
wp_send_json_error(__('Please refresh the page', 'debug-log-viewer'), 403); |
| 17 |
} |
| 18 |
|
| 19 |
if (! current_user_can($capability)) { |
| 20 |
wp_send_json_error(__('Insufficient permissions', 'debug-log-viewer'), 403); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
protected function verifyRequest($nonce_action, $capability = 'manage_options', $method = null) |
| 25 |
{ |
| 26 |
$method = $method ?: $_SERVER['REQUEST_METHOD']; |
| 27 |
$source = ($method === 'POST') ? $_POST : $_GET; |
| 28 |
|
| 29 |
$nonce = isset($source['_wpnonce']) ? sanitize_text_field(wp_unslash($source['_wpnonce'])) : ''; |
| 30 |
|
| 31 |
if (! wp_verify_nonce($nonce, $nonce_action)) { |
| 32 |
wp_die(esc_html__('Security check failed', 'debug-log-viewer'), 403); |
| 33 |
} |
| 34 |
|
| 35 |
if (! current_user_can($capability)) { |
| 36 |
wp_die(esc_html__('You do not have permission to perform this action', 'debug-log-viewer'), 403); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|