CCCPaste

Account Page Restriction

/** Account Page Restriction */
function restrict_account_page() {
	$restrict_role = array( 'customer' );
	$user          = wp_get_current_user();
	if ( in_array( $user->roles[0], $restrict_role ) ) {
		remove_action( 'admin_init', array( \JNews\AccountPage::getInstance(), 'prevent_admin_access' ), 5 );
		if ( class_exists( 'JNews_Frontend_Endpoint' ) ) {
			remove_filter( 'admin_init', array( JNews_Frontend_Template::getInstance(), 'disable_admin_dashboard' ) );
		}

		/* remove menu account */
		remove_filter( 'jnews_dropdown_link', array( \JNews\AccountPage::getInstance(), 'dropdown_link' ) );

		$current_url = ( 'on' === isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] ? 'https' : 'http' ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
		if ( strpos( $current_url, home_url( 'account' ) ) !== false ) {
			wp_safe_redirect( esc_url( home_url( '/' ) ) );
			exit;
		}
	}
}
add_action( 'init', 'restrict_account_page' );