arie_cristianD

change account dropdown list

Nov 3rd, 2025 (edited)
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1.  
  2. add_filter( 'jnews_dropdown_link', 'j_edit_account_dropdown', 99 );
  3. add_filter( 'jnews_mobile_account_url', 'j_change_acocunt_link', 99 );
  4.  
  5. function j_edit_account_dropdown( $dropdown ) {
  6.  
  7.     if ( is_user_logged_in() ) {
  8.         $new_dropdown = array();
  9.         if ( function_exists( 'wc_get_page_permalink' ) ) {
  10.             $new_dropdown['my_account'] = array(
  11.                 'text' => __( 'My Acocunt', 'jnews' ),
  12.                 'url'  => wc_get_page_permalink( 'myaccount' ),
  13.             );
  14.             if ( j_is_jpw_subsribed() ) {
  15.                 $new_dropdown['download_pdf'] = array(
  16.                     'text' => __( 'Download PDF', 'jnews' ),
  17.                     'url'  => get_permalink( 64 ), /* change 64 with your page ID  */
  18.                 );
  19.             }
  20.         }
  21.         if ( isset( $dropdown['logout'] ) ) {
  22.             $new_dropdown['logout'] = $dropdown['logout'];
  23.         }
  24.  
  25.         if ( isset( $new_dropdown ) ) {
  26.             return $new_dropdown;
  27.         }
  28.     }
  29.  
  30.     return $dropdown;
  31. }
  32.  
  33. function j_change_acocunt_link( $url ) {
  34.     if ( function_exists( 'wc_get_page_permalink' ) ) {
  35.         return wc_get_page_permalink( 'myaccount' );
  36.     }
  37.     return $url;
  38. }
  39.  
  40.  
  41. function j_is_jpw_subsribed() {
  42.     $roles = apply_filters( 'jnews_paywall_unaffected_role_list', array( 'administrator' ) );
  43.     $user  = wp_get_current_user();
  44.  
  45.     foreach ( $roles as $role ) {
  46.         if ( in_array( $role, $user->roles ) ) {
  47.             return true;
  48.         }
  49.     }
  50.  
  51.     $subscribe_status = is_user_logged_in() ? get_user_option( 'jpw_subscribe_status', get_current_user_id() ) : false;
  52.     if ( $subscribe_status ) {
  53.         $subscription_type = get_user_option( 'jpw_subs_type', get_current_user_id() );
  54.  
  55.         if ( 'paypal' === $subscription_type ) {
  56.             /* get current date by paypall timezone setting */
  57.             $timezone = '+8'; /* change with your paypal time zone settings */
  58.         } else {
  59.             $timezone = '+0';
  60.         }
  61.         $timezone     = new DateTimeZone( $timezone );
  62.         $current_date = new DateTime( 'now', $timezone );
  63.         $expired      = get_user_option( 'jpw_expired_date', get_current_user_id() );
  64.  
  65.         $expired_timestamp = strtotime( $expired );
  66.         if ( $expired_timestamp ) {
  67.             $current_date = new DateTime( $current_date->format( 'Y-m-d H:i:s' ) );
  68.             $expired_date = new DateTime( $expired );
  69.             if ( $current_date <= $expired_date ) {
  70.                 return $subscribe_status;
  71.             }
  72.         }
  73.         update_user_option( get_current_user_id(), 'jpw_subscribe_status', false );
  74.     }
  75.  
  76.     return false;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment