Last active
January 18, 2024 21:16
-
-
Save Lonsdale201/35b668c05fa4cb0a340481eb1ab7bcee to your computer and use it in GitHub Desktop.
JetEngine - Dynamic Visibility - Fluent CRM Lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // place the code in the child theme functions.php or a custom code snippets plugin like Fluent Snippts etc.. | |
| // This conditions required the FluentCRM plugin to be installed and activated on your site. This Conditions only work with | |
| // LOGGED IN USERS + user need to Contant in your CRM | |
| // https://fluentcrm.com/ | |
| // https://wordpress.org/plugins/fluent-crm/ | |
| // Only Elementor | |
| // HOW TO | |
| // Go to your , widget container etc, open the Dynamic Visibility modul, and scroll down and select the Fluent CRM Lists option | |
| // In the next select field, choose one or more Lists (Internal operator OR) | |
| // don't see any listings? That's because you haven't created them yet. | |
| // The list or lists that you select, if the logged in contact user is included, you can hide or show the item based on the setting. | |
| // IMAGE: https://prnt.sc/YzX-e1QX3ecF | |
| add_action( 'jet-engine/modules/dynamic-visibility/conditions/register', function( $conditions_manager ) { | |
| if ( function_exists( 'FluentCrmApi' ) ) { | |
| class FluentCRM_Lists_Visibility extends \Jet_Engine\Modules\Dynamic_Visibility\Conditions\Base { | |
| public function get_id() { | |
| return 'fluentcrm-lists'; | |
| } | |
| public function get_name() { | |
| return __( 'Fluent CRM Lists', 'jet-engine' ); | |
| } | |
| public function get_group() { | |
| return 'fluent_crm'; | |
| } | |
| public function check( $args = array() ) { | |
| $contactApi = FluentCrmApi('contacts'); | |
| $contact = $contactApi->getCurrentContact(); | |
| if ( !$contact ) { | |
| return false; | |
| } | |
| $selected_lists = isset( $args['condition_settings']['selected_lists'] ) ? $args['condition_settings']['selected_lists'] : array(); | |
| $is_in_list = false; | |
| $user_lists = $contact->lists; | |
| foreach ( $selected_lists as $selected_list ) { | |
| foreach ($user_lists as $list) { | |
| if ($list->id == $selected_list) { | |
| $is_in_list = true; | |
| break; | |
| } | |
| } | |
| if ($is_in_list) { | |
| break; | |
| } | |
| } | |
| $type = isset( $args['type'] ) ? $args['type'] : 'show'; | |
| return ( 'hide' === $type ) ? !$is_in_list : $is_in_list; | |
| } | |
| private function get_fluentcrm_lists() { | |
| $listApi = FluentCrmApi('lists'); | |
| return $listApi->all(); | |
| } | |
| public function get_custom_controls() { | |
| $fluent_lists = $this->get_fluentcrm_lists(); | |
| $options = array(); | |
| foreach ($fluent_lists as $list) { | |
| $options[$list->id] = $list->title; | |
| } | |
| return array( | |
| 'selected_lists' => array( | |
| 'label' => __( 'Select Lists', 'jet-engine' ), | |
| 'type' => 'select2', | |
| 'multiple' => true, | |
| 'default' => array(), | |
| 'options' => $options, | |
| ), | |
| ); | |
| } | |
| public function is_for_fields() { | |
| return false; | |
| } | |
| public function need_value_detect() { | |
| return false; | |
| } | |
| } | |
| $conditions_manager->register_condition( new FluentCRM_Lists_Visibility() ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment