ID; $status = 'new'; if ( isset( $_GET['post'] ) ) { $status = 'edit'; } if ( $post_ID && am_in_post_type( $post_ID ) ) { $control = ''; if ( current_user_can( 'manage_options' ) ) { $control = "

"; } else { $settings = get_option( 'am_settings' ); $notify = ( isset( $settings['am_notify'] ) && is_email( $settings['am_notify'] ) ); if ( $notify ) { $control = ' ' . "

"; } } echo '
' . $control . '
'; } } /** * JS that executes when 'Publish' pressed and only executes the command if Tenon results pass. */ add_action( 'admin_enqueue_scripts', 'am_pre_publish' ); function am_pre_publish( $hook ) { global $post; $options = get_option( 'am_settings' ); $check = isset( $options['tenon_pre_publish'] ) ? $options['tenon_pre_publish'] : 0; $args = isset( $options['am_criteria'] ) ? $options['am_criteria'] : array(); if ( $check == 1 ) { if ( $hook == 'post-new.php' || $hook == 'post.php' ) { if ( am_in_post_type( $post->ID ) ) { wp_enqueue_script( 'tenon.inspector', plugins_url( 'js/inspector.js', __FILE__ ), array( 'jquery' ), '', true ); $settings = array( 'level' => ( isset( $args['level'] ) ) ? $args['level'] : 'AA', 'certainty' => ( isset( $args['certainty'] ) ) ? $args['certainty'] : '60', 'priority' => ( isset( $args['priority'] ) ) ? $args['priority'] : '20', 'container' => ( isset( $args['container'] ) && !empty( $args['container'] ) ) ? $args['container'] : '.access-monitor-content', 'store' => ( isset( $args['store'] ) ) ? $args['store'] : '0', 'grade' => ( isset( $args['grade'] ) ) ? $args['grade'] : '90', 'hide' => __( 'Hide issues', 'access-monitor' ), 'show' => __( 'Show issues', 'access-monitor' ), 'failed' => __( 'Could not retrieve content from your content area. Set your content container in Access Monitor settings.', 'access-monitor' ), 'error' => __( 'Post may not be published: does not meet minimum accessibility requirements.', 'access-monitor' ), 'pass' => __( 'Post may be published!: meets your accessibility requirements.', 'access-monitor' ), 'ajaxerror' => __( 'There was an error sending your post to Tenon.io.', 'access-monitor' ) ); wp_localize_script( 'tenon.inspector', 'am', $settings ); wp_localize_script( 'tenon.inspector', 'am_ajax_notify', 'am_ajax_notify' ); $user_ID = get_current_user_ID(); $post_ID = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : false; $security = wp_create_nonce( 'am_notify_admin' ); $notify = array( 'user' => $user_ID, 'post_ID' => $post_ID, 'security' => $security, 'error' => __( "Accessibility Review Request failed to send.", 'access-monitor' ) ); wp_localize_script( 'tenon.inspector', 'amn', $notify ); } } } } /** * Check whether a given post is in an allowed post type and has an update template configured. * * @param integer $id Post ID. * * @return boolean True if post is allowed, false otherwise. */ function am_in_post_type( $id ) { $settings = get_option( 'am_settings' ); $post_type_settings = isset( $settings['am_post_types'] ) ? $settings['am_post_types'] : array(); if ( is_array( $post_type_settings ) && !empty( $post_type_settings ) ) { $type = get_post_type( $id ); if ( in_array( $type, $post_type_settings ) ) { return true; } } return false; } /** * Add hidden notice to post edit page. */ add_action( 'edit_form_top', 'am_edit_form_after_title' ); function am_edit_form_after_title( $post ) { if ( am_in_post_type( $post->ID ) ) { echo '

' . sprintf( __( 'Score: %s / %s %s', 'access-monitor' ), '', '', '' ) . "

"; } } /** * Generate percentage grade for page. * For now, use overall error density scoring. Later, add error-specific exits. */ function am_percentage( $results ) { $status = $results->status; if ( $status == 200 ) { $stats = $results->globalStats; $max = $stats->allDensity + (3 * $stats->stdDev); // test against all errors & warnings $score = $results->resultSummary->density->allDensity; /* Alternate scoring options to be added in future releases // test against errors only $score = $results->resultSummary->density->errorDensity; // test against error count only $score = $results->resultSummary->issues->totalErrors; // test against error count by class $scoreA = $results->resultSummary->issuesByLevel->A->count; $scoreAA = $results->resultSummary->issuesByLevel->AA->count; $scoreAAA = $results->resultSummary->issuesByLevel->AAA->count; */ $min = 0; if ( $score > $max ) { $return = 0; } else if ( $score <= $min ) { $return = 100; } else { $return = 100 - (( $score / $max ) * 100 ); } } else { $return = false; } return apply_filters( 'am_modify_grade', $return, $results ); } add_action('wp_ajax_am_ajax_notify', 'am_ajax_notify'); function am_ajax_notify() { if ( isset( $_REQUEST['security'] ) ) { if ( ! check_ajax_referer( 'am_notify_admin', 'security', false ) ) { wp_send_json( array( 'response' => 0, 'message' => __( 'Invalid Security Check', 'access-monitor' ) ) ); } else { $settings = get_option( 'am_settings' ); $notify = ( isset( $settings['am_notify'] ) && is_email( $settings['am_notify'] ) ); if ( $notify ) { $email = $settings['am_notify']; $post_ID = $_REQUEST['post_ID']; $user_ID = $_REQUEST['user']; $post = get_post( $post_ID ); $user = get_user_by( 'id', $user_ID ); $edit_link = get_edit_post_link( $post_ID ); $body = sprintf( __( 'Accessibility review on "%s" requested by %s. Review post: %s', 'access-monitor' ), $post->post_title, $user->user_login, $edit_link ); $notice = wp_mail( $email, __( 'Request for Accessibility Review', 'access-monitor' ), $body ); wp_send_json( array( 'response' => 1, 'message' => __( 'Review request sent!', 'access-monitor' ) ) ); } else { wp_send_json( array( 'response' => 0, 'message' => __( 'Invalid Email provided for accessibility reviewer', 'access-monitor' ) ) ); } } } } /** * If custom value is not set for Access Monitor content container, add independent container and test that. */ add_filter( 'the_content', 'am_testable_post_content' ); function am_testable_post_content( $content ) { global $post; if ( am_in_post_type( $post->ID ) ) { $options = get_option( 'am_settings' ); $args = isset( $options['am_criteria'] ) ? $options['am_criteria'] : array(); $test = ( isset( $options['tenon_pre_publish'] ) && $options['tenon_pre_publish'] == 1 ) ? true : false; $container = isset( $args['container'] ) ? $args['container'] : false; if ( $test ) { if ( !$container || $container == '.access-monitor-content' ) { $content = '
' . $content . '
'; } } } return $content; }