Commit 53b663f87010f2570451069ca249638a6badfa46

Authored by Paulo Graça
1 parent eccb01d834
Exists in master

rename file

wp_multisite_redirect.git.php
... ... @@ -0,0 +1,34 @@
  1 +<?php
  2 +/*
  3 +Plugin Name: Redirect Main Site To User 1 Site
  4 +Description: Redirect 'main-site' to 'main-site/sub-site/' for user 1, based on original work of WPSE
  5 +Version: 0.1
  6 +Author: RCAAP
  7 +Author URI: http://www.rcaap.pt
  8 +License: GPL2
  9 +*/
  10 +add_action('parse_request', 'redirect_to_user1_blog');
  11 +function redirect_to_user1_blog(){
  12 + if ( ! is_multisite() ) {
  13 + exit;
  14 + }
  15 +
  16 + #Sniff requests for a specific slug
  17 + if(is_main_site()){
  18 + # the default website by the user Webmaster
  19 + $user_info = get_userdata(1);
  20 + if ($user_info->primary_blog) {
  21 + $url = get_blogaddress_by_id($user_info->primary_blog);
  22 + } else {
  23 + #The URL to redirect TO
  24 + $url = network_site_url();
  25 + }
  26 +
  27 + #Let WordPress handle the redirect - the second parameter is obviously the status
  28 + if (get_site_url() != network_site_url()) {
  29 + wp_redirect($url, 301);
  30 + }
  31 + #It's important to exit, otherwise wp_redirect won't work properly
  32 + exit;
  33 + }
  34 +}
... ...
wp_multisite_redirect.php
... ... @@ -1,34 +0,0 @@
1   -<?php
2   -/*
3   -Plugin Name: Redirect Main Site To User 1 Site
4   -Description: Redirect 'main-site' to 'main-site/sub-site/' for user 1, based on original work of WPSE
5   -Version: 0.1
6   -Author: RCAAP
7   -Author URI: http://www.rcaap.pt
8   -License: GPL2
9   -*/
10   -add_action('parse_request', 'redirect_to_user1_blog');
11   -function redirect_to_user1_blog(){
12   - if ( ! is_multisite() ) {
13   - exit;
14   - }
15   -
16   - #Sniff requests for a specific slug
17   - if(is_main_site()){
18   - # the default website by the user Webmaster
19   - $user_info = get_userdata(1);
20   - if ($user_info->primary_blog) {
21   - $url = get_blogaddress_by_id($user_info->primary_blog);
22   - } else {
23   - #The URL to redirect TO
24   - $url = network_site_url();
25   - }
26   -
27   - #Let WordPress handle the redirect - the second parameter is obviously the status
28   - if (get_site_url() != network_site_url()) {
29   - wp_redirect($url, 301);
30   - }
31   - #It's important to exit, otherwise wp_redirect won't work properly
32   - exit;
33   - }
34   -}