[wordpress插件] Cookie Tasting饼干品尝

wordpress 插件 文章 2020-04-02 09:20 482 0 全屏看文

AI助手支持GPT4.0

评分
100
描述

This plugin sets user cookie when user is logged in.

此插件在用户登录时设置用户cookie。

You can use cookie as data store,

您可以将cookie用作数据存储,

so you can use it as UI resource.

因此您可以将其用作UI资源。

Visibility

可见度

This plugin adds class to html element.

此插件将类添加到 html 元素。

    • ct-logged-in The current user is logged in.
    • ct-logged-in 当前用户已登录。

    • ct-not-logged-in The current user is anonymous.
    • ct-not-logged-in 当前用户是匿名用户。

    You can control elements visibility with CSS.

    您可以使用CSS控制元素的可见性。

    .some-element{  

     .some-element {  

    display: none;

    显示:无;

    }

    }

    .ct-logged-in .some-element{  

    .ct-login .some-element {  

    display: block;

    显示:块;

    }

    }

    From JavaScript

    来自JavaScript

    You can use Global Object CookieTasting for utility.

    您可以将全局对象 CookieTasting 用于实用程序。

      • CookieTasting.userName() Returns user name.

      • CookieTasting.userName()返回用户名。

        If not logged in, returns ‘Guest’.

      • 如果尚未登录,则返回“访客”。

      • CookieTasting.lastUpdated() Returns timestamp of last log in check.

      • CookieTasting.lastUpdated()返回上次登录检查的时间戳。

        If this equals 0, it means that user is anonymous.

      • 如果该值等于0,则表示该用户是匿名用户。

      Besides that, this plugin checks periodically log-in status.

      此外,此插件会定期检查登录状态。

      You can handle it with jQuery.

      您可以使用jQuery处理它。

      jQuery( document ).on( 'cookie.tasting', function( event, response ) {  

       jQuery(document).on('cookie.tasting',function(event,response){  

      if ( response.login ) {    

      如果(response.login){    

      // User is logged in.    

      //用户已登录。    

      // If you use React...    

      //如果您使用React ...    

      setAttributes({ name: CookieTasting.userName() })  

      setAttributes({名称:CookieTasting.userName()})  

      } else {    

      }其他{    

      // User is not logged in.  

      //用户未登录。  

      }

      }

      } );

      });

      If you use react or something, updated the status with setState().

      如果您使用react或其他方法,请使用 setState()更新状态。

      Check Before Action

      操作前检查

      If you manage cached WordPress and customizing your own theme,

      如果您管理缓存的WordPress并自定义自己的主题,

      It’s a good idea to implement dynamic UI components with JavaScript.

      最好使用JavaScript来实现动态UI组件。

      You can check user’s credential just before important actions.

      您可以在执行重要操作之前检查用户的凭据。

      // Click action for button.

       //单击按钮的操作。

      $('.read-more').click( function( e ) {  

      $('。read-more')。click(function(e){  

      e.preventDefault();  

      e.preventDefault();  

      // Check cookie before do something.  

      //在做某事之前检查cookie。  

      CookieTasting.testBefore().then( function( response ) {    

      CookieTasting.testBefore()。then(function(response){    

      // Now user has fresh information.    

      //现在,用户有了新的信息。    

      // Load premium contents.    

      //加载高级内容。    

      loadPremiumContents();  

      loadPremiumContents();  

      }).catch( function( response ) {    

      })。catch(function(response){    

      // This user is not logged in.    

      //此用户尚未登录。    

      // Redirect them to login page.    

      //将他们重定向到登录页面。    

      window.locaion.href = '/wp-login.php';  

      window.locaion.href ='/wp-login.php';  

      } );

      });

      } );

      });

      Plese remember adding dependency for cookie-tasting-heartbeat to your script.

      请记住在脚本中添加 cookie-tasting-heartbeat 的依赖项。

      Handle UUID

      处理UUID

      By default, this plugin set UUID for each user.

      默认情况下,此插件为每个用户设置UUID。

      This will be…

      这将是...

        • Unique for each logged in user and will be saved as user_meta.
        • 每个登录用户的唯一身份,并将另存为user_meta。

        • Also kept for anonymous user.
        • 还保留给匿名用户。

        So you can use it for Google Analytic’s User ID View.

        因此,您可以将其用于Google Analytic(分析)的用户ID视图

        const uuid = CookieTasting.get( 'uuid' );

         const uuid = CookieTasting.get('uuid');

        // For Google Analytics.

        //对于Google Analytics(分析)。

        ga( 'set', "userId", uid );

        ga('set',“ userId”,uid);

安装步骤

    • Download zip file and unpack it.
    • 下载zip文件并解压缩。

    • Upload the directory to wp-content/plugins.
    • 将目录上传到 wp-content / plugins

    • Go to WordPress admin screen and activate this plugin.
    • 转到WordPress管理屏幕并激活此插件。

    Recommendation: Search on WordPress admin screen and install it.

    建议:在WordPress管理屏幕上搜索并安装。

下载地址
https://downloads.wordpress.org/plugin/cookie-tasting.1.0.10.zip
-EOF-

AI助手支持GPT4.0