Skip Navigation

[Resolved] product visibility to specific user

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by FuChan 4 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1448291

I use Types to create a repeatable field to PRODUCTS. My purpose is that different products are visible only to specific users.
For example:
I have 2 users (Username: hwk1, hwk2) and 3 products.
In the repeater field of the products, I put the value as below in order to match with username.
Product 1: hwk1
Product 2: hwk2
Product 3: hwk1, hwk2

I hope that after hwk1 is logged in, he can only see the product 1 + 3, and hwk2 only see product 2 + 3.
Is it possible? Could show me how to do it?
Thanks.

#1448563

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Is this just a simplified example and in reality you would have many more products and many more users?

Because if it is fairly simple like this, you can use Access and create a post group for posts that would only be seen by hwk1, a post group for posts that would only be seen by hwk2, and a post group for posts that would be seen by both, and then set permissions for individual users for each group.

But if you had more products/users it would start to get too complex.

In which case you would need a different solution, but let me know first...

#1448577

Thanks for your reply.

Yes, it is just a simple example to express what I want. I do have more users/products now and may have many more in the future.
Due to not so many users/products at this stage, I will try to use the way you provide.
In case there are many in the future, do you have any better suggestions?

Thanks again.

#1448681

Hi Nigel,

Your instruction above works fine, but I have another question:
Are the Access permissions only for the single page and not for archive page?

I hope that when hwk1 is logged in, he can see the single and archive pages that only belong to him.
The archive pages with no permission will not be visible to him.

How to do it? Thanks.

#1448801

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, if your use-case will become more complex then we should plan for that from the beginning.

So, rather than using Access you should use wpv-conditional shortcodes to restrict visibility (which you can use both in Views or Archives). You probably don't need to worry about using them on the templates for single posts, unless you are worried users might guess the URLs, in which case you could also wrap the content of the entire template in such a conditional.

As for how the conditional should work, in this scenario it makes more sense to me to use a taxonomy to specify who should get access. So you would make a taxonomy where you add terms that match the name/slug of the users.

Then edit posts and check the users that should be able to see the post.

Then in your Views, archives, or even individual templates, wrap the content in a conditional shortcode, like so:

		<wpv-loop>
          [wpv-conditional if="( CONTAINS(#(privilege),'[wpv-current-user info='login']') )"]
          <h3>[wpv-post-link]</h3>
          [/wpv-conditional]          
		</wpv-loop>

Note, in this example I created a taxonomy "privilege", and my terms are the user usernames.

Would that work for you?

#1448941

I am checking your new method to see if it works.

Now, I encounter a problem. I am using the theme Astra pro+Elementor pro.
After installing Toolset Views, following messages appear at Elementor page:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, cannot access private method Astra_Addon_Background_Updater::needs_db_update() in.................

After I disable Astra pro and change to the default theme Twenty Twenty , it is back to normal and the error messages disappear.
Do Astra pro conflict with Toolset?
What should I do?
Thanks.

#1448953

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

That's a known issue, which should be fixed soon, but in the meantime you can find a patch here: https://toolset.com/errata/php-warning-when-using-astra-pro-plugin-and-toolset-views-or-blocks/

#1449941

My issue is resolved now. Thank you!