';
return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- inline static SVG for the admin menu icon, not obfuscation.
}
public static function enqueue( $hook ) {
if ( 'toplevel_page_aegistha' !== $hook ) {
return;
}
wp_enqueue_style( 'aegistha-admin', AEGISTHA_PLUGIN_URL . 'assets/css/admin.css', array(), AEGISTHA_VERSION );
wp_enqueue_script( 'aegistha-admin', AEGISTHA_PLUGIN_URL . 'assets/js/admin.js', array(), AEGISTHA_VERSION, true );
}
/**
* Apply or undo a single fix. One handler, nonce + capability protected.
*/
public static function handle_fix() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to do this.', 'aegistha' ), '', array( 'response' => 403 ) );
}
check_admin_referer( 'aegistha_fix' );
$key = isset( $_POST['fix'] ) ? sanitize_key( wp_unslash( $_POST['fix'] ) ) : '';
$on = ! empty( $_POST['enable'] );
$settings = Aegistha_Settings::get();
if ( 'alerts' === $key ) {
$settings['alerts_enabled'] = $on ? 1 : 0;
} elseif ( isset( $settings['fixes'][ $key ] ) ) {
$settings['fixes'][ $key ] = $on ? 1 : 0;
}
update_option( Aegistha_Settings::OPTION, Aegistha_Settings::sanitize( $settings ) );
$args = array( 'page' => 'aegistha', 'aegistha_done' => '1' );
if ( $on ) {
$args['aegistha_applied'] = $key;
}
wp_safe_redirect( add_query_arg( $args, admin_url( 'admin.php' ) ) );
exit;
}
/**
* Clear the abandoned-code cache and re-scan on the next page load.
*/
public static function handle_recheck() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to do this.', 'aegistha' ), '', array( 'response' => 403 ) );
}
check_admin_referer( 'aegistha_recheck' );
Aegistha_Abandoned::invalidate();
wp_safe_redirect( admin_url( 'admin.php?page=aegistha&aegistha_rechecked=1#you' ) );
exit;
}
public static function notices() {
$screen = get_current_screen();
if ( ! $screen || 'toplevel_page_aegistha' !== $screen->id ) {
return;
}
if ( isset( $_GET['aegistha_applied'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only UI flag after our own redirect.
echo '' . esc_html__( 'Nice work — that protection is now in place. One less thing to worry about.', 'aegistha' ) . '
';
} elseif ( isset( $_GET['aegistha_done'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only UI flag after our own redirect.
echo '' . esc_html__( 'Done. Your checkup is updated below.', 'aegistha' ) . '
';
}
if ( isset( $_GET['aegistha_rechecked'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only UI flag after our own redirect.
echo '' . esc_html__( 'Re-checked your plugins and themes.', 'aegistha' ) . '
';
}
}
public static function render_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$rows = Aegistha_Checks::run();
$meter = Aegistha_Checks::meter( $rows );
$applied = isset( $_GET['aegistha_applied'] ) ? sanitize_key( wp_unslash( $_GET['aegistha_applied'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only UI highlight after our own redirect.
require AEGISTHA_PLUGIN_DIR . 'admin/views/checkup.php';
}
}