Advertisement
fauzanjeg

Account Page Restriction

Dec 19th, 2021
1,320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. /** Account Page Restriction */
  2. function restrict_account_page() {
  3.     $restrict_role = array( 'customer' );
  4.     $user          = wp_get_current_user();
  5.     if ( in_array( $user->roles[0], $restrict_role ) ) {
  6.         remove_action( 'admin_init', array( \JNews\AccountPage::getInstance(), 'prevent_admin_access' ), 5 );
  7.         if ( class_exists( 'JNews_Frontend_Endpoint' ) ) {
  8.             remove_filter( 'admin_init', array( JNews_Frontend_Template::getInstance(), 'disable_admin_dashboard' ) );
  9.         }
  10.  
  11.         /* remove menu account */
  12.         remove_filter( 'jnews_dropdown_link', array( \JNews\AccountPage::getInstance(), 'dropdown_link' ) );
  13.  
  14.         $current_url = ( 'on' === isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] ? 'https' : 'http' ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  15.         if ( strpos( $current_url, home_url( 'account' ) ) !== false ) {
  16.             wp_safe_redirect( esc_url( home_url( '/' ) ) );
  17.             exit;
  18.         }
  19.     }
  20. }
  21. add_action( 'init', 'restrict_account_page' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement