在Wordpress多站点上,我使用“redirect-multisite-user-to-their-own-site”插件为从前端登录的用户重定向到他们自己的特定博客。但是,此插件仅重定向到用户博客的主页(例如mulstisite.com/users-site),而不是仪表板(例如mulstisite.com/users-site/wp-admin)。我希望将用户重定向到他们的仪表板。
在插件的代码中(见下文,完整版),他们有wp_redirect($user_target_site->siteurl);
。我还不熟悉PHP,需要它以某种方式转到$user_target_site->siteurl
+ /wp-admin
。我怎么能做到这一点?我很高兴编辑插件并创建自己的插件,以防止它被插件更新覆盖。
<?php
/*
Plugin Name: Redirect multisite user to their own site
Plugin URI: https://wordpress.org/plugins/redirect-multisite-user-to-their-own-site/
Description: If the current user in a multisite environment accesses a subsite to which access has not been granted, then redirect the user back to their own site. This plugin requires PHP 5.3 or newer because it uses PHP namespaces.
Author: Mark Howells-Mead
Version: 1.1.1
Author URI: https://www.permanenttourist.ch/
Text Domain: redirect-multisite-user-to-their-own-site
*/
namespace MHM\MultisiteRedirectuser;
class Plugin
{
public function __construct()
{
load_plugin_textdomain('redirect-multisite-user-to-their-own-site');
if (is_multisite()) {
add_action('parse_request', array($this, 'checkAccess'));
}
}
public function checkAccess()
{
global $current_user, $wpdb;
$current_site_id = (int) $wpdb->blogid;
$user_sites = get_blogs_of_user($current_user->ID);
if (is_array($user_sites)) {
switch (count($user_sites)) {
case 0:
if (is_user_logged_in()) {
do_action('redirect-multisite-user-to-their-own-site/no-sites', $current_user, $current_site_id);
}
break;
case 1:
$user_target_site = array_values($user_sites)[0];
if ((int) $user_target_site->userblog_id !== $current_site_id) {
do_action('redirect-multisite-user-to-their-own-site/redirecting', $current_user, $current_site_id, $user_target_site->siteurl);
wp_redirect($user_target_site->siteurl);
exit;
}
break;
default:
if (!array_key_exists($current_site_id, $user_sites)) {
do_action('redirect-multisite-user-to-their-own-site/not-allowed', $current_user, $current_site_id, $user_sites);
}
break;
}
}
}
}
new Plugin();
答案 0 :(得分:0)
只要您了解更改插件代码的含义,请尝试更改此行;
wp_redirect($user_target_site->siteurl);
对此:
wp_redirect($user_target_site->siteurl . "/wp-admin/");