PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 3, 2022

[FIXED] How do I force (subdomain) multisite to create new subsites with https?

 July 03, 2022     multisite, wordpress     No comments   

Issue

Does anyone know how to force subdomain multisite to retain the URL schema (specifically https) when a new subsite is created?

By default, it creates subsites with the "siteurl" and "home" options urls with "http://".

There are a few lines in ms-functions.php that explicitly tell subsite NOT to use the schema, so I'm wondering what the best way to change that is without modifying the source. Thanks!


Solution

We use the Multisite Clone Duplicator plugin, and I was able to write a function that hooks into the plugin during the cloning process, avoiding having to touch the core code.

if ( ! function_exists( 'mucd_after_copy_data' ) ) {
function force_https($from_site_id, $to_site_id) {
        $site_url = get_site_url($to_site_id);
        $https_site_url = str_replace( 'http://', 'https://', $site_url );
        update_blog_option( $to_site_id, 'siteurl', $https_site_url );
        update_blog_option( $to_site_id, 'home', $https_site_url );
    }
    add_action('mucd_after_copy_data', 'force_https', 10, 2 );
}


Answered By - wsizoo
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing