• Resolved insurancetrainer

    (@insurancetrainer)


    I would like to set up the system so that each user can add their own clients and view only the clients they have created. Specifically, users should not be able to view clients added by others, while administrators should have access to all clients from all users.

    We have already attempted to implement this functionality using custom scripts, but unfortunately, without success. Below, I would like to ask if there is a built-in feature within the plugin that could meet this requirement without needing manual customization. If not, I have a few questions about how we can fix the script.The scripts we have tried are as follows:

    1. Script to associate a client with a specific user (nft_post):

    php

    add_action('save_post_nft_posts', 'assign_user_to_nft_post', 10, 3); function assign_user_to_nft_post($post_id, $post, $update) { // Avoid saving if the post is not of type 'nft_posts' or is an autosave if ($post->post_type != 'nft_posts' || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // Get the current user's ID $current_user_id = get_current_user_id(); // Check if the meta data already exists to avoid overwriting it $existing_user = get_post_meta($post_id, '_assigned_user', true); if (empty($existing_user)) { // Save the meta data associated with the user update_post_meta($post_id, '_assigned_user', $current_user_id); } }

    2. Script to filter clients visible by user:

    php

    add_action('pre_get_posts', 'filter_nft_posts_by_user'); function filter_nft_posts_by_user($query) { // Check if it's the main query, not a backend query if (!is_admin() && $query->is_main_query() && is_post_type_archive('nft_posts')) { // Only if the user is not an administrator if (!current_user_can('administrator')) { // Get the current user's ID $current_user_id = get_current_user_id(); // Modify the query to include only the clients associated with this user $meta_query = [ [ 'key' => '_assigned_user', 'value' => $current_user_id, 'compare' => '=' ] ]; // Set the meta_query to filter the results $query->set('meta_query', $meta_query); } } } Questions:

    1. What is the best way to associate a client with a specific user so that only the user who created it can view it?
    2. How can we ensure that administrators always have visibility on all clients, regardless of which user created them?
    3. Is there an existing feature that allows filtering the client view by user, so that users cannot see clients added by other users?
    4. If there is no built-in functionality, what changes should we make to our script to achieve the desired outcome?
Viewing 1 replies (of 1 total)
  • Plugin Support lastsplash (a11n)

    (@lastsplash)

    Hi @insurancetrainer

    We received a similar request from you via email. This functionality isn’t currently available in Jetpack CRM. We have logged your request in our internal issue tracker, but at this time, there is no timeline for when/if this functionality might be added.

    We aren’t able to provide support for custom code per our support policy, but it is possible that another community member may be able to assist you.

Viewing 1 replies (of 1 total)

The topic ‘Functionality for Managing Clients by Different Users’ is closed to new replies.