Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper function is_allowed_cookie() does inexact match #169

Open
wizzud opened this issue Jun 4, 2018 · 1 comment
Open

Helper function is_allowed_cookie() does inexact match #169

wizzud opened this issue Jun 4, 2018 · 1 comment

Comments

@wizzud
Copy link

wizzud commented Jun 4, 2018

Change function to (something along the lines of) ...

function is_allowed_cookie( $cookie_name, $exactMatch = false ) {
	if ( isset( $_COOKIE['gdpr']['allowed_cookies'] ) ) {
		$allowed_cookies = array_map( 
			'sanitize_text_field',
			json_decode(
				wp_unslash( $_COOKIE['gdpr']['allowed_cookies'] ),
				true
			)
		);
		if ( in_array( $cookie_name, $allowed_cookies, true ) ) {
			return true;
		}
		if ( ! $exactMatch ) {
			$name = preg_quote( $cookie_name, '~' );
			$result = preg_grep( '~' . $name . '~', $allowed_cookies );
			return ! empty( $result );
		}
	}

	return false;
}

Note : the above is suggested without reference/regard to any other Issue raised, and is merely - without changing the functionality of existing calls to the helper - a way for developers to be able to determine an exact match for, say, '_ga' (by calling is_allowed_cookie('_ga', true);), and not risk a false match against 'online_gaming' (a made-up 'for instance'!).

@fclaussen
Copy link
Member

That's a good suggestion.
Can you submit this as a pull request?

For your other suggestion for checking for categories, I will add as a new function so we don't break thousands of sites when changing from cookie to category based checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants