clean build for version 1.4.5 with fixes of security funtionalities, logic branches, etc. Already tested and working fine

This commit is contained in:
dwindown
2026-01-07 15:10:47 +07:00
parent 31b3398c2f
commit 0ba62b435a
26 changed files with 8962 additions and 2804 deletions

292
admin/test-turnstile.php Normal file
View File

@@ -0,0 +1,292 @@
<?php
/**
* Test script for debugging Turnstile configuration in Sheet Data Checker Pro
*
* This script helps diagnose why Turnstile might not be showing up in the security dashboard.
* Run this in WordPress admin by navigating to: /wp-admin/admin.php?page=test-turnstile
*
* @since 1.5.0
*/
// Don't allow direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Register test page in admin menu
*/
function checker_turnstile_test_add_menu() {
add_submenu_page(
null, // Hide from menu
'Turnstile Test',
'Turnstile Test',
'manage_options',
'test-turnstile',
'checker_turnstile_test_page'
);
}
add_action('admin_menu', 'checker_turnstile_test_add_menu');
/**
* Render the test page
*/
function checker_turnstile_test_page() {
?>
<div class="wrap">
<h1>Turnstile Configuration Test</h1>
<?php
// Test if class exists
if (!class_exists('CHECKER_CAPTCHA_HELPER')) {
echo '<div class="notice notice-error"><p>CHECKER_CAPTCHA_HELPER class not found. Please ensure the helper file is loaded.</p></div>';
return;
}
?>
<div class="card">
<h2 class="title">Turnstile Configuration Check</h2>
<?php
// Get all checkers
$checkers = get_posts([
'post_type' => 'checker',
'post_status' => 'publish',
'numberposts' => -1
]);
$total_checkers = count($checkers);
$turnstile_enabled = 0;
$turnstile_configured = 0;
$results = [];
echo "<h3>Testing $total_checkers checkers...</h3>";
foreach ($checkers as $checker) {
$checker_id = $checker->ID;
$checker_title = get_the_title($checker_id);
$checker_data = get_post_meta($checker_id, 'checker', true);
// Initialize result for this checker
$result = [
'id' => $checker_id,
'title' => $checker_title,
'has_security' => false,
'has_turnstile' => false,
'turnstile_enabled' => false,
'has_site_key' => false,
'has_secret_key' => false,
'site_key_format' => false
];
// Check if security data exists
if (isset($checker_data['security'])) {
$result['has_security'] = true;
// Check if Turnstile data exists
if (isset($checker_data['security']['turnstile'])) {
$result['has_turnstile'] = true;
$turnstile_data = $checker_data['security']['turnstile'];
// Check if enabled
if (isset($turnstile_data['enabled']) && $turnstile_data['enabled'] === 'yes') {
$result['turnstile_enabled'] = true;
$turnstile_enabled++;
// Check site key
if (isset($turnstile_data['site_key']) && !empty($turnstile_data['site_key'])) {
$result['has_site_key'] = true;
$site_key = $turnstile_data['site_key'];
// Check format
if (preg_match('/^0x4AAA[a-zA-Z0-9_-]{33}$/', $site_key)) {
$result['site_key_format'] = true;
$turnstile_configured++;
}
}
// Check secret key
if (isset($turnstile_data['secret_key']) && !empty($turnstile_data['secret_key'])) {
$result['has_secret_key'] = true;
}
}
}
}
$results[] = $result;
}
// Display summary
echo "<div class='notice notice-info'>";
echo "<p><strong>Summary:</strong></p>";
echo "<ul>";
echo "<li>Total checkers: $total_checkers</li>";
echo "<li>Checkers with Turnstile enabled: $turnstile_enabled</li>";
echo "<li>Checkers with Turnstile properly configured: $turnstile_configured</li>";
echo "</ul>";
echo "</div>";
// Display detailed results
echo "<h3>Detailed Results</h3>";
echo "<table class='wp-list-table widefat fixed striped'>";
echo "<thead>";
echo "<tr>";
echo "<th>Checker</th>";
echo "<th>Security Data</th>";
echo "<th>Turnstile Data</th>";
echo "<th>Turnstile Enabled</th>";
echo "<th>Site Key</th>";
echo "<th>Secret Key</th>";
echo "<th>Key Format</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
foreach ($results as $result) {
echo "<tr>";
echo "<td><strong>" . esc_html($result['title']) . "</strong> (ID: {$result['id']})</td>";
// Security Data
echo "<td>";
echo $result['has_security']
? '<span class="dashicons dashicons-yes text-success"></span> Yes'
: '<span class="dashicons dashicons-no text-danger"></span> No';
echo "</td>";
// Turnstile Data
echo "<td>";
echo $result['has_turnstile']
? '<span class="dashicons dashicons-yes text-success"></span> Yes'
: '<span class="dashicons dashicons-no text-danger"></span> No';
echo "</td>";
// Turnstile Enabled
echo "<td>";
echo $result['turnstile_enabled']
? '<span class="dashicons dashicons-yes-alt text-success"></span> Enabled'
: '<span class="dashicons dashicons-no-alt text-danger"></span> Disabled';
echo "</td>";
// Site Key
echo "<td>";
if ($result['has_site_key']) {
echo '<span class="dashicons dashicons-yes text-success"></span> Present';
} else {
echo '<span class="dashicons dashicons-no text-danger"></span> Missing';
}
echo "</td>";
// Secret Key
echo "<td>";
if ($result['has_secret_key']) {
echo '<span class="dashicons dashicons-yes text-success"></span> Present';
} else {
echo '<span class="dashicons dashicons-no text-danger"></span> Missing';
}
echo "</td>";
// Key Format
echo "<td>";
if ($result['site_key_format']) {
echo '<span class="dashicons dashicons-yes text-success"></span> Valid';
} else {
echo '<span class="dashicons dashicons-warning text-warning"></span> Invalid';
}
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Test helper methods
echo "<h3>CAPTCHA Helper Test</h3>";
if ($turnstile_enabled > 0) {
echo "<p>Testing CAPTCHA helper methods with first Turnstile-enabled checker...</p>";
// Find first Turnstile-enabled checker
$test_checker = null;
foreach ($results as $result) {
if ($result['turnstile_enabled']) {
$test_checker = $result;
break;
}
}
if ($test_checker) {
echo "<h4>Testing Checker: " . esc_html($test_checker['title']) . "</h4>";
// Test get_captcha_config
if (class_exists('CHECKER_CAPTCHA_HELPER')) {
$config = CHECKER_CAPTCHA_HELPER::get_captcha_config($test_checker['id']);
echo "<h5>CAPTCHA Config:</h5>";
echo "<pre>";
print_r($config);
echo "</pre>";
// Test validate_captcha_config
$validation = CHECKER_CAPTCHA_HELPER::validate_captcha_config($test_checker['id']);
echo "<h5>Validation Result:</h5>";
echo "<pre>";
print_r($validation);
echo "</pre>";
}
}
} else {
echo "<p>No checkers with Turnstile enabled found to test.</p>";
}
// Show debug info
echo "<h3>Debug Information</h3>";
echo "<p>WordPress Version: " . get_bloginfo('version') . "</p>";
echo "<p>PHP Version: " . PHP_VERSION . "</p>";
echo "<p>Plugin Version: " . defined('SHEET_CHECKER_PRO_VERSION') ? SHEET_CHECKER_PRO_VERSION : 'Unknown' . "</p>";
// Check WordPress debug mode
echo "<p>WordPress Debug: " . (WP_DEBUG ? 'Enabled' : 'Disabled') . "</p>";
echo "<p>WordPress Debug Log: " . (WP_DEBUG_LOG ? 'Enabled' : 'Disabled') . "</p>";
// Show last few error log entries
if (WP_DEBUG && WP_DEBUG_LOG) {
$log_file = WP_CONTENT_DIR . '/debug.log';
if (file_exists($log_file) && is_readable($log_file)) {
echo "<h4>Last 10 lines from debug log:</h4>";
echo "<pre>";
$lines = file($log_file);
$last_lines = array_slice($lines, -10);
echo htmlspecialchars(implode('', $last_lines));
echo "</pre>";
}
}
?>
<div class="card">
<h3>Troubleshooting Tips</h3>
<ol>
<li>If Turnstile appears enabled but not configured, check that both site key and secret key are set.</li>
<li>If key format is invalid, ensure the key starts with "0x4AAA" and is 40 characters long.</li>
<li>Check WordPress debug log for any errors related to Turnstile.</li>
<li>Verify the Turnstile keys are correctly copied from the Cloudflare dashboard.</li>
<li>If security data is missing, try resaving the checker settings.</li>
</ol>
</div>
</div>
</div>
<style>
.text-success {
color: #46b450;
}
.text-danger {
color: #dc3232;
}
.text-warning {
color: #ffb900;
}
</style>
<?php
}