Support » Plugin: GDPR Cookie Compliance (CCPA ready) » Script contains PHP and does not work

  • Resolved ARCangelGIRL

    (@arcangelgirl)


    Hello,

    I was testing “3rd party cookies” functionality and faced one issue. One of my scripts that I had in functions.php file has some dynamic info (current user email address) that I gather using PHP. After getting user email I just echo it inside the JS script.

    <?php $current_user = wp_get_current_user();
      $userEmail = $current_user->user_email; ?>
      <script defer async type="text/javascript">
      var cpaAccount='test';
      var cpaE='<?php echo $userEmail; ?>';
      ............
    </script>

    When I place that code inside the “3rd party cookies” section it does not work. Looks like, that it does not understand the PHP part and works only JS part.

    Any suggestions or workarounds for this?
    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Moove Agency

    (@mooveagency)

    Hi @arcangelgirl,

    Thanks for your comments.

    We have a PHP checker feature implemented in our plugin, you can align your code snippet using the consent checker PHP functions, like:

    if ( function_exists( 'gdpr_cookie_is_accepted' ) ) {
      /* supported types: 'strict', 'thirdparty', 'advanced' */
      if ( gdpr_cookie_is_accepted( 'thirdparty' ) ) {
        $current_user = wp_get_current_user();
      $userEmail = $current_user->user_email; ?>
      <script defer async type="text/javascript">
      var cpaAccount='test';
      var cpaE='<?php echo $userEmail; ?>';
      ............
    </script>
      } 
    }

    You can find all the available hooks and functions in plugin settings -> Help, Hooks, Filters & Shortcodes -> Default hooks.

    Hope this helps.

    Thread Starter ARCangelGIRL

    (@arcangelgirl)

    Great, thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.