Support » Plugin: Math Captcha » Set cookies only when user allows use of cookies

  • Can you please check whether cookies are allowed to be set before you create cookies.

    In my case I use Cookie Notice Plugin which provides a feature detection and integration whether the user agreed to the usage of cookies.

    Function to call: cn_cookies_accepted() === true

    method_exists(‘cn_cookies_accepted’) will help with detection whether cookie_notice is available.

    It would be awesome if you would support “Cookie notice” from dfactory as it has 600k+ installations and is likely the most used plugin.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Here are my changes to /wp-math-captcha/includes/class-cookie-session.php

    Function ‘init_session’

    After:

    if ( is_admin () )
    return;

    // CHANGE START – Check if cookies are allowed
    if (function_exists(‘cn_cookies_accepted’) === true
    && cn_cookies_accepted() !== true
    )
    {
    return;
    }
    // CHANGE END

    Doesn’t work for me, unfortunately. A sustainable solution would be great, means a plugin update.

    If you use caching plugins in WordPress, this will most likely not work.

    In my case, the optin setting is cached as well. So the generated html code in the template is from the cache and not on a per user base.

    Try to turn caching plugin off if you have any active plugin. Then check the result again.

    There’s no caching plugin installed or active. Maybe another reason?

    Just to be sure if I did the changes right. The crucial part of the code for class-cookie-session.php looks like this now:

    
    	/**
    	 * Initialize cookie-session.
    	 */
    	public function init_session() {
    		if ( is_admin() )
    			return;
    
    	// CHANGE START – Check if cookies are allowed
    	if (function_exists(‘cn_cookies_accepted’) === true
    	&& cn_cookies_accepted() !== true
    	)
    	{
    	return;
    	}
    	// CHANGE END
    
    		if ( isset( $_COOKIE['mc_session_ids'] ) )
    			$this->session_ids = $_COOKIE['mc_session_ids'];
    		else {
    			foreach ( array( 'default', 'multi' ) as $place ) {
    				switch ( $place ) {
    					case 'multi':
    						for ( $i = 0; $i < 5; $i ++  ) {
    							$this->session_ids[$place][$i] = sha1( $this->generate_password() );
    						}
    						break;

    That is correct.

    If the Cookie Notice Plugin is installed – this should work.

    Oh, my mistake. I’ve tried many possibilities and in the end I didn’t notice that this script is for the Cookie Notice Plugin. Instead I’m using the EU Cookie Law plugin, which has a similiar PHP cookie consent check:

    if ( function_exists(‘cookie_accepted’) && cookie_accepted() ) {
    // Your code
    }

    Unfortunately I didn’t get it to work yet.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Set cookies only when user allows use of cookies’ is closed to new replies.