register_ajax_handlers(); } /** * Summary Ajax * * @return void * * - '-1' means that nonce could not be varified * - '-2' means that the post ID was not specified * - '-3' means that there isn't any summary data to return * - '-5' means that the user does not have permission to view this information for this post */ public function summary() { // nonce security. if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['nonce'] ) ), 'ajax-nonce' ) ) { wp_send_json_error( new \WP_Error( '-1', __( 'Permission Denied', 'accessibility-checker' ) ) ); } if ( ! isset( $_REQUEST['post_id'] ) ) { wp_send_json_error( new \WP_Error( '-2', __( 'The post ID was not set', 'accessibility-checker' ) ) ); } if ( ! current_user_can( 'edit_post', (int) $_REQUEST['post_id'] ) ) { wp_send_json_error( new \WP_Error( '-5', __( 'You do not have permission to view this information for this post.', 'accessibility-checker' ) ) ); } $html = []; $html['content'] = ''; $post_id = (int) $_REQUEST['post_id']; $summary = ( new Summary_Generator( $post_id ) )->generate_summary(); $simplified_summary_text = ''; $simplified_summary_prompt = get_option( 'edac_simplified_summary_prompt' ); $simplified_summary = get_post_meta( $post_id, '_edac_simplified_summary', true ) ? get_post_meta( $post_id, '_edac_simplified_summary', true ) : ''; $simplified_summary_grade = 0; if ( class_exists( 'DaveChild\TextStatistics\TextStatistics' ) ) { $text_statistics = new \DaveChild\TextStatistics\TextStatistics(); $simplified_summary_grade = (int) floor( $text_statistics->fleschKincaidGradeLevel( $simplified_summary ) ); } $simplified_summary_grade_failed = ( $simplified_summary_grade > 9 ) ? true : false; $simplified_summary_text = esc_html__( 'A Simplified summary has not been included for this content.', 'accessibility-checker' ); if ( 'none' !== $simplified_summary_prompt ) { if ( $summary['content_grade'] <= 9 ) { $simplified_summary_text = esc_html__( 'Your content has a reading level at or below 9th grade and does not require a simplified summary.', 'accessibility-checker' ); } elseif ( $summary['simplified_summary'] ) { if ( $simplified_summary_grade_failed ) { $simplified_summary_text = esc_html__( 'The reading level of the simplified summary is too high.', 'accessibility-checker' ); } else { $simplified_summary_text = esc_html__( 'A simplified summary has been included for this content.', 'accessibility-checker' ); } } } $html['content'] .= '
' . esc_html( $row['object'] ) . '';
$html .= 'Your post has a reading level higher than 9th grade. Web Content Accessibility Guidelines (WCAG) at the AAA level require a simplified summary of your post that is 9th grade or below.
'; } elseif ( 0 === $post_grade ) { $html .= 'Your post does not contain enough content to calculate its reading level.
'; } else { $html .= 'A simplified summary is not necessary when content reading level is 9th grade or below. Choose when to prompt for a simplified summary on the settings page.
'; } $html .= '' . esc_html__( 'Not enough content to determine an accurate reading level.', 'accessibility-checker' ) . '
' . ( ( $simplified_summary_grade_failed ) ? esc_html__( 'Your simplified summary has a reading level above 9th grade.', 'accessibility-checker' ) : esc_html__( 'Your simplified summary has a reading level at or below 9th grade.', 'accessibility-checker' ) ) . '
Your Prompt for Simplified Summary is set to "never." If you would like the simplified summary to be displayed automatically, you can change this on the settings page.
Set where the Simplified Summary is inserted into the content on the settings page.
Your Simplified Summary location is set to "manually" which requires a function be added to your page template. If you would like the simplified summary to be displayed automatically, you can change this on the settings page.