Skip Navigation

[Resolved] User registration associated with your company (Taxonomies)

This support ticket is created 7 years, 2 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.

Our next available supporter will start replying to tickets in about 5.18 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by reinaldoM 7 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#564098

Good evening,

I tried to sort this out easily, but I did not get it around here.

I need my users to register with two actions going on.

1- The user writes the name of his "Company" (Creates new taxonomie).
2- The user writes the remaining information "Receive access" to read everything related to his "Company" (New taxonomy created).

Final result: The user registers a new taxonomy and receives access to view everything that is associated with it and only to it.

#564119

Dear reinaldo,

I assume the "Company" is a custom taxonomy.
You are going to achieve this:
When user submit the CRED form for creating user, add a new term in the "Company" taxonomy,

If it is:
1) There isn't user taxonomy, you can not assign a taxonomy to wordpress user, so there isn't such a built-in feature within CRED form.
2) You can try with some custom PHP codes, for example:
When user submit the CRED user form, use action hook "cred_save_data" to trigger a PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
In this PHP function, do this:
a) Create a post, set the post author as current user
https://codex.wordpress.org/Function_Reference/wp_insert_post
b) Assign above post with the specific taxonomy term
https://developer.wordpress.org/reference/functions/wp_set_object_terms/

For your reference.

#564132
Acessos Digitallivre Toolset.png

I understand Luo Yang,

Unfortunately I still can not solve the problem, I will focus on the result to explain better.

I put an attached image, I need it:

1- A specific "Role" of users can only view or edit a content if it belongs to a specific company.

2- It must happen from the time of registration.

3- I need to associate these permissions in some way.

#564152

I assume the "Company" as a custom taxonomy.
Wordpress user's role is related with custom post types, it can not achieve what you want:
A specific "Role" of users can only view or edit a content if it belongs to a specific company.
https://toolset.com/documentation/user-guides/setting-access-control/

In your case, I suggest you try these:
1) You can create a custom post type, for example "user CPT", assign it with taxonomy "Company", each user will have only one "user CPT" post.
When user is created with CRED form, please check above answer to create the "user CPT" post:
https://toolset.com/forums/topic/user-registration-associated-with-your-company-taxonomies/#post-564119

2) When user is logged in, redirect him to a wordpress page, in this page setup a view to list "user CPT" post, whose author is current user:
https://toolset.com/documentation/user-guides/filtering-views-query-by-author/
Then you will get the "user CPT" post, and it's term of taxonomy "Company"
Use it to display the content related to this company.

#564439

Perfect Luo Yang, thank you for the support. I'm really understanding how the Toolset works.

You did exactly what you said, but I was not able to use the custom PHP code. I believe that is what is below.

- Insert post with custom taxonomy and post meta data (since 4.4.0):

$hierarchical_tax = array( 13, 10 ); // Array of tax ids.
$non_hierarchical_tax = 'tax name 1, tax name 2'; // Can use array of ids or string of tax names separated by commas
 
$post_arr = array(
    'post_title'   => 'Test post',
    'post_content' => 'Test post content',
    'post_status'  => 'publish',
    'post_author'  => get_current_user_id(),
    'tax_input'    => array(
        'hierarchical_tax'     => $hierarchical_tax,
        'non_hierarchical_tax' => $non_hierarchical_tax,
    ),
    'meta_input'   => array(
        'test_meta_key' => 'value of test_meta_key',
    ),
);

1. I created the custom post type "user CPT", and assign it with taxonomy "Company".
2. I was unable to use the "CRED user form" to create a post, set the post to the current user and assign the post with the specific taxonomy term.

How exactly can I do this?

Result: I think of something similar to this hierarchy.

> Company
    > Clients or employees
       > Users
          > Custom post

Each user can only see what is associated with his for him, by each company.

But each User is associated with more than one company.

Thanks for the help Luo.

#564528

We can handles the question one by one, for this question:
Q1) How exactly can I do this?
It is a custom PHP codes problem, if you need more assistance for it, please provide a test site with same problem, also point out the problem page URL and CRED form URL, and where I can edit your PHP codes, I need a live website to test and debug.

For other questions, please create new thread for each new question, that will help other users to find the answers. thanks