id || ! current_user_can( self::CAP ) || ! get_option( self::WELCOME ) ) { return; } $dismiss = wp_nonce_url( admin_url( 'admin-post.php?action=alexibility_fixes_dismiss' ), 'alexibility_fixes_dismiss' ); echo '

' . esc_html__( 'Alexibility Fixes is active.', 'alexibility-fixes' ) . ' ' . esc_html__( 'Take a quick look at your images and PDFs, and get a free scan of your site', 'alexibility-fixes' ) . '' . ' | ' . esc_html__( 'Dismiss', 'alexibility-fixes' ) . '

'; } public static function dismiss() { if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'alexibility-fixes' ), 403 ); } check_admin_referer( 'alexibility_fixes_dismiss' ); delete_option( self::WELCOME ); wp_safe_redirect( admin_url( 'plugins.php' ) ); exit; } /** On the plugin's own page only: the badge's CSS, for the preview in Settings. */ public static function enqueue_styles( $hook_suffix ) { if ( 'tools_page_' . self::SLUG !== $hook_suffix ) { return; } Alexibility_Render::inline_style( 'alexibility-fixes-admin', Alexibility_Render::badge_css() . '.alexibility-fixes-badge-preview{max-width:420px;margin-top:8px;background:#f0f0f1;border-radius:4px}' ); } public static function menu() { add_management_page( __( 'Accessibility Fixes', 'alexibility-fixes' ), __( 'Accessibility Fixes', 'alexibility-fixes' ), self::CAP, self::SLUG, array( __CLASS__, 'render' ) ); } private static function page_url() { return admin_url( 'tools.php?page=' . self::SLUG ); } private static function notice( $type, $message ) { set_transient( 'alexibility_fixes_notice_' . get_current_user_id(), array( 'type' => $type, 'message' => $message ), 60 ); } /** One handler for every form on the page; each action has its own nonce. */ public static function handle() { $do = isset( $_POST['do'] ) ? sanitize_key( wp_unslash( $_POST['do'] ) ) : ''; if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'alexibility-fixes' ), 403 ); } check_admin_referer( 'alexibility_fixes_' . $do ); switch ( $do ) { case 'upload': $file = $_FILES['plan'] ?? null; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- validated below. if ( ! $file || UPLOAD_ERR_OK !== $file['error'] || ! is_uploaded_file( $file['tmp_name'] ) || $file['size'] > 5 * MB_IN_BYTES ) { self::notice( 'error', __( 'Choose the fixes.json file to upload (5 MB at most).', 'alexibility-fixes' ) ); break; } // Read in place; the file is never stored in uploads where it could be fetched. $plan = Alexibility_Plan::from_json( (string) file_get_contents( $file['tmp_name'] ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions if ( is_wp_error( $plan ) ) { self::notice( 'error', $plan->get_error_message() ); break; } Alexibility_Plan::save( $plan ); /* translators: %d: number of fixes */ self::notice( 'success', sprintf( _n( 'Loaded %d approved fix. Review it below, then apply.', 'Loaded %d approved fixes. Review them below, then apply.', count( $plan['fixes'] ), 'alexibility-fixes' ), count( $plan['fixes'] ) ) ); break; case 'apply': $run = Alexibility_Content::apply( Alexibility_Plan::approved() ); update_option( Alexibility_Render::ENABLED, true ); $message = sprintf( /* translators: %d: number of changes */ _n( 'Applied: %d content change saved, and theme-level fixes are on.', 'Applied: %d content changes saved, and theme-level fixes are on.', count( $run['changes'] ), 'alexibility-fixes' ), count( $run['changes'] ) ); if ( $run['failed'] ) { /* translators: %s: list of problems */ $message .= ' ' . sprintf( __( 'Not saved: %s.', 'alexibility-fixes' ), implode( '; ', array_map( function ( $id, $why ) { return get_the_title( $id ) . ' (' . $why . ')'; }, array_keys( $run['failed'] ), $run['failed'] ) ) ); } self::notice( $run['failed'] ? 'warning' : 'success', $message ); break; case 'rollback': $result = Alexibility_Content::rollback( isset( $_POST['run'] ) ? sanitize_text_field( wp_unslash( $_POST['run'] ) ) : '' ); if ( is_wp_error( $result ) ) { self::notice( 'error', $result->get_error_message() ); break; } update_option( Alexibility_Render::ENABLED, false ); /* translators: %d: number of changes restored */ $message = sprintf( __( 'Rolled back %d change(s) and switched theme-level fixes off.', 'alexibility-fixes' ), $result['restored'] ); if ( $result['skipped'] ) { /* translators: %s: list of items */ $message .= ' ' . sprintf( __( 'Left alone because they changed since: %s.', 'alexibility-fixes' ), implode( ', ', $result['skipped'] ) ); } self::notice( $result['skipped'] ? 'warning' : 'success', $message ); break; case 'pdf-rollback': $result = Alexibility_Pdfs::rollback( isset( $_POST['run'] ) ? sanitize_text_field( wp_unslash( $_POST['run'] ) ) : '' ); if ( is_wp_error( $result ) ) { self::notice( 'error', $result->get_error_message() ); break; } /* translators: %d: number of PDF files restored */ $message = sprintf( _n( 'Put back %d original PDF.', 'Put back %d original PDFs.', $result['restored'], 'alexibility-fixes' ), $result['restored'] ); if ( $result['skipped'] ) { /* translators: %s: list of files */ $message .= ' ' . sprintf( __( 'Left alone: %s.', 'alexibility-fixes' ), implode( ', ', $result['skipped'] ) ); } self::notice( $result['skipped'] ? 'warning' : 'success', $message ); break; case 'settings': update_option( Alexibility_Render::ENABLED, ! empty( $_POST['render'] ) ); // '0'/'1' rather than false/true: update_option() skips saving false when the option doesn't exist // yet, so a string always records the site's own choice. update_option( Alexibility_Render::CREDIT, empty( $_POST['credit'] ) ? '0' : '1' ); update_option( Alexibility_Render::CREDIT_URL, isset( $_POST['credit_url'] ) ? esc_url_raw( wp_unslash( $_POST['credit_url'] ) ) : '' ); self::notice( 'success', __( 'Settings saved.', 'alexibility-fixes' ) ); break; } wp_safe_redirect( self::page_url() ); exit; } private static function form_open( $do ) { echo '
'; echo ''; wp_nonce_field( 'alexibility_fixes_' . $do ); } /** * @param array $content_results Places each fix would still change (from a dry run). * @param array $applied Places each fix changed in the latest run that wasn't rolled back. */ private static function describe( $fix, $content_results, $applied ) { switch ( $fix['kind'] ) { case 'image-alt': case 'accessible-name': $where = $content_results[ $fix['id'] ] ?? array(); if ( 'image-alt' === $fix['kind'] ) { $value = $fix['decorative'] ? __( 'decorative (alt="")', 'alexibility-fixes' ) : '"' . $fix['alt'] . '"'; } else { $value = empty( $fix['decorative'] ) ? '"' . $fix['name'] . '"' : __( 'hidden from screen readers (aria-hidden)', 'alexibility-fixes' ); } if ( ! $where && ! empty( $applied[ $fix['id'] ] ) ) { /* translators: 1: value, 2: list of places */ return sprintf( __( 'Applied: %1$s is set in %2$s.', 'alexibility-fixes' ), $value, implode( ', ', $applied[ $fix['id'] ] ) ); } $prefix = $where /* translators: 1: value, 2: list of places */ ? sprintf( __( 'Sets %1$s in: %2$s.', 'alexibility-fixes' ), $value, implode( ', ', $where ) ) /* translators: %s: value */ : sprintf( __( 'Not in saved content; sets %s where the theme outputs it.', 'alexibility-fixes' ), $value ); return $prefix; case 'set-lang': /* translators: %s: language code */ return sprintf( __( 'Adds lang="%s" to pages that lack it.', 'alexibility-fixes' ), $fix['lang'] ); case 'contrast-color': /* translators: 1: old color, 2: new color, 3: selectors */ return sprintf( __( 'Text color %1$s becomes %2$s on: %3$s', 'alexibility-fixes' ), $fix['fg'], $fix['replacement'], implode( ', ', $fix['selectors'] ) ); case 'focus-visible': /* translators: %s: selector */ return sprintf( __( 'Visible focus outline on %s.', 'alexibility-fixes' ), $fix['selector'] ); case 'skip-link': return __( 'Adds a "Skip to content" link unless the theme already has one.', 'alexibility-fixes' ); case 'css-repair': $declarations = array(); foreach ( $fix['css'] as $property => $value ) { $declarations[] = $property . ': ' . $value; } /* translators: 1: CSS declarations, 2: selector */ return sprintf( __( 'Sets %1$s on %2$s.', 'alexibility-fixes' ), implode( '; ', $declarations ), $fix['selector'] ); case 'attr-repair': $changes = array(); foreach ( $fix['remove'] as $attribute ) { /* translators: %s: attribute name */ $changes[] = sprintf( __( 'removes %s', 'alexibility-fixes' ), $attribute ); } foreach ( $fix['set'] as $attribute => $value ) { /* translators: 1: attribute name, 2: value */ $changes[] = sprintf( __( 'sets %1$s="%2$s"', 'alexibility-fixes' ), $attribute, $value ); } foreach ( $fix['style'] as $property => $value ) { /* translators: 1: CSS property, 2: value */ $changes[] = sprintf( __( 'adds %1$s: %2$s to its style', 'alexibility-fixes' ), $property, $value ); } /* translators: 1: CSS selector, 2: list of changes */ return sprintf( __( 'On %1$s as pages are output: %2$s.', 'alexibility-fixes' ), alexibility_fixes_match_selector( $fix['match'] ), implode( ', ', $changes ) ); } return ''; } /** For a site that isn't working with Alexibility yet: what the plugin does, a quick check, and the free scan. */ private static function render_start() { $check = Alexibility_Check::results(); $found = array(); if ( $check['images'] ) { $found[] = $check['images_no_alt'] ? sprintf( /* translators: 1: images without a description, 2: all images */ _n( '%1$d of the %2$d images in your media library has no description (alt text).', '%1$d of the %2$d images in your media library have no description (alt text).', $check['images_no_alt'], 'alexibility-fixes' ), $check['images_no_alt'], $check['images'] ) . ' ' . __( 'Screen readers skip an image like that or read out its file name, so people who can\'t see it miss what it shows.', 'alexibility-fixes' ) : sprintf( /* translators: %d: number of images */ _n( 'Your media library has %d image, and it has a description (alt text).', 'All %d images in your media library have a description (alt text).', $check['images'], 'alexibility-fixes' ), $check['images'] ); } if ( $check['content_items'] ) { $found[] = $check['content_no_alt'] ? sprintf( /* translators: 1: images, 2: pages and posts */ _n( '%1$d image in your published content has no alt attribute at all, on %2$d page or post.', '%1$d images in your published content have no alt attribute at all, on %2$d pages and posts.', $check['content_no_alt'], 'alexibility-fixes' ), $check['content_no_alt'], $check['content_with_problem'] ) : __( 'Every image in your published pages and posts has an alt attribute.', 'alexibility-fixes' ); } if ( $check['pdfs'] ) { $found[] = sprintf( /* translators: %d: number of PDF files */ _n( 'Your media library has %d PDF file.', 'Your media library has %d PDF files.', $check['pdfs'], 'alexibility-fixes' ), $check['pdfs'] ) . ' ' . __( 'A screen reader can only read a PDF properly when it has tags, a title and a language; the full scan checks each one.', 'alexibility-fixes' ); } ?>

sprintf( __( 'Roll back the run from %s', 'alexibility-fixes' ), $run['time'] ) ) ); ?>

sprintf( __( 'Put back the original PDFs replaced on %s', 'alexibility-fixes' ), $run['time'] ) ) ); ?>