The new version of FluentCRM allows you to create shortcodes that support conditional logic.
FluentCRM and FluentCommunity do not provide the same functionality as membership or content restriction plugins. Maybe it's worth implementing?
What I mean is the ability to control which parts of a page are visible by using shortcodes.
This can be especially useful, for example, on a unique βMy Accountβ page, or for extending a course with access to additional WordPress pages.
This effect can be achieved using a simple code snippet.
With it, you can show or hide specific content on a page using shortcodes.
You can also create a condition such as: if a user has tag 1, an image is displayed, but if they have tag 1 and also tag 2 or tag 3, the image will not be displayed.
Let me explain why such a condition makes sense.
I have a product available in several versions:
- Silver (basic course),
- Gold (basic and advanced course),
- Platinum (basic, advanced, and supplementary course),
- Diamond (basic, advanced, supplementary, and masterclass courses).
On the βMy Accountβ page, thumbnail images of the course covers are displayed.
If someone has purchased the Silver plan, they see a button labeled βGo to the course.β
They also see three additional course images with buttons labeled βGet access.β
These allow them to upgrade:
a. from Silver to Gold,
b. from Silver to Platinum,
c. from Silver to Diamond.
Now, letβs see what happens when a customer makes an upgrade.
Suppose the customer chooses option a and upgrades from Silver to Gold.
On the βMy Accountβ page, theyβll now see access to both the Basic and Advanced courses, along with two new upgrade options:
a. from Gold to Platinum,
b. from Gold to Diamond.
Everything here is pretty straightforward.
Based on the defined conditions, specific buttons and images will appear dynamically on the βMy Accountβ page.
This approach automates the process of purchasing new product variants directly online.
Below is a modified by me snippet I found online. You can paste it into Fluent Snippets:
/**
Β * Shortcode: [fluentcrm_condition]
Β *
- Extended version with support for exclude_tags and exclude_lists.
Β *
Β * example:
Β * [fluentcrm_condition tags="rjo-os" exclude_tags="rjo-oz,rjo-os-do-oz" exclude_lists="newsletter,archiwum"]
Β *Β Β Only visible if user has rjo-os but no rjo-oz, rjo-os-do-oz or newsletter/archive lists.
Β * [/fluentcrm_condition]
Β */
Β
function fluentcrm_condition_shortcode($atts, $content = null)
{
Β Β Β if (!function_exists('FluentCrmApi')) {
Β Β Β Β Β Β Β return '';
Β Β Β }
Β
Β Β Β $atts = shortcode_atts([
Β Β Β Β Β Β Β 'tags' => '',
Β Β Β Β Β Β Β 'exclude_tags' => '',
Β Β Β Β Β Β Β 'lists' => '',
Β Β Β Β Β Β Β 'exclude_lists' => '',
Β Β Β Β Β Β Β 'custom_fields' => '',
Β Β Β Β Β Β Β 'relation' => 'any',
Β Β Β Β Β Β Β 'has' => 'yes',
Β Β Β ], $atts);
Β
Β Β Β $contactApi = FluentCrmApi('contacts');
Β
Β Β Β try {
Β Β Β Β Β Β Β $contact = $contactApi->getCurrentContact(true, true);
Β Β Β } catch (Throwable $e) {
Β Β Β Β Β Β Β return '';
Β Β Β }
Β
Β Β Β if (!$contact) {
Β Β Β Β Β Β Β return '';
Β Β Β }
Β
Β Β Β // --- Parsowanie atrybutΓ³w ---
Β Β Β $tags = array_filter(array_map('trim', explode(',', $atts['tags'])));
Β Β Β $exclude_tags = array_filter(array_map('trim', explode(',', $atts['exclude_tags'])));
Β Β Β $lists = array_filter(array_map('trim', explode(',', $atts['lists'])));
Β Β Β $exclude_lists = array_filter(array_map('trim', explode(',', $atts['exclude_lists'])));
Β Β Β $relation = strtolower($atts['relation']) === 'all' ? 'all' : 'any';
Β Β Β $has = strtolower($atts['has']) !== 'no';
Β
Β Β Β // --- Pobierz tagi kontaktu ---
Β Β Β $tagSlugs = [];
Β Β Β if (method_exists($contact, 'tags')) {
Β Β Β Β Β Β Β try {
Β Β Β Β Β Β Β Β Β Β Β $tagSlugs = $contact->tags()->pluck('slug')->toArray();
Β Β Β Β Β Β Β } catch (Throwable $e) {
Β Β Β Β Β Β Β Β Β Β Β $tagSlugs = [];
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β if (empty($tagSlugs) && property_exists($contact, 'tags')) {
Β Β Β Β Β Β Β foreach ($contact->tags as $t) {
Β Β Β Β Β Β Β Β Β Β Β if (is_object($t) && isset($t->slug)) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β $tagSlugs[] = $t->slug;
Β Β Β Β Β Β Β Β Β Β Β } elseif (is_array($t) && isset($t['slug'])) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β $tagSlugs[] = $t['slug'];
Β Β Β Β Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β $tagSlugs = array_map('strtolower', $tagSlugs);
Β
Β Β Β // --- Pobierz listy kontaktu ---
Β Β Β $listSlugs = [];
Β Β Β if (method_exists($contact, 'lists')) {
Β Β Β Β Β Β Β try {
Β Β Β Β Β Β Β Β Β Β Β $listSlugs = $contact->lists()->pluck('slug')->toArray();
Β Β Β Β Β Β Β } catch (Throwable $e) {
Β Β Β Β Β Β Β Β Β Β Β $listSlugs = [];
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β if (empty($listSlugs) && property_exists($contact, 'lists')) {
Β Β Β Β Β Β Β foreach ($contact->lists as $l) {
Β Β Β Β Β Β Β Β Β Β Β if (is_object($l) && isset($l->slug)) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β $listSlugs[] = $l->slug;
Β Β Β Β Β Β Β Β Β Β Β } elseif (is_array($l) && isset($l['slug'])) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β $listSlugs[] = $l['slug'];
Β Β Β Β Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β $listSlugs = array_map('strtolower', $listSlugs);
Β
Β Β Β // --- SprawdΕΊ tagi ---
Β Β Β $has_tags = true;
Β Β Β if (!empty($tags)) {
Β Β Β Β Β Β Β $matches = array_intersect(array_map('strtolower', $tags), $tagSlugs);
Β Β Β Β Β Β Β if ($relation === 'all') {
Β Β Β Β Β Β Β Β Β Β Β $has_tags = (count($matches) === count($tags));
Β Β Β Β Β Β Β } else {
Β Β Β Β Β Β Β Β Β Β Β $has_tags = !empty($matches);
Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β if (!$has) {
Β Β Β Β Β Β Β Β Β Β Β $has_tags = !$has_tags;
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β // --- SprawdΕΊ wykluczone tagi ---
Β Β Β $has_excluded_tags = false;
Β Β Β if (!empty($exclude_tags)) {
Β Β Β Β Β Β Β foreach ($exclude_tags as $ex) {
Β Β Β Β Β Β Β Β Β Β Β if (in_array(strtolower($ex), $tagSlugs, true)) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β $has_excluded_tags = true;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β break;
Β Β Β Β Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β // --- SprawdΕΊ listy ---
Β Β Β $has_lists = true;
Β Β Β if (!empty($lists)) {
Β Β Β Β Β Β Β $matches = array_intersect(array_map('strtolower', $lists), $listSlugs);
Β Β Β Β Β Β Β if ($relation === 'all') {
Β Β Β Β Β Β Β Β Β Β Β $has_lists = (count($matches) === count($lists));
Β Β Β Β Β Β Β } else {
Β Β Β Β Β Β Β Β Β Β Β $has_lists = !empty($matches);
Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β if (!$has) {
Β Β Β Β Β Β Β Β Β Β Β $has_lists = !$has_lists;
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β // --- SprawdΕΊ wykluczone listy ---
Β Β Β $has_excluded_lists = false;
Β Β Β if (!empty($exclude_lists)) {
Β Β Β Β Β Β Β foreach ($exclude_lists as $ex) {
Β Β Β Β Β Β Β Β Β Β Β if (in_array(strtolower($ex), $listSlugs, true)) {
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β $has_excluded_lists = true;
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β break;
Β Β Β Β Β Β Β Β Β Β Β }
Β Β Β Β Β Β Β }
Β Β Β }
Β
Β Β Β // --- Logika koΕcowa ---
Β Β Β // Warunek: ma wymagane tagi i listy, ale nie ma ΕΌadnych wykluczonych.
Β Β Β if ($has_tags && $has_lists && !$has_excluded_tags && !$has_excluded_lists) {
Β Β Β Β Β Β Β return do_shortcode($content);
Β Β Β }
Β
Β Β Β return '';
}
Β
add_shortcode('fluentcrm_condition', 'fluentcrm_condition_shortcode');
Β
I think you're talking about this feature: https://www.youtube.com/watch?v=zYIXoMgLlxM
We already have it built-in.
Nazir HimelΒ Yes. In the extended version with shortcodes and conditions - if you have 1, the image will display, but if you have 1, 2, 3, or 1, 2 or 1, 3, it won't display.
Nazir HimelΒ Example:
[fluentcrm_condition tags="rjo-oz, rjo-os-do-oz" exclude_tags="rjo-op, rjo-os-do-op, rjo-os-do-od, rjo-oz-do-op, rjo-oz-do-od, rjo-od"] image [/fluentcrm_condition]
AdventurerΒ Ohh got it. Thanks for posting!
AdventurerΒ would this work:
https://github.com/WeMakeGood/fluentcrm-shortcodes
I just built this out for my own user account area and it can handle conditional blocks like you're suggesting.