[Hustle Pro] Creating Custom Visibility Conditions for Hustle

Hi!

As requested by Patrick Freitas, I’m creating a brand new ticket as a follow-up to this thread on Custom Visibility Rules.

I’m trying to create a custom Visibility Condition for Hustle Pro. I was able to create the new Condition option using the

hustle_visibility_condition_options

filter, I’ve set up custom variable data using the

hustle_optin_vars

filter and even created the necessary template using the

hustle_visibility_condition_templates

action. And everything gets added nicely. I followed your tutorial from the above thread regarding adding

jQuery( document ).on( "hustleAddViewConditions"...

using

‘admin_footer’

. Although the content does get added to the page, the settings never appear.

I even pulled your original code to see if that one would function, but as mentioned in the other thread, the gist doesn’t function:
https://gist.github.com/wpmudev-sls/5ac750e1d343de4c811783085ab26e86
With your code, I’m able to see Pageviews as an option and select it. But it also never renders the template to adjust the settings.

Can you take a look at your code and provide suggestions on how to make this work?

Documentation on how to create and implement third-party visibility conditions would probably be helpful to other devs who want to create integrations with Hustle Pro.

Thanks!
David

  • Nithin Ramdas
    • Support Wizard

    Hi David @ BBS ,

    I’m afraid, the code snippet you have mentioned is outdated. I’m escalating this to our developer’s attention to better assist on what might be missing with the existing snippet.

    Could we also know whether you are looking for the same “Page View” visibility? Possible to provide further details of what custom rules you are looking to add so that it would help us better in checking what could be suggested.

    Looking forward to your response.

    Kind Regards,
    Nithin

  • David @ BBS
    • Site Builder, Child of Zeus

    I’m actually wanting to create a series of rules based on the type of Membership a user has within our Membership plugin (RCP). I was able to use the Visitor’s Browser template as a great starting point for what I want to display.

    The dream would be to have a side-tabs option with three options:
    – Active Membership,
    – Expired Membership,
    – Specific Membership
    With the last one opening up the multi-select of Membership Names.

    If the devs can provide any sort of guide for how to fully implement that, that would be amazing. Having said that, I’ll probably be able to figure some things out from a generic guide.

    Thanks!

  • Anderson
    • Staff

    Hi David @ BBS !

    Thanks for contacting us. I hope you are doing well.

    Unfortunately, due to recent changes in the plugin’s core, that snippet is not working anymore and there’s no easy workaround currently, but we appreciated your request and I have informed Hustle team to add a few useful hooks for this.

    Best regards,
    Anderson Salas.

  • Nithin Ramdas
    • Support Wizard

    Hi David @ BBS ,

    I’m afraid, there isn’t any further progress we have specifically regarding such use cases at the moment. I’ll make sure to check with our Hustle team regarding the status of this feature down the roadmap.

    In the meanwhile, you could check whether hustle_render_module_markup filter and see whether that would help or not, so that you could use it as a mu-plugins.

    For example:

    <?php
    add_action( 'plugins_loaded', function() { 
    	add_filter( 'hustle_render_module_markup', function( $html, $module, $render_id, $sub_type, $post_id ) {
    		$module_id = 1;
    		
            // (Custom logic here. Return an empty string '' to hide the Pop-up.)
            // return '';
    
    		return $html;
    	}, 10, 5 );
    });

    Please do note that the above code is more of a reference and it’ll require custom coding to tweak it further to your requirement in order to make it work.

    Best Regards,
    Nithin

  • David @ BBS
    • Site Builder, Child of Zeus

    Man oh man. It pains me to see it when Support folks don’t really know the plugins they’re supporting. The filter you suggested is way too late in the code execution. It’s already after it’s been rendered, significantly slowing down page load. There’s actually a filter much earlier to determine if the popup/slide-in should be rendered at all. No need for a mu-plugin. You can quite literally put the below code in your theme’s function file.

    For anyone else looking at how to easily add custom logic to whether a pop-up or slide-in should be displayed, you can use the hustle_module_is_allowed_to_display filter. Here’s an example that only displays the module to logged-in users who have an active RCP Membership.

    /**
     * Display Hustle Pop-Up or Slide-in only to logged-in users who have an active RCP Membership.
     *
     * @param bool   $allow
     * @param string $module_id
     * @param string $module_type Type of the current module.
     * @param string $sub_type    Display type for embeds and sharing.
     *
     * @return false|mixed
     */
    function my_prefix_display_hustle_to_active_rcp_members( $allow, $module_id, $module_type, $sub_type ) {
    	if ( ! $allow ) {
    		return $allow;
    	}
    	
    	// You can target the $module_id, or instead target the module name as I am below.
    	$module = Hustle_Module_Collection::instance()->return_model_from_id( $module_id );
    	
    	if ( $module->module_name !== 'August 2023 Pricing Change' ) {
    		return $allow;
    	}
    	
    	if ( ! is_user_logged_in() ) {
    		return false;
    	}
    	
    	return rcp_user_has_active_membership();
    }
    
    add_filter( 'hustle_module_is_allowed_to_display', 'my_prefix_display_hustle_to_active_rcp_members', 10, 4 );