| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Plugin admin-notice renderers shown only on the plugin's own admin page. |
| 8 |
* |
| 9 |
* abj404_show_runtime_integrity_notice() warns when required plugin files are |
| 10 |
* missing. |
| 11 |
* |
| 12 |
* abj404_show_plugin_db_notice() surfaces user-actionable database errors |
| 13 |
* (never the developer-level collation notices) on the plugin page. |
| 14 |
* |
| 15 |
* The add_action('admin_notices', ...) registrations stay in 404-solution.php; |
| 16 |
* this file only defines the renderers. |
| 17 |
*/ |
| 18 |
// allow-no-test-found: boot-time admin_notices global renderers wired via add_action in 404-solution.php; no same-named unit file. abj404_show_plugin_db_notice (and the other notice renderers) are exercised in CollationAutoRecoveryTest. |
| 19 |
|
| 20 |
if (!function_exists('abj404_show_plugin_db_notice')) { |
| 21 |
/** @return void */ |
| 22 |
function abj404_show_plugin_db_notice() { |
| 23 |
if (!is_admin() || !abj404_current_user_is_plugin_admin()) { |
| 24 |
return; |
| 25 |
} |
| 26 |
$page = ABJ_404_Solution_RequestInputNormalizer::readText($_GET, array('name' => 'page')); |
| 27 |
if ($page !== ABJ404_PP) { |
| 28 |
return; |
| 29 |
} |
| 30 |
$notice = get_transient('abj404_plugin_db_notice'); |
| 31 |
if (!is_array($notice)) { |
| 32 |
return; |
| 33 |
} |
| 34 |
$type = isset($notice['type']) ? $notice['type'] : ''; |
| 35 |
// Collation issues are developer-level; don't show them to the user. |
| 36 |
if ($type === 'collation') { |
| 37 |
return; |
| 38 |
} |
| 39 |
$noticeMessage = isset($notice['message']) && is_string($notice['message']) ? $notice['message'] : ''; |
| 40 |
if ($noticeMessage === '') { |
| 41 |
return; |
| 42 |
} |
| 43 |
$guidance = isset($notice['guidance']) && is_string($notice['guidance']) ? $notice['guidance'] : ''; |
| 44 |
echo '<div class="notice notice-error"><p><strong>404 Solution:</strong> ' . esc_html($noticeMessage) . '</p>'; |
| 45 |
if ($guidance !== '') { |
| 46 |
echo '<p>' . esc_html($guidance) . '</p>'; |
| 47 |
} |
| 48 |
if (!empty($notice['error_string'])) { |
| 49 |
$errorString = is_string($notice['error_string']) ? $notice['error_string'] : ''; |
| 50 |
echo '<details><summary>' . esc_html(__('Show database error details', '404-solution')) . '</summary>'; |
| 51 |
echo '<pre style="white-space:pre-wrap;word-break:break-all;max-width:100%;margin:6px 0;">' . esc_html($errorString) . '</pre></details>'; |
| 52 |
} |
| 53 |
echo '</div>'; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
if (!function_exists('abj404_show_runtime_integrity_notice')) { |
| 58 |
/** @return void */ |
| 59 |
function abj404_show_runtime_integrity_notice() { |
| 60 |
if (!is_admin() || !abj404_current_user_is_plugin_admin()) { |
| 61 |
return; |
| 62 |
} |
| 63 |
$page = ABJ_404_Solution_RequestInputNormalizer::readText($_GET, array('name' => 'page')); |
| 64 |
if ($page !== ABJ404_PP) { |
| 65 |
return; |
| 66 |
} |
| 67 |
$missing = get_transient('abj404_runtime_missing_files'); |
| 68 |
if (!is_array($missing) || count($missing) === 0) { |
| 69 |
return; |
| 70 |
} |
| 71 |
echo '<div class="notice notice-error"><p><strong>404 Solution:</strong> '; |
| 72 |
echo esc_html(__('Some required plugin files are missing. Please reinstall the plugin package.', '404-solution')); |
| 73 |
$missingBasenames = array(); |
| 74 |
foreach ($missing as $missingPath) { |
| 75 |
if (is_string($missingPath)) { |
| 76 |
$missingBasenames[] = basename($missingPath); |
| 77 |
} |
| 78 |
} |
| 79 |
echo '</p><p><code>' . esc_html(implode(', ', $missingBasenames)) . '</code></p></div>'; |
| 80 |
} |
| 81 |
} |
| 82 |
|