Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2015-01-11 14:07:38

gaufde
Member
From: Ojai, CA
Registered: 2014-07-11
Posts: 72
Website

One PHPlugin File for Multiple Websites - Solution

Hi Everyone,
A few days ago I had asked a question about using one phplugins file for all three of my website. However, I soon realized that it wasn't necessary for what I wanted to do, so I took my post down. A little while later I received an email from Rod saying that he had an idea for how I could implement this. It seemed like a fun project, so I took him up on his offer. He gave me some code that he thought would work, but hadn't tested. I took that code and played with it for a while to get everything to work.

This code makes it so that you can control the phplugins for many sites with one phplugins.php file. In case anyone wants to do this, I have put the code that Rod and I came up with below. The first section of code is to implement wordpress menus for multiple sites, and the second is to use different custom css files for each site. If you use the custom css code, then you will need to create a new .css file in /public_html/phplugins/css/ for each of your sites. You will have to fill in some information for your sites into the code and update the path to the phplugins file in your sub sites. This code assumes that you have your phplugins folder in the root of your site and that site1 is the main site on your hosting service. Also, my example if for three sites, but you can add more if you need to.

Wordpress Code:

// GET FUNCTIONS FROM WORDPRESS SITE 1
if ($_SERVER[SERVER_NAME] == 'SITE1.COM') {
define('__ROOT__', 'SET/PATH/TO/WORDPRESS/FOR/SITE1'); // SET PATH TO WORDPRESS
require_once(__ROOT__.'/wp-includes/version.php'); global $wp_version;
require_once(__ROOT__.'/wp-load.php');

// SITE-WIDE NAVIGATION FROM WORDPRESS
function ttg_header_navigation( $style, $path ) {
    if (G_STYLE != 'CE4-WORDPRESS') {
        echo '
<div id="navigation-container" class="navigation-container clearfix">

    <div id="navigation" class="block-id navigation clearfix">
    <div class="mantle clearfix">
        <div class="core clearfix">
        <div id="navigation-background">

        <div id="r2d2-menu" class="clearfix">
        <ul id="pull">
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li id="open-nav"><a href="#r2d2-menu"><i class="fa fa-reorder"></i></a></li>
            <li id="close-nav"><a href="#"><i class="fa fa-times"></i></a></li>
        </ul>
        ';

        wp_nav_menu(array( 'theme_location' => 'site-navigation', 'container' => false, 'menu_id' => 'nav', 'menu_class' => '', 'fallback_cb' => false, 'walker' => new My_Walker_Nav_Menu() ));

        echo '    
        </div><!-- #r2d2-menu -->

        </div><!-- #navigation-background -->
        </div>
    </div>
    </div> <!-- #navigation -->

</div> <!-- #navigation-container -->
        ';

        return false; // Replaces normal menu for non-WordPress pages
    }
    return true; // WordPress returns normal menu
} // END


// GET FUNCTIONS FROM WORDPRESS SITE 2
} else if ($_SERVER[SERVER_NAME] == 'SITE2.COM') {
define('__ROOT__', 'SET/PATH/TO/WORDPRESS/FOR/SITE2'); // SET PATH TO WORDPRESS
require_once(__ROOT__.'/wp-includes/version.php'); global $wp_version;
require_once(__ROOT__.'/wp-load.php');

// SITE-WIDE NAVIGATION FROM WORDPRESS
function ttg_header_navigation( $style, $path ) {
    if (G_STYLE != 'CE4-WORDPRESS') {
        echo '
<div id="navigation-container" class="navigation-container clearfix">

    <div id="navigation" class="block-id navigation clearfix">
    <div class="mantle clearfix">
        <div class="core clearfix">
        <div id="navigation-background">

        <div id="r2d2-menu" class="clearfix">
        <ul id="pull">
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li id="open-nav"><a href="#r2d2-menu"><i class="fa fa-reorder"></i></a></li>
            <li id="close-nav"><a href="#"><i class="fa fa-times"></i></a></li>
        </ul>
        ';

        wp_nav_menu(array( 'theme_location' => 'site-navigation', 'container' => false, 'menu_id' => 'nav', 'menu_class' => '', 'fallback_cb' => false, 'walker' => new My_Walker_Nav_Menu() ));

        echo '    
        </div><!-- #r2d2-menu -->

        </div><!-- #navigation-background -->
        </div>
    </div>
    </div> <!-- #navigation -->

</div> <!-- #navigation-container -->
        ';

        return false; // Replaces normal menu for non-WordPress pages
    }
    return true; // WordPress returns normal menu
} // END


// GET FUNCTIONS FROM WORDPRESS SITE 3
} else {
define('__ROOT__', 'SET/PATH/TO/WORDPRESS/FOR/SITE3'); // SET PATH TO WORDPRESS
require_once(__ROOT__.'/wp-includes/version.php'); global $wp_version;
require_once(__ROOT__.'/wp-load.php');

// SITE-WIDE NAVIGATION FROM WORDPRESS
function ttg_header_navigation( $style, $path ) {
    if (G_STYLE != 'CE4-WORDPRESS') {
        echo '
<div id="navigation-container" class="navigation-container clearfix">

    <div id="navigation" class="block-id navigation clearfix">
    <div class="mantle clearfix">
        <div class="core clearfix">
        <div id="navigation-background">

        <div id="r2d2-menu" class="clearfix">
        <ul id="pull">
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li><span>&nbsp;</span></li>
            <li id="open-nav"><a href="#r2d2-menu"><i class="fa fa-reorder"></i></a></li>
            <li id="close-nav"><a href="#"><i class="fa fa-times"></i></a></li>
        </ul>
        ';

        wp_nav_menu(array( 'theme_location' => 'site-navigation', 'container' => false, 'menu_id' => 'nav', 'menu_class' => '', 'fallback_cb' => false, 'walker' => new My_Walker_Nav_Menu() ));

        echo '    
        </div><!-- #r2d2-menu -->

        </div><!-- #navigation-background -->
        </div>
    </div>
    </div> <!-- #navigation -->

</div> <!-- #navigation-container -->
        ';

        return false; // Replaces normal menu for non-WordPress pages
    }
    return true; // WordPress returns normal menu
} // END
}

Conditionally apply custom css:

// CUSTOM STYLESHEET FOR ALL SITES
function ttg_head_end( $style, $path ) {
  if ($_SERVER[SERVER_NAME] == 'SITE1.COM') {
 echo '
 <link rel="stylesheet" href="/phplugins/css/custom.css" />
    ';
 } else if ($_SERVER[SERVER_NAME] == 'SITE2.COM') {
 echo '
 <link rel="stylesheet" href="http://SITE2/phplugins/css/SITE2.css" />
    ';
 } else {
 echo '
 <link rel="stylesheet" href="http://SITE3/phplugins/css/SITE3.css" />
';
 }
}

Hope this helps someone, and let us know if it works for you.
Graceson

Last edited by gaufde (2015-01-18 10:16:04)


Graceson Aufderheide
gracesonaufderheide.com

Offline

#2 2015-04-09 21:32:59

pideja
Member
From: Montreal
Registered: 2013-02-26
Posts: 1,299

Re: One PHPlugin File for Multiple Websites - Solution

I'd like to try this. I have a main Home page that links to French and English sites. I'd like to implement your method of having specific CSS for each of the three sites : main, french and english.
But I'm not sure what is the Server Name?

Offline

#3 2015-04-09 22:06:45

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: One PHPlugin File for Multiple Websites - Solution

SERVER_NAME will yield everything after http:// or http://www. depending on your site address.

my site is at http://rodbarbee.com. So the SERVER_NAME will be rodbarbee.com

so, for example, your main site should need:

if ($_SERVER[SERVER_NAME] == 'lucnadeau.ca') {
   echo ' ---path to custom css --- ';


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

Board footer

Powered by FluxBB