isset( $saved['post_types'] ) && is_array( $saved['post_types'] ) ? array_values( array_map( 'sanitize_key', $saved['post_types'] ) ) : array(), 'max_pages' => isset( $saved['max_pages'] ) ? max( 1, min( 2000, (int) $saved['max_pages'] ) ) : 200, 'skip_rules' => isset( $saved['skip_rules'] ) && is_array( $saved['skip_rules'] ) ? array_values( array_map( 'sanitize_key', $saved['skip_rules'] ) ) : array(), 'auto' => isset( $saved['auto'] ) ? (bool) $saved['auto'] : true, ); } /** * @param array $input Submitted values. */ public static function save( array $input ) { $public = get_post_types( array( 'public' => true ), 'names' ); unset( $public['attachment'] ); $types = isset( $input['post_types'] ) && is_array( $input['post_types'] ) ? array_values( array_intersect( array_map( 'sanitize_key', $input['post_types'] ), $public ) ) : array(); $rules = isset( $input['skip_rules'] ) && is_array( $input['skip_rules'] ) ? array_values( array_intersect( array_map( 'sanitize_key', $input['skip_rules'] ), array_keys( Accesswell_Rules::all() ) ) ) : array(); update_option( self::OPTION, array( 'post_types' => count( $types ) === count( $public ) ? array() : $types, 'max_pages' => isset( $input['max_pages'] ) ? max( 1, min( 2000, (int) $input['max_pages'] ) ) : 200, 'skip_rules' => $rules, 'auto' => ! empty( $input['auto'] ), ), false ); } /** * Post types the site scan visits. * * @return array */ public static function post_types() { $public = get_post_types( array( 'public' => true ), 'names' ); unset( $public['attachment'] ); $chosen = self::get()['post_types']; return $chosen ? array_values( array_intersect( $chosen, $public ) ) : array_values( $public ); } // ------------------------------------------------------------------ // Ignored issues // ------------------------------------------------------------------ /** * Key of an ignored issue. With no path it applies to every page (for * example a footer that appears everywhere). * * @param string $rule Rule ID. * @param string $selector CSS path of the element. * @param string $path Page path, or '' for every page. * @return string */ public static function ignore_key( $rule, $selector, $path ) { return md5( $rule . '|' . $selector . '|' . $path ); } /** * @return array Key => { rule, selector, path, snippet, user, time }. */ public static function ignored() { $all = get_option( self::IGNORE_OPTION, array() ); return is_array( $all ) ? $all : array(); } /** * @param array $issue { rule, selector, path, snippet }. */ public static function ignore( array $issue ) { $all = self::ignored(); $key = self::ignore_key( $issue['rule'], $issue['selector'], $issue['path'] ); $all[ $key ] = array( 'rule' => $issue['rule'], 'selector' => $issue['selector'], 'path' => $issue['path'], 'snippet' => $issue['snippet'], 'user' => get_current_user_id(), 'time' => time(), ); update_option( self::IGNORE_OPTION, $all, false ); return $key; } /** * @param string $key Ignore key. */ public static function unignore( $key ) { $all = self::ignored(); unset( $all[ $key ] ); update_option( self::IGNORE_OPTION, $all, false ); } /** * Whether an issue on a page is ignored. * * @param array $issue Issue with rule and selector. * @param string $path Page path. * @param array $all Ignored list. * @return bool */ public static function is_ignored( $issue, $path, $all ) { return isset( $all[ self::ignore_key( $issue['rule'], $issue['selector'], $path ) ] ) || isset( $all[ self::ignore_key( $issue['rule'], $issue['selector'], '' ) ] ); } }