register_hooks(); } return self::$instance; } /** * Register hooks. */ private function register_hooks() { add_action( 'admin_menu', array( $this, 'add_submenu' ) ); add_action( 'wp_ajax_wpag_generate_statement', array( $this, 'ajax_generate_statement' ) ); } /** * Add the statement submenu page. */ public function add_submenu() { add_submenu_page( 'wpag-dashboard', __( 'Accessibility Statement', 'accessibility-guard' ), __( 'Statement', 'accessibility-guard' ), 'manage_options', 'wpag-statement', array( $this, 'render_page' ) ); } /** * Render the statement admin page. */ public function render_page() { $settings = get_option( 'wpag_settings', wpag_default_settings() ); $page_id = ! empty( $settings['statement_page_id'] ) ? absint( $settings['statement_page_id'] ) : 0; $page = $page_id ? get_post( $page_id ) : null; ?>

post_title ); ?> —

generate_statement_html( $settings ) ); ?>
__( 'Unauthorized.', 'accessibility-guard' ) ) ); } $settings = get_option( 'wpag_settings', wpag_default_settings() ); // Update statement settings. // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized below. $settings['statement_org_name'] = isset( $_POST['org_name'] ) ? sanitize_text_field( wp_unslash( $_POST['org_name'] ) ) : ''; $settings['statement_email'] = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; $settings['statement_conformance'] = isset( $_POST['conformance'] ) ? sanitize_text_field( wp_unslash( $_POST['conformance'] ) ) : 'AA'; $settings['statement_limitations'] = isset( $_POST['limitations'] ) ? sanitize_textarea_field( wp_unslash( $_POST['limitations'] ) ) : ''; // phpcs:enable $html = $this->generate_statement_html( $settings ); $page_id = ! empty( $settings['statement_page_id'] ) ? absint( $settings['statement_page_id'] ) : 0; if ( $page_id && get_post( $page_id ) ) { // Update existing page. wp_update_post( array( 'ID' => $page_id, 'post_content' => $html, ) ); $message = __( 'Accessibility statement page updated.', 'accessibility-guard' ); } else { // Create new page. $page_id = wp_insert_post( array( 'post_title' => __( 'Accessibility Statement', 'accessibility-guard' ), 'post_content' => $html, 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'accessibility-statement', ) ); if ( is_wp_error( $page_id ) ) { wp_send_json_error( array( 'message' => $page_id->get_error_message() ) ); } $settings['statement_page_id'] = $page_id; $message = __( 'Accessibility statement page created.', 'accessibility-guard' ); } update_option( 'wpag_settings', $settings ); wp_send_json_success( array( 'message' => $message, 'page_id' => $page_id, 'url' => get_permalink( $page_id ), ) ); } /** * Generate the accessibility statement HTML. * * @param array $settings Plugin settings. * @return string HTML content. */ public function generate_statement_html( $settings ) { $org_name = ! empty( $settings['statement_org_name'] ) ? $settings['statement_org_name'] : get_bloginfo( 'name' ); $email = ! empty( $settings['statement_email'] ) ? $settings['statement_email'] : get_option( 'admin_email' ); $conformance = ! empty( $settings['statement_conformance'] ) ? $settings['statement_conformance'] : 'AA'; $limitations = ! empty( $settings['statement_limitations'] ) ? $settings['statement_limitations'] : ''; $site_url = home_url(); $date = current_time( 'F j, Y' ); $html = '

' . esc_html__( 'Accessibility Statement', 'accessibility-guard' ) . '

'; $html .= '

' . sprintf( /* translators: 1: organization name, 2: site URL */ esc_html__( '%1$s is committed to ensuring digital accessibility for people with disabilities. We are continually improving the user experience for everyone, and applying the relevant accessibility standards.', 'accessibility-guard' ), '' . esc_html( $org_name ) . '' ) . '

'; $html .= '

' . esc_html__( 'Conformance Status', 'accessibility-guard' ) . '

'; $html .= '

' . sprintf( /* translators: 1: site URL, 2: WCAG level */ esc_html__( 'The Web Content Accessibility Guidelines (WCAG) defines requirements for designers and developers to improve accessibility for people with disabilities. It defines three levels of conformance: Level A, Level AA, and Level AAA. %1$s is partially conformant with WCAG 2.2 Level %2$s.', 'accessibility-guard' ), '' . esc_html( $org_name ) . '', esc_html( $conformance ) ) . '

'; if ( $limitations ) { $html .= '

' . esc_html__( 'Known Limitations', 'accessibility-guard' ) . '

'; $html .= '

' . esc_html__( 'Despite our best efforts, some areas may not yet be fully accessible:', 'accessibility-guard' ) . '

'; $html .= ''; } $html .= '

' . esc_html__( 'Feedback', 'accessibility-guard' ) . '

'; $html .= '

' . sprintf( /* translators: %s: contact email */ esc_html__( 'We welcome your feedback on the accessibility of this website. If you encounter accessibility barriers, please contact us at %s.', 'accessibility-guard' ), '' . esc_html( $email ) . '' ) . '

'; $html .= '

' . esc_html__( 'Assessment Approach', 'accessibility-guard' ) . '

'; $html .= '

' . esc_html__( 'This website is assessed using the Accessibility Guard plugin, which performs automated WCAG 2.2 scanning and provides remediation guidance.', 'accessibility-guard' ) . '

'; $html .= '

' . sprintf( /* translators: %s: date */ esc_html__( 'This statement was last updated on %s.', 'accessibility-guard' ), esc_html( $date ) ) . '

'; return $html; } }