On a multisite environment, get the subdomain value as variable

I’m trying to setup a multisite where everytime a new site is added, a DNS record is also added in Cloudflare. So far, the code is working but I’m having troubles trying to parse the subdomain value onto a variable.

This is the code so far:

function create_cloudflare_dns_record() {  //$  current_site = ''.$  get_blog_details->siteurl.''; //$  current_site = ''.$  substr( $  current_site, -8).''; //$  current_site = ''.explode('.', $  current_site).'';   /* Cloudflare.com | APİv4 | Api Ayarları */ $  apikey     = '778***************************c37'; // Cloudflare Global API $  email      = 'al******@***********.com'; // Cloudflare Email Adress $  domain     = 'mer*****.com';  // zone_name // Cloudflare Domain Name $  zoneid     = 'ecc**********************1e1'; // zone_id // Cloudflare Domain Zone ID //$  current_site   = ''.$  get_sites->path.''; $  current_site = explode('.', $  _SERVER['HTTP_HOST']);   // $  _SERVER['HTTP_HOST']  // A-record oluşturur DNS sistemi için. $  ch = curl_init("https://api.cloudflare.com/client/v4/zones/".$  zoneid."/dns_records"); curl_setopt($  ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($  ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($  ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($  ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($  ch, CURLOPT_HTTPHEADER, array( 'X-Auth-Email: '.$  email.'', 'X-Auth-Key: '.$  apikey.'', 'Cache-Control: no-cache', // 'Content-Type: multipart/form-data; charset=utf-8', 'Content-Type:application/json', 'purge_everything: true'  ));  // -d curl parametresi. $  data = array(      'type' => 'CNAME',     'name' => ''.$  current_site.'',     'content' => 'mer***.com',     'zone_name' => ''.$  domain.'',     'zone_id' => ''.$  zoneid.'',     'proxied' => true,     'ttl' => '120' );  $  data_string = json_encode($  data);  curl_setopt($  ch, CURLOPT_POST, true); curl_setopt($  ch, CURLOPT_POSTFIELDS, $  data_string); //curl_setopt($  ch, CURLOPT_POSTFIELDS, http_build_query($  data_string));  $  sonuc = curl_exec($  ch);  /*     //print_r($  sonuc); */  curl_close($  ch);    }   add_action( 'wp_insert_site', 'create_cloudflare_dns_record' ); 

None of the three different attempts for $ current_site at the beggining of the function is giving any result.

If I manually replace the value for $ current_site, the code is working.

Any help is greatly appreciated.

Add www to the Root Site in WP Multisite Network

I have a WordPress (Latest version) based website with Multisite Network Enabled. For example, the domain is example.com. So, my root site is example.com and my subsite is blog.example.com. But I want my root site as www.example.com. To do so, I’ve taken 4 steps:

Modified .htaccess file. Added the code below:

RewriteEngine on RewriteCond %{HTTP_HOST} !^www.example.com$   RewriteRule ^(.*)$   https://www.example.com/$  1 [R=301] 

Modified wp-config.php:

define('DOMAIN_CURRENT_SITE', 'www.example.com'); 

Modified MySQL table wp_site. Old data: domain: example.com. New Data:

domain: www.example.com 

Modified MySQL table wp_sitemeta. Old data: siteurl: example.com. New Data:

siteurl: www.example.com 

But unfortunately, it didn’t work. What to do? Thanks in advance.

How do I display/pull posts from subdomains to the landing page (domain) in WordPress Multi-site?

I have 8 sites in my multi-site network:

  1. Group Landing site (domain)
  2. Group 1 site (subdomain 1)
  3. Group 2 site (subdomain 2)
  4. Group 3 site (subdomain 3)
  5. Group 4 site (subdomain 4)
  6. Group 5 site (subdomain 5)
  7. Group 6 site (subdomain 6)
  8. Group 7 site (subdomain 7)

Essentially, Groups 1 to 7 will have separate contents. However, the Group Landing site will have content from both. I would rather not have the user enter the content twice. The post must also link/point to the Group/subdomain where it was originally published.

Is there a way for me to pull content from Group 1 and Group 2, and display it in Group Landing?

(Clarification: I want to pull content. That means, that I want to be able to run a query and get information from other posts and pages and display on the front end. I am not looking to duplicate content on the back-end, or to share content on the back-end. So, if the source is deleted than nothing will show on the front-end.)

What I did: I’m not sure if I did it correctly (I don’t even know how to code), but I appended the code snippet below in the functions.php of my theme:

foreach( $  blog_ids as $  blog_id ){     switch_to_blog( $  blog_id );     $  post = get_post( $  post_id );     restore_current_blog(); } 

Reason for asking: I want to replicate this feature from the front/homepage of this website: https://www.inquirer.net. Also, the web hosting support team cannot provide snippets for this feature because they only have Python/Go developers rather than WordPress developers.

What conditions must be met in order to upload .zip file to a multisite WordPress installation?

I cannot upload .zip files to my WordPress network, despite making IMHO everything that is needed. I am still hit by this irritating error.

enter image description here

Details:

  1. I am a super-admin in my network.
  2. The ALLOW_UNFILTERED_UPLOADS flag is set to true
  3. Custom hook of $ existing_mimes['zip'] = 'application/zip'; is added
  4. Uploading .zip files is allowed in my network:

enter image description here

Here is entire code of my hook:

function so_387865_custom_upload_mimes ( $  existing_mimes ) {     $  existing_mimes['epub'] = 'application/epub+zip';     $  existing_mimes['mobi'] = 'application/x-mobipocket-ebook';     $  existing_mimes['zip'] = 'application/zip';       return $  existing_mimes; }   add_filter('upload_mimes', 'so_387865_custom_upload_mimes'); 

I thought that maybe there’s something wrong with the hook, so I have installed the Enhanced Media Library extension (as suggested in here). All for nothing, as it clearly shows that this MIME type is added:

enter image description here

What else should I do in order to be able to upload .zip files? I am seriously lost!

Multisite: menus can’t be added in child sites

It seems that we cannot add menus in child sites in multisite. Did anyone face this issue before?

I have the Menu container enabled in my functions.php

register_nav_menus(     array(         'primary-menu' => __( 'Primary Menu' ),         'secondary-menu' => __( 'Secondary Menu' )     ) ); 

I can add menus to the parent site. But I can’t do it in the child sites even though I can see the Menu container and the Create Menu button.

No menu is created when the Create Menu button is clicked. WordPress just refreshed the page and the menu I tried to create is not present at all.

I have inspected the database of my child site and I can’t find any row for nav_menu_item.

Any ideas?

EDIT:

I also found out that I cannot add any category or tag in my child sites. Why??

WordPress Multisite Shared Cookies with Multiple domains

I have a strong feeling you can no longer do this, but here it goes.

I’ve got a WordPress Multisite using two domains (For our example: domain-one.test and domain-two.test).

I would like shared user session/cookies between the two sites. Example user experience, a user logs into domain-one.test and later navigates to domain-two.test while maintaining the user session.

What are the wp-config and other settings to achieve this, or has this kind of functionality been fully shot down?

In Multisite the users profile picture keeps disappearing for “the other site”

I have the following setup: Site A with Domain A and Site B with Domain B

Site A is set to be the main site.

The users’ profile pictures have all been set via Site A and therefore Domain A. They do show under "Network Admin > Users", but they don’t show under "Site B > Users".

If I now set an image for profile XYZ under "Site B > Users", the URL for that profile pic changes to Domain B in the users table and there is no image anymore displayed for profile XYZ under Network Admin nor under Site A.

Any idea what the issue might be and is there a way around that?

What are Attributes used for in a WordPress Multisite?

When you edit a WordPress Multisite, there is this section of Attributes with multicheckboxes to select from, just curious what this actually does (if anything). I never needed to check "Public" checkbox in here for the site to be shown publicly. This is very strange to me and just wondering how WordPress uses this and if it’s used at all and how?

multisite-edit-settings

Redirect a WordPress Multisite url after it has been change to a new one

In the multisite dashboard network admin, you can edit a site and change its url.

For example, I have this url: multisite.com/old and I have change it to multisite.com/new

How can I make the multisite.com/old redirect to multisite.com/new so that users will not get lost and will not return an error? Current error is "Page not found / File not found".

I have tried adding this to my htaccess with no success

RewriteRule ^old/(.*)$   /new/$  1 [R=301,NC,L] 

And also this one

Redirect 301 /old/ https://www.multisite.com/new/