Advertisement
devamit

Community Blocker - Force to save some specific fields

Aug 3rd, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. add_action( 'bp_template_redirect', function() {
  2.     if ( ! is_user_logged_in() ) {
  3.             return;
  4.     }
  5.    
  6.     $user_id = bp_loggedin_user_id();
  7.     $redirect_url = bp_core_get_user_domain( $user_id ) . bp_get_profile_slug();
  8.     $memberDob = xprofile_get_field_data( 'DOB', $user_id );
  9.     $diff = (date( 'Y' ) - date( 'Y', strtotime( $memberDob ) ) );
  10.     if( $diff < 18 ) {
  11.         if( is_buddypress() && ! bp_is_user_profile()  ){
  12.             bp_core_redirect( $redirect_url . '/edit/' );
  13.         }
  14.     }
  15.    
  16. } );
  17.  
  18.  
  19.  
  20.  
  21. add_action( 'wp_footer', 'wbcom_age_verificarion_popup' );
  22. function wbcom_age_verificarion_popup() {
  23.         if ( ! is_user_logged_in() ) {
  24.             return;
  25.     }  
  26.    
  27.     if( is_buddypress() && bp_is_user_profile() ){ 
  28.         $member_id = bp_loggedin_user_id();
  29.         $memberDob = xprofile_get_field_data( 'DOB', $member_id );
  30.         $diff = (date( 'Y' ) - date( 'Y', strtotime( $memberDob ) ) );
  31.         if( $diff < 18 ) { 
  32.             ?>
  33.             <div id="age-verification" onclick="ageVerificationHide()" >
  34.                 <div class="age-verification-main">
  35.                     <span class="age-title"><?php _e( 'Are you 18 or older?', 'reign' ); ?></span>
  36.                     <span class="age-main-text"><?php _e( 'You must be of legal age to view our website. Due to legal requirements you must verify your age.', 'reign' ); ?></span>
  37.                 </div>
  38.             </div>
  39.             <script type="text/javascript">
  40.                 function ageVerificationHide() {
  41.                   var ageVerificationModel = document.getElementById('age-verification');
  42.                   ageVerificationModel.style.display = 'none';
  43.                 }
  44.                 function ageVerificationShow() {
  45.                   var ageVerificationModel = document.getElementById('age-verification');
  46.                   ageVerificationModel.style.display = 'block';
  47.                 }
  48.  
  49.                 document.addEventListener("DOMContentLoaded", function(event) {
  50.                   ageVerificationShow();
  51.                 });
  52.             </script>
  53.             <?php
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement