__( 'Disconnect AbleGuard?', 'ableguard-accessibility-toolkit' ), 'message' => __( 'Disconnect this site from AbleGuard? Fixes and your statement stop being applied here. You can connect again at any time.', 'ableguard-accessibility-toolkit' ), 'cancel' => __( 'Cancel', 'ableguard-accessibility-toolkit' ), 'confirm' => __( 'Disconnect', 'ableguard-accessibility-toolkit' ), ) ); return '(function(){var t=' . $text . ';' . <<<'JS' var f=document.getElementById('ableguard-disconnect-form'); if(!f){return;} var trigger=f.querySelector('input[type="submit"],button[type="submit"]'); if(!trigger){return;} var confirmed=false; var open=null; function el(tag,cls,text){var n=document.createElement(tag);if(cls){n.className=cls;}if(text){n.textContent=text;}return n;} function build(id){ var box=el('div','ableguard-confirm-body'); var h=el('h2','ableguard-confirm-title',t.title);h.id=id+'-title'; var p=el('p','ableguard-confirm-message',t.message);p.id=id+'-message'; var row=el('div','ableguard-confirm-actions'); var cancel=el('button','button',t.cancel);cancel.type='button'; var go=el('button','button button-link-delete ableguard-confirm-go',t.confirm);go.type='button'; row.appendChild(cancel);row.appendChild(go); box.appendChild(h);box.appendChild(p);box.appendChild(row); return {box:box,cancel:cancel,go:go}; } function proceed(){confirmed=true;trigger.click();} function close(){ if(!open){return;} var o=open;open=null; if(o.dialog){if(o.dialog.open){o.dialog.close();}if(o.dialog.parentNode){o.dialog.parentNode.removeChild(o.dialog);}} else if(o.panel&&o.panel.parentNode){o.panel.parentNode.removeChild(o.panel);} trigger.focus(); } function showDialog(){ var d=document.createElement('dialog'); d.className='ableguard-confirm'; d.setAttribute('aria-labelledby','ableguard-confirm-title'); d.setAttribute('aria-describedby','ableguard-confirm-message'); var c=build('ableguard-confirm'); d.appendChild(c.box); (f.closest('.ableguard-wrap')||document.body).appendChild(d); open={dialog:d}; c.cancel.addEventListener('click',close); c.go.addEventListener('click',function(){close();proceed();}); d.addEventListener('click',function(e){if(e.target===d){close();}}); d.addEventListener('close',function(){if(open&&open.dialog===d){open=null;if(d.parentNode){d.parentNode.removeChild(d);}trigger.focus();}}); d.showModal(); c.cancel.focus(); } function showPanel(){ var c=build('ableguard-confirm-inline'); var panel=el('div','ableguard-confirm-inline'); panel.setAttribute('role','group'); panel.setAttribute('aria-labelledby','ableguard-confirm-inline-title'); panel.setAttribute('aria-describedby','ableguard-confirm-inline-message'); panel.appendChild(c.box); f.insertBefore(panel,trigger); open={panel:panel}; c.cancel.addEventListener('click',close); c.go.addEventListener('click',function(){close();proceed();}); c.cancel.focus(); } f.addEventListener('submit',function(e){ if(confirmed){confirmed=false;return;} e.preventDefault(); if(open){return;} if(typeof HTMLDialogElement!=='undefined'&&typeof HTMLDialogElement.prototype.showModal==='function'){showDialog();}else{showPanel();} }); }()); JS; } public static function admin_css() { return <<<'CSS' .ableguard-wrap { max-width: 780px; } .ableguard-brand { display: flex; align-items: baseline; gap: 14px; margin: 8px 0 4px; } .ableguard-brand h1 { font-family: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif; font-size: 30px; font-weight: 600; color: #253238; margin: 0; padding: 0; } .ableguard-brand h1 em { font-style: normal; color: #0B6B67; } .ableguard-brand .tagline { color: #5D6C76; font-size: 13.5px; } .ableguard-card { background: #fff; border: 1px solid #E8E4DB; border-radius: 12px; padding: 20px 24px; margin: 18px 0 0; } .ableguard-status { border-left: 4px solid #2E7D4F; } .ableguard-status.is-off { border-left-color: #8A5A00; } .ableguard-status h2 { margin: 0 0 6px; font-size: 15px; } .ableguard-status p { margin: 4px 0; color: #50575e; } .ableguard-status .ableguard-sync-form { display: inline; } .ableguard-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; } .ableguard-action-form { display: inline; margin: 0; } .ableguard-account strong { color: #253238; word-break: break-all; } .ableguard-manual summary { cursor: pointer; font-weight: 600; color: #253238; } .ableguard-manual[open] summary { margin-bottom: 6px; } .ableguard-card .form-table th { padding-left: 0; } .ableguard-card .submit { padding-bottom: 0; } .ableguard-wrap .button-primary { background: #0B6B67; border-color: #0B6B67; } .ableguard-wrap .button-primary:hover, .ableguard-wrap .button-primary:focus { background: #084E4B; border-color: #084E4B; } .ableguard-confirm { border: 0; border-radius: 4px; padding: 0; width: calc(100% - 32px); max-width: 480px; box-shadow: 0 3px 30px rgba(0, 0, 0, .2); color: #1d2327; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif; } .ableguard-confirm::backdrop { background: rgba(0, 0, 0, .7); } .ableguard-confirm-body { padding: 24px; } .ableguard-confirm-title { margin: 0 0 12px; font-size: 18px; line-height: 1.4; font-weight: 600; } .ableguard-confirm-message { margin: 0 0 24px; font-size: 14px; line-height: 1.5; } .ableguard-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; } .ableguard-wrap .ableguard-confirm .button-link-delete { border: 1px solid #d63638; color: #d63638; background: #fff; text-decoration: none; } .ableguard-wrap .ableguard-confirm .button-link-delete:hover, .ableguard-wrap .ableguard-confirm .button-link-delete:focus { background: #d63638; border-color: #d63638; color: #fff; } .ableguard-confirm-inline { flex-basis: 100%; background: #fff; border: 1px solid #c3c4c7; border-left: 4px solid #d63638; border-radius: 4px; box-shadow: 0 1px 1px rgba(0, 0, 0, .04); margin-bottom: 8px; } .ableguard-confirm-inline .ableguard-confirm-body { padding: 16px 20px; } .ableguard-confirm-inline .ableguard-confirm-title { font-size: 15px; margin-bottom: 6px; } .ableguard-confirm-inline .ableguard-confirm-message { margin-bottom: 12px; } .ableguard-tip { background: #FAF9F6; border: 1px dashed #D8D2C4; border-radius: 12px; padding: 12px 18px; margin-top: 18px; color: #50575e; } .ableguard-tip code { background: #fff; } CSS; } /** * Our settings screen is where owners make accessibility decisions; other * plugins' upsell notices don't belong in that moment. Applies ONLY to the * AbleGuard screen — the rest of wp-admin is untouched. */ public static function suppress_foreign_notices() { $screen = get_current_screen(); if ( $screen && ( '' !== self::$screen_hook ? self::$screen_hook : 'toplevel_page_ableguard' ) === $screen->id ) { remove_all_actions( 'admin_notices' ); remove_all_actions( 'all_admin_notices' ); } } /** "Settings" link on the Plugins list row. */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Settings', 'ableguard-accessibility-toolkit' ) . '' ); return $links; } /** * Only the switch is a registered setting. `options.php` writes every option in the posted * group and sets any field the form left out to empty, so a group holding the credentials * would let any form that shares it rewrite or blank them — and would write them through * 0.3.1's storage. The credentials are saved by the connection store instead. A settings * screen opened before an update still posts them, and `options.php` now ignores them. */ public static function register_settings() { register_setting( 'ableguard', 'ableguard_enabled', array( 'sanitize_callback' => array( __CLASS__, 'sanitize_enabled' ) ) ); } /** * An unticked box posts nothing, so `options.php` saves null. On a fresh install the option does * not exist and the default is on, and updating a missing option to a false value writes nothing, * so the box stayed on. The row is created here so the unticked state is stored; `add_option()` * does nothing when the row already exists. */ public static function sanitize_enabled( $value ) { $enabled = rest_sanitize_boolean( $value ); static $creating = false; if ( ! $enabled && ! $creating ) { $creating = true; add_option( 'ableguard_enabled', false, '', false ); $creating = false; } return $enabled; } public static function handle_sync() { if ( ! current_user_can( 'manage_options' ) || ! check_admin_referer( 'ableguard_sync' ) ) { wp_die( esc_html__( 'Not allowed.', 'ableguard-accessibility-toolkit' ) ); } $result = AbleGuard_Api_Client::sync_rules(); set_transient( self::sync_notice_key(), is_wp_error( $result ) ? $result->get_error_message() : 'ok', MINUTE_IN_SECONDS ); wp_safe_redirect( admin_url( 'admin.php?page=ableguard' ) ); exit; } /** * The result of the last "Sync now" press is handed to the next page load in * a short-lived, per-user transient rather than in the address, so the screen * never prints text that arrived in a URL. */ private static function sync_notice_key() { return 'ableguard_sync_notice_' . get_current_user_id(); } public static function render_page() { // Read directly, not from the request's snapshot: this is a control path, and it shows // what pages apply (the delivery counts only while it belongs to the connection). $view = AbleGuard_Connect_Store::view_direct(); $rules = $view['rules']; $last_sync = $view['last_sync']; $statement = $view['statement_html']; $enabled = (bool) get_option( 'ableguard_enabled', true ); $api_url = ableguard_api_origin( $view['api_url'] ); $refused = '' !== $view['api_url'] && '' === $api_url; $configured = '' !== $api_url && $view['has_connection']; $denied = $configured && AbleGuard_Api_Client::connection_was_refused( $view['generation'] ); $connected = $configured && $last_sync > 0; // The label is a masked address that any plugin could have written into the options table, // so it is checked again here, and printed escaped like everything else. $account = $view['has_connection'] && AbleGuard_Connect::valid_account_label( $view['account'] ) ? $view['account'] : ''; $flow = AbleGuard_Connect::take_notice(); $flow = null === $flow ? null : AbleGuard_Connect::notice_view( $flow ); $synced = get_transient( self::sync_notice_key() ); if ( false !== $synced ) { delete_transient( self::sync_notice_key() ); } $synced = false === $synced ? '' : (string) $synced; ?>
' . esc_html( $account ) . '' ); ?>