Wordpress 登录页面重定向到普通用户的 Woocommerce 我的帐户页面

问题描述:

我遇到了很大的麻烦.请帮我找到以下解决方案.

I am in a deep trouble. Please help me to find a solution for the following.

我有使用 Woocommerce 插件的 wordpress 网站.通常 Woocommerce 不允许普通用户(客户、用户 - 这些是您可以从 Wordpress 管理区域 > 添加新用户 > 角色中选择的角色).问题是只有管理员(角色)特权人员才能查看管理区域仪表板和完整设置.

I have wordpress site which uses Woocommerce Plugin. Normally Woocommerce doesn't allow normal Users (Customer,User - These are roles that you can Select from Wordpress Admin Area > Add new User > Role). The problem is that only Administrator(Role) privilege guys have the access to see the Admin area dashboard and full settings.

我需要所有用户进入仪表板区域而不重定向到我的帐户页面.因为现在当具有角色客户或类似角色的用户尝试输入管理员的登录凭据时,他们会被重定向到我的帐户页面.只有管​​理员权限角色具有进入仪表板和设置的能力.

I need all users to enter into dashboard area without redirecting to my-account page . Because now when users with Role Customer or something like, tried to enter login credentials of admin, they are getting redirected to my-account page. Only Administrator privilege role has the capability of entering the dashboard and settings.

于是我在谷歌搜索,找到了以下链接:

So I searched in google and found the following link:

WooCommerce 管理栏和仪表板访问权限 - 角色编辑器页面链接

WooCommerce admin bar and dashboard access - Role editor page link

我通过在functions.php中编写以下代码尝试了以下链接,但现在我看不到管理员设置,请查看我以普通用户身份输入时可以看到的屏幕截图.

I tried the following link by writing the following code in functions.php , but now I can't see admin settings, please see the screenshot that I can see when entering as a normal user.

我需要所有用户都有权查看管理区域仪表板和管理区域设置(能够查看帖子、页面、设置等),并且不想重定向到我的帐户页面.

I need all users access to see admin area dashboard and admin area settings (able to see Post, Page, Settings etc) and donot want to redirect to my-account page.

请帮助找到解决方案,因为我为此苦苦挣扎了很长时间.

please help to find a solution for this, since I am struggling with this for a long time.

我花了很多时间寻找这个问题的答案,它可以在 prevent_admin_access 函数下的 class-wc-admin.php 文件中找到.

I spent a lot of time looking for the answer to this one and it can be found in the class-wc-admin.php file under the prevent_admin_access function.

添加以下代码:

add_filter( 'woocommerce_prevent_admin_access', '__return_false' );

到您的函数 PHP 文件,它将阻止它阻止没有:edit_posts"、manage_woocommerce"、view_admin_dashboard"的用户访问仪表板.

To your functions PHP file and it will stop it blocking users who do not have: 'edit_posts', 'manage_woocommerce', 'view_admin_dashboard' from accessing the dashboard.

为了更好的衡量,您还可以添加此内容,将帐户永久链接覆盖为您的管理页面 - 这可能是相关的.

For good measure you can also add this which overrides the account permalink to be your admin page - which may be relevant.

function my_account_permalink($permalink) {

    return admin_url();
}

add_filter( 'woocommerce_get_myaccount_page_permalink', 'my_account_permalink', 1);