( isset( $input['guest_mode'] ) && 'deny' === $input['guest_mode'] ) ? 'deny' : 'allow', 'allow' => self::patterns( isset( $input['guest_allow'] ) ? $input['guest_allow'] : '' ), 'deny' => self::patterns( isset( $input['guest_deny'] ) ? $input['guest_deny'] : '' ), ); } if ( 'role' === $section ) { $role = isset( $input['role'] ) ? sanitize_key( $input['role'] ) : ''; $roles = wp_roles()->get_names(); if ( '' !== $role && 'administrator' !== $role && isset( $roles[ $role ] ) ) { $mode = isset( $input['role_mode'] ) ? (string) $input['role_mode'] : 'none'; if ( in_array( $mode, array( 'allow', 'deny' ), true ) ) { $out['roles'][ $role ] = array( 'default' => $mode, 'allow' => self::patterns( isset( $input['role_allow'] ) ? $input['role_allow'] : '' ), 'deny' => self::patterns( isset( $input['role_deny'] ) ? $input['role_deny'] : '' ), ); } else { unset( $out['roles'][ $role ] ); } } } if ( 'learn' === $section ) { $out['learn'] = ! empty( $input['learn'] ); } return $out; } /** * Route patterns from a textarea: one per line, # starts a comment. * * @param string $text Text. * @return array */ public static function patterns( $text ) { $out = array(); foreach ( (array) preg_split( '/\R/', (string) $text ) as $line ) { $line = trim( preg_replace( '#]*>#i', '', (string) $line ) ); $line = trim( wp_strip_all_tags( $line ) ); if ( '' === $line || '#' === $line[0] ) { continue; } $line = preg_replace( '#[^A-Za-z0-9_\-./*]#', '', $line ); if ( '' === trim( (string) $line, '/' ) ) { continue; } $out[] = '/' . ltrim( (string) $line, '/' ); } return array_values( array_unique( $out ) ); } }