Hello Petar,
For support rules, we are able to handle only one issue at the time. This helps us to bring you a better service and also helps other users to find all the information here exposed.
Let's focus on this ticket about the original request and we can create another ticket for any other request.
Acting on WordPress menus is out of the scope of all Toolset Plugins. To modify a WordPress plugin, I suggest one of the following solutions:
- Custom code: similar to this article hidden link
- Using a 3rd party plugin: This plugin seems a good fit https://wordpress.org/plugins/if-menu/
Both these solutions are out of the scope of the Toolset Support forum, and If you are not familiar with website development, you should consider hiring a developer or one of our partners https://toolset.com/contractors/
Toolset, on the other hand, gives several ways to get what you try to have. I'll explain below and example of a "Toolset Training" website. The user can create only one Profile.
1. Create custom post type Profile.
2. Create custom fields for the Profile custom post.
3. Create a Toolset form for creating a Profile (Create Profile).
4. Create a Toolset form for editing a Profile (Edit Profile).
5. Create a page "My Profile", where we will show the "Create Profile" form or the "Edit Profile" depending on whether the user has created a profile or not.
At this stage, Toolset has no built-in way to limit the user to only one profile post. We will create a function on the theme's code to use withing Toolset.
6. Add the following code to your theme's functions.php file. Adapt the code depending on your custom-post-type slug, here we use "profile".
function my_user_profile_count() {
$user_post_count = count( get_posts( array(
'post_type' => 'profile', // <== put your post type slug here
'author' => get_current_user_id(),
'post_status' => array('publish', 'draft', 'pending', 'private'),
) ) );
return $user_post_count;
}
Note that in post_status, we are searching for several statuses, you can adapt that to your use case too.
7. Adding the functions to Toolset->Settings->Front-end Content->Functions inside conditional evaluations.
8. On the "My Profile" page. Assuming you are using Gutenberg.
8.1. Add a Toolset conditional block, on the condition use custom function "my_user_profile_count" equals to static value 0.
8.1.1. Check this screenshot hidden link
8.1.2. Add a form block inside the conditional block and choose the "Create Profile" form.
8.2. Add a Toolset conditional block, on the condition use custom function "my_user_profile_count" greater than static value 0.
8.2.1. Check this screenshot hidden link
8.2.2. Add a View Block inside the conditional block. The view should show the Profile posts whos the author is the current user, and the status is any of "publish", "pending", "draft", "private". Check this screenshot hidden link
8.2.3. Insert a Toolset form block inside the view loop. Choose the "Edit Profile" form. And the "Post to edit" is "The current post". Check hidden link
8.3. Save the page.
Check what I got too far. hidden link
If you are using the legacy Toolset Views editor, read more about it and check the images here https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/
Let's get back to the menu, I was able to update the menu by adding a custom visibility rule to the "If Menu" plugin based on our custom function to count Profile posts. Visibility rules are described on the faqs section of the plugin page https://wordpress.org/plugins/if-menu/
Add the following code to your theme functions.php file:
add_filter('if_menu_conditions', 'my_new_menu_conditions');
function my_new_menu_conditions($conditions) {
$conditions[] = array(
'id' => 'my-user-has-profile-post', // unique ID for the rule
'name' => __('User has Profile', 'i18n-domain'), // name of the rule
'condition' => function($item) { // callback - must return Boolean
return my_user_profile_count() > 0;
}
);
return $conditions;
}
Then configure the rules on your WordPress menu:
- Check my settings on this screenshot hidden link
- Check my results. hidden link
I hope this answers your original question. Let me know if you have any doubts.