如何创建 Peter 登录重定向的 link 到 user/role 登录页面

How to create a link to user/role login page of Peter's Login Redirect

我在 Wordpress 中使用 Peter 的登录重定向将每个 User/Role 重定向到它的 "Personal Page"。

一切正常,但我想创建一个 link 任何用户都可以单击并被重定向回其登录重定向页面的地方。

现在,当用户登录时,它会转到他们的 "Personal Page",但是当单击另一个 link 时,无法返回。

您应该可以使用 redirect_to_front_page($redirect_to, $requested_redirect_to, $user) that is part of the plugin. It is primarily used as part of the login_redirect 过滤器,这样您就可以在此处查看有关参数的更多信息。要在此过滤器之外使用,您可以执行以下操作,为重定向 URL 传入 false 并检测它是否通过您的规则更新。

$user_id = get_current_user_id();
$user =  get_user_by( 'id', $user_id );
if ( false !== ( $redirect_url = redirect_to_front_page( false, false, $user ) ) ){
    // $redirect_url is the custom URL
} else {
    // there is no custom URL
}

为了解决这个问题,我在 functions.php 中添加了一些代码,以便能够 运行 PHP 小部件中的代码。

这是我添加到 functions.php

中的代码
add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

在此之后,我只需添加 HTML/PHP 代码来创建一个 link,它将当前用户重定向到其个人页面。我将这段代码放在文本中,当用户登录我正在使用的登录小部件插件时应该显示这些文本。

<a href="<?php echo redirect_to_front_page( false, false, wp_get_current_user()); ?>">Your Page</a>

就是这样。如果需要更多关于我所做的解释,请在下面发表评论。