• Hello ??

    I wanted to show agegate only to users who set their buddypress profile to be mature content.

    I have already setup some code but I am not able to trigger agegate with javascript and also need a “if agegate has been approved” check.

    function mature_content_restriction() {
        function restrict_content(){
            add_filter( 'age_gate_restricted', true, 0);
        }
        $user_id = bp_displayed_user_id();
        $user_profile_mature = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( 90, $user_id ) );
        echo ('<input type="hidden" id="mature-content-filter" value="' . $user_profile_mature . '" />' );
        ?>
        <script>
            var matureCheck = document.getElementById("mature-content-filter").value;
            if(matureCheck === "1"){
                console.log("Ist Mature User");
                <?php restrict_content(); ?>
                var style = "<style id='mature-content-blur' type='text/css'>.yz-header-cover,.avatar{filter:blur(15px);}</style>";
                jQuery('head').append(style);
                if(AgeGate = 'passed'){
                    jQuery('#mature-content-blur').remove;
                }
            }
            var slug = window.location.pathname;
            if('/wordpress/profiles/' === slug){
                console.log("Ist Profiles Mature");
                <?php restrict_content(); ?>
            }
        </script>
        <?php
    }
    add_action( 'wp_head', 'mature_content_restriction');

    Would be great if you could help me here, since I can’t figure out how to do this.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @nushara,

    Sorry for the really slow reply here! Do you still need help with this?

    Thanks
    Phil

    Thread Starter nushara

    (@nushara)

    I have found a better way to trigger it. But now the time it takes to show the agegate is like 3-4 seconds.

    This is my code on my functions.php:

    function remove_age_gate_restriction(){
    	?>
    	<script>
    		jQuery(document).on('agegateshown', function () {
    			jQuery('head').append("<style id='mature-content-blur' type='text/css'>.yzm-user-cover,.avatar,.index-honor-user,.yz-header-cover,#twitter-feed,#yz-bp:before,#custom_gallery_tab,#picarto-stream-container{opacity:0;}</style>");
    		});
    		jQuery(document).on('agegatepassed', function () {
    			jQuery('#mature-content-blur').remove();
    		});
    	</script>
    	<?php
    }
    add_action ( 'wp_head', 'remove_age_gate_restriction', 10 );
    
    //Enable age gate for mature content
    add_filter('age_gate_restricted', function ($restrict, $meta) {
    	$user_mature = bp_get_profile_field_data( array( bp_displayed_user_id(),'field' => 90 ) );
    	if($user_mature != 'Yes'){
    		return $restrict;
    	}else{
    		return true;
    	}
    }, 1, 2);

    Everything works fine but the delay is horrable. Can you help me find a way to get this firing faster?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trigger AgeGate with JavaScript’ is closed to new replies.