如何查看当前访问者是否是商店的管理员?

编程入门 行业动态 更新时间:2024-10-26 12:24:24
本文介绍了如何查看当前访问者是否是商店的管理员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想创建一种产品,该产品可以在Shopify的店面中使用,但只能由商店管理员使用.无论如何,是否可以通过液体识别当前用户是管理员?还是有其他解决方案来应对这一挑战.谢谢!

I would like to create a product that would be available in Shopify's storefront but would only be accessible for the shop administrator. Is there anyway to identify if the current user is an admin via liquid? or is there any other solution for this challenge. Thanks!

推荐答案

如果您以管理员身份登录,则在呈现{{ content_for_header }}包含时,它将包含一些JavaScript,以向下推送页面内容,以便为Shopify管理栏.

If you're signed in as an admin, when rendering the {{ content_for_header }} include, it will contain some JavaScript to push the page content down to make room for the Shopify admin bar.

我们可以利用capture将{{ content_for_header }}代码存储为液体变量,然后使用contains运算符检查变量中是否存在admin_bar_iframe.

We can utilize capture to store the {{ content_for_header }} code as a liquid variable and then use the contains operator to check if admin_bar_iframe exists in the variable.

{% capture CFH %}{{ content_for_header }}{% endcapture %}{{ CFH }} {% if CFH contains 'admin_bar_iframe' %} {% assign admin = true %} {% endif %} {% if admin %} <!-- User is an admin --> {% else %} <!-- User is not an admin --> {% endif %}

注意:我注意到Shopify管理栏并非始终都填充(我认为这是一个错误).如果您的实例上没有填充Shopify管理栏,则此操作将无效.

Note: I've noticed that the Shopify admin bar doesn't populate at all times (I think its a bug). If your Shopify admin bar is not populating on your instance this will not work.

更多推荐

如何查看当前访问者是否是商店的管理员?

本文发布于:2023-10-31 18:32:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:访问者   商店   管理员

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!