PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label multisite. Show all posts
Showing posts with label multisite. Show all posts

Sunday, July 3, 2022

[FIXED] How can I convert a folder into a sub domain?

 July 03, 2022     .htaccess, mod-rewrite, multisite, redirect, subdomain     No comments   

Issue

I have a website that looks like this (the Ferrari is not a physical folder is an alias virtual):

www.example.com/en/ferrari

and I would like to convert this site into a sub-domain, like so:

ferrari.example.com

or something like:

ferrari.example.com/en/


The idea is to have all sub-pages from the Ferrari section working inside the sub-domain.

I don't know if this is even possible, all my .htaccess test didn't worked out. I am searching for a re-write rule but I don't seem to find it.

EDIT:

Let me rephrase the question, I don't want to REDIRECT from example.com/ferrari to ferrari.example.com

What I want is to show the example.com/ferrari site when someone opens ferrari.example.com. That is the difficult part. If someone opens ford.example.com, I want to show all the pages that are inside example.com/ford.


Solution

You can use that in your root .htaccess:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^ferrari\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/en/ferraricars [NC]
RewriteRule ^(?:en/)?(.*) en/ferraricars/$1 [NC,L]

Work with ferrari.example.com/en/other and ferrari.example.com/other -> example.com/en/ferraricars/other



Answered By - Croises
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to replace instance of WordPress home_url hyperlink via functions.php

 July 03, 2022     multisite, php, wordpress-theming     No comments   

Issue

The WordPress theme I'm using applies a home_url() link to the header logo and I'd like to change it to network_home_url()... Easy enough if I am editing the theme files but I'd like to do it via the child theme functions.php file so I can keep all my tweaks separate from the main theme (it's a multisite installation).

This is what I'm working with (albeit simplified):

<div class="logo">
    <a href="<?php echo home_url(); ?>">
        <img src="/image.png">
    </a>
</div>

I've tried the following, which worked but resulted in a site-wide change (including WP settings, etc) which in turn broke all the permalinks:

add_filter('home_url', 'change_logo_link');
function change_logo_link($output) {
    return network_home_url();
}

Is there a way I can target that specific hyperlink without editing the parent theme files? I don't think the home_url function is used anywhere else in the theme so it doesn't need to be too specific, I just want to avoid affecting the WP settings.

Thanks in advance!!!


Solution

The concept of child themes is to allow customizing of almost everything without changing the parent theme. Just copy your parent theme's template file with that logo code to your child theme's folder and replace home_url() with network_home_url(). WordPress will use that modified child template instead of parent one if you activate this child theme on your network site.



Answered By - Ihor Vorotnov
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to load User Meta?

 July 03, 2022     author, meta, multisite, php, wordpress     No comments   

Issue

Wordpress author.php is not loading the correct information from user meta. It's loading whoever is currently logged in to the blog and not displaying the person who it links to for example:

http://www.website.com/author/username1
http://www.website.com/author/username2

is displaying the same despite been two different users. I've done what is asked, however I'm still confused to why its only loading the currently user meta and not the meta of the username?

This is my author template:

<?php get_header(); ?>  

<div class="author-name">
<?php echo get_the_author_meta('first_name'); ?>
<?php echo get_the_author_meta('last_name'); ?> 
<?php echo get_user_role('user_role'); ?>
</div>

<div class="author-information">
Username: <?php echo get_the_author('user_nicename'); ?>
</div>

<?php get_footer(); ?>  

Solution

You must supply the User ID when using get_the_author_meta() to get a different user than the one in the loop or currently logged in.

Assuming username1 and username2 are actual usernames in the users database table you can get the username from the URL by using the following snippet:

$username_from_url = basename( get_permalink() );

And then:

$user = get_user_by( 'login', $username_from_url );

Now you have the full $user object with ID and everything.

Edit: complete solution

User visits an URL with the following pattern /page/somename where somename corresponds to the user´s user_nicename in the database table users.

<?php
    $username_from_url = basename( get_permalink() );
    $user = get_user_by( 'slug', $username_from_url );

    echo get_the_author_meta( 'first_name', $user->ID );
    echo get_the_author_meta( 'last_name', $user->ID );

    foreach ($user->roles as $role) {
        // You can also use get_role( $role ) to get more data on the role
        echo $role;
    }

    echo __( "Username:" ) . " " . $user->user_nicename;
?>


Answered By - Niklas Brunberg
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to set-up Wordpress Multi-sites on Azure using sub-directories

 July 03, 2022     azure, multisite, wordpress     No comments   

Issue

A question on Wordpress Multisite running on Windows Azure using Sub-directories: does it work? how do you do it?.

I've installed Wordpress(4.2.2) from the Azure Gallery, updated the wp.config.php and web.config files to enable and install Multisites, but the result is a half working solution: Multi-sites is installed, and I can create and delete new sites, but the new sites have no css styling (404 errors) and I can't access their admin dashboards (404: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable).

So, for example, the base website:

http://mywordpressmultisite.azurewebsites.net

works fine. But the multi-sites:

http://mywordpressmultisite.azurewebsites.net/site2/ http://mywordpressmultisite.azurewebsites.net/site3/

Display an unstyled css website, but I can't really do anything with them since I have no admin access; a routing error perhaps.

More Details

I've followed this how to article: https://azure.microsoft.com/en-gb/documentation/articles/web-sites-php-convert-wordpress-multisite/, to set-up Wordpress Multisite on Azure for sub-directories. I haven't followed on past the section entitled Add Custom Domains because I don't want to do that (yet, anyway).

My web.config file is:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WordPress Rule 1" stopProcessing="true">
                    <match url="^index\.php$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 2" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                    <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
                </rule>
                <rule name="WordPress Rule 3" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                    </conditions>
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 4" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:1}" />
                </rule>
                <rule name="WordPress Rule 5" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 6" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

My wp-config.php is:

define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'mywordpressmultisite.azurewebsites.net');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Things I've tried

  • Using both the Free and Shared hosting solutions.
  • Checking permalinks work on standard wordpress and the base No1 site (so mywordpressmultisite.azurewebsites.net/helloworld works).
  • Scrubbing down the database and starting the whole process again.
  • Changing file permissions to allow read, write and execute; just in case.

Debugging

I've configured the WebApp on Windows Azure to log everything possible but it's not spitting anything out. There's nothing in the php_error.log or other log files that I can find. I've configured wordpress wp-config.php as follows, but again nothing is being produced that I can find:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', true);
@ini_set('display_errors', 0);

Where I am I'm flat out of ideas on how to get this work, and I'm beginning to wonder whether it actually does work on Azure for sub-directories? I have seen other references to this issue on the web but no solutions.


Solution

This stackoverflow question on IIS has the answer:

getting 404 error on admin panel for sub-directory multisite on a sub-domain in wordpress

It gives this XML for the web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WordPress Rule 1" stopProcessing="true">
                    <match url="^index\.php$" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 2" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" />
                    <action type="Rewrite" url="wp-includes/ms-files.php?file={R:2}" appendQueryString="false" />
                </rule>
                <rule name="WordPress Rule 3" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                    <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
                </rule>
                <rule name="WordPress Rule 4" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                    </conditions>
                    <action type="None" />
                </rule>
                <rule name="WordPress Rule 5" stopProcessing="true">
                    <match url="(^[_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 6" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>
                <rule name="WordPress Rule 7" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

I've uploaded this to Azure and it works. Theme's and dashboard are now accessible.

Not sure where the error is in the original web.config, which I would like to know as Wordpress seems to be providing the wrong web.config xml, but http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference may help work it out.

Edit:

It would seem these IIS web.config routing rewrite rules are based on the Apache .htaccess and Mod rewrite rules given here: https://codex.wordpress.org/Multisite_Network_Administration

The web.config which I found and used above, which does work, would appear to be derived from a .htaccess file targetting Wordpress versions of < 3.5.

Where as the original version provided by Wordpress, as part of the Mulisite install, is based on the .htaccess files targeting Wordpress 3.5+.

Web.config File Differences

Referencing rules from the working web.config in relation against those in the one which doesn't work:

  • Rule 1: Is identical.
  • Rule 2: This is an additional rule. Reviewing the Wordpress documentation this rule is no longer required for Wordpress versions 3.5+ (fresh installs) as ms-files.php is no longer used, so it can be removed.
  • [The following rules below are now out of sync!]
  • Rule 3: Identical to non working web.config's rule 2.
  • Rule 4: Identical to the orignal web.config's rule 3.
  • Rule 5. Almost the same, but the back reference url="{R:1}" is different. The working version uses url="{R:2}". I have seen this fix referenced elsewhere too.
  • Rule 6: This is similar to the Rule 5 in the original file, but the regular expression is shorter; However, it looks to me like these regular expressions may amount to the same thing. I'm sticking with the shorter version.
  • Rule 7: Identical to rule 6 in original web.config.

Leaving me with a reworked version which now looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="WordPress Rule 1 Identical" stopProcessing="true">
                    <match url="^index\.php$" ignoreCase="false" />
                    <action type="None" />
                </rule>

                <rule name="WordPress Rule 3 Identical" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?wp-admin$" ignoreCase="false" />
                    <action type="Redirect" url="{R:1}wp-admin/" redirectType="Permanent" />
                </rule>

                <rule name="WordPress Rule 4 Identical" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" />
                    </conditions>
                    <action type="None" />
                </rule>

                <rule name="WordPress Rule 5 R2" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>

                <rule name="WordPress Rule 6 Shorter" stopProcessing="true">
                    <match url="^([_0-9a-zA-Z-]+/)?(.*\.php)$" ignoreCase="false" />
                    <action type="Rewrite" url="{R:2}" />
                </rule>


                <rule name="WordPress Rule 7 Identical" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>


Answered By - Anthony
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to get users who belong to a WordPress Multisite blog (site) with SQL?

 July 03, 2022     multisite, sql, wordpress     No comments   

Issue

I need to get all the users who have joined (are members) of a site (blog) in WordPress multisite. To complicate it, I am doing this outside of WordPress and don't have access to internal Wordpress functions, so need to construct the SQL directly.

In English the SQL would break down as "get an array of user IDs of users that are members of site x" (where site relates to one of the WordPress Multisite sites).

I've tried going through WordPress code to understand, but struggling with the above.

I don't need the PHP, I can work that out, just an example SQL statement.

Many thanks!


Solution

  1. select * from wp_blogs

From the output of the command note down the blog_id you want the users of. For eg: say you are wanting the users of the site with blog_id = 2 , next run the following query.

  1. select * from wp_users u join wp_usermeta um on u.id=um.user_id where um.meta_key="wp_2_capabilities"


Answered By - Anand Shah
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to setup multisite hosting with bitnami VM

 July 03, 2022     bitnami, host, multisite, virtual-machine     No comments   

Issue

I would like to host a wordpress site. But I have a owncloud bitnami VM that is works very well.

Is it enough to set different domains or subdomains in apache configuration?


Solution

As you are using a Bitnami installation, you can download the Bitnami Wordpress Module: https://bitnami.com/stack/lamp/modules

After the installation, you will have both Owncloud and Wordpress. If you don't like the default configuration, you can adapt the Apache prefixes and virtual hosts to fix your needs.



Answered By - Javier Salmeron
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to configure correctly Wordpress Multi Site on Amazon AWS EC2?

 July 03, 2022     amazon-ec2, amazon-web-services, multisite, wordpress     No comments   

Issue

I created an amazon ec2 t2micro instance and installed on it Wordpress Multi Site (Bitnami) from the aws marketplace. After the installation I couldn't add a site to the network. I decided to change the mode to sub_folder instead of sub_domain, so I connected through ssh to edit the wp-config file.

I changed define('SUBDOMAIN_INSTALL', true); to define('SUBDOMAIN_INSTALL', false);

After this editing nothing changed so I decided to look for the .htaccess file. I edited the htaccess this way

`RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]`

Now I'm trying again to add a site to the network but after the creation of the new site I can't see the dashboard. What should I do?


Solution

  • Missed these commands from bitnami documentation

    sudo ./bnconfig --machine_hostname my-domain.com
    
    sudo mv bnconfig bnconfig.disabled
    
  • Assigned the DNS to Route53 setting custom DNS on my namecheap account. Added an A type DNS Record for the specific subdomain that points to my Elastic Ip Address.

It works now!



Answered By - Alessandro Carrese
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to Create Wordpress Multisite user with network admin privleges

 July 03, 2022     multisite, wordpress     No comments   

Issue

I created a new user with Admin privileges and realized it cannot see the Network Admin menu. I have one user with Network Admin, but I want to create a different user with those privileges.

Can't figure out how.

Help!


Solution

For adding a user to the sites in Multisite first loge in with admin privilege that you have then go into the network setting and in the sites section on each sites you have to go in the users tab and then add the user you want to have the privilege or create one in there and the user will have the appropriate privilege



Answered By - KamyarMK
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I add a slug to the end of "siteurl" in this Wordpress redirect plugin?

 July 03, 2022     multisite, php, plugins, wordpress     No comments   

Issue

On Wordpress multisite I am using the "redirect-multisite-user-to-their-own-site" plugin for users who login from the frontend to be redirected to their own specific blog. However, this plugin only redirects to the user's blog's homepage (e.g. mulstisite.com/users-site), rather than the dashboard (e.g. mulstisite.com/users-site/wp-admin). I want the user to be redirected to their dashboard.

In the plugin's code (see below, included in full), they have wp_redirect($user_target_site->siteurl);. I don't know PHP well yet and need it to somehow go to $user_target_site->siteurl + /wp-admin. How can I accomplish this? I am happy to edit the plugin and create my own plugin to prevent it being overridden by plugin updates.

    <?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();

Solution

As long as you're aware of the implications of changing a plugins code, try changing this line;

wp_redirect($user_target_site->siteurl);

To this:

wp_redirect($user_target_site->siteurl . "/wp-admin/");


Answered By - user7236046
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to show primary menu of main site throughout multi-site network

 July 03, 2022     genesis, menu, multisite, navigation, share     No comments   

Issue

I have managed to switch the primiary navigation menu of my subsites to show the main site primary navigation.

However, it renders above the site-header instead of in the menu location dictated in the code.

Here is the code I currently have:

    function wp_multisite_nav_menu() {
    global $blog_id;
}
    if ( ! is_multisite() || 2 == $blog_id ) {

    switch_to_blog( 1 );

    wp_nav_menu( array(
        'menu'              => 2,
        'fallback_cb'       => false,
        'menu_class'        => 'genesis-nav-menu',
        'theme_location'    => 'Primary Navigation Menu',

    )); 

    restore_current_blog(); 

}

I was expecting the menu to be placed in the 'Primary Navigation Menu' location.

What have I missed?

Any clarity is appreciated.

UPDATE

I managed to figure it out for my primary and secondary menus however how do get the site title to change to the main site title and hyperlink?

Here is the code I currently have minus the site title switch

//*Multisite global menus

//*Primary global menu
add_action('genesis_after_header', 'primary_menu_switch');
function primary_menu_switch() {
    global $blog_id;
    if ( ! is_multisite() || 2 == $blog_id ) {
    switch_to_blog( 1 );

    wp_nav_menu( array(
        'menu'              => 2,
        'fallback_cb'       => false,
        'menu_class'        => 'genesis-nav-menu',
        'theme_location'    => 'primary'
    ) );

    restore_current_blog(); 
}
}


//*Secondary global menu
add_action('genesis_header_right', 'secondary_menu_switch');
function secondary_menu_switch() {
    global $blog_id;
    if ( ! is_multisite() || 2 == $blog_id ) {
    switch_to_blog( 1 );

    wp_nav_menu( array(
        'menu'              => 17,
        'fallback_cb'       => false,
        'menu_class'        => 'genesis-nav-menu menu-primary responsive-menu',
        'theme_location'    => 'primary'

        ));         
    restore_current_blog(); 
}
}

//*Use main site title

function site_title_switch() {
    global $blog_id;
    if ( ! is_multisite() || 2 == $blog_id ) {

    switch_to_blog( 1 );



   restore_current_blog();  

}
} 

I am a complete novice so please excuse the hack job.

Your insights are appreciated.


Solution

This is an answer to the updated question, not the one in the title.

This should do the trick, if you put it in a network activated plugin. Read the comments to see what it does exactly. It might not work depending on how your theme is made. I made it for the Twenty Eleven theme.

Keep in mind that it will change the home URL everywhere where it is called with a path '/', not only in the header.

add_filter( 'option_blogname', 'function_to_filter_the_blogname' );

// Changes the blog name of all sites that are not the main one to the name of the main one, only outside of the admin panel
function function_to_filter_the_blogname( $name ) {
    $main_site_id = get_main_site_id();
    if ( get_current_blog_id() != $main_site_id && ! is_admin() ) {
        return get_blog_option( $main_site_id, 'blogname' );
    }
    return $name;
}

add_filter( 'home_url', 'function_to_filter_the_home_url', 10, 4 );

// Changes the home URL of all sites that are not the main one to the home URL of the main one, only outside of the admin panel and only when the path is '/'
function function_to_filter_the_home_url( $url, $path, $orig_scheme, $blog_id ) {
    $main_site_id = get_main_site_id();
    if ( $blog_id != $main_site_id && ! is_admin() && '/' == $path ) {
        return get_blog_option( $main_site_id, 'home' );
    }
    return $url;
}


Answered By - Nikolay
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] When Single User Logged In One Wordpress Site then user can automatically Logged-in other User's related site

 July 03, 2022     codex, multisite, wordpress     No comments   

Issue

I want Multisite Wordpress Network.In which when user login in one site then there are option for login in particulate this user's related sites.

And If User login in one site.(on subdomain) User also able to login there other sites. with some link or option. (on subdomain). all site are in same domain.

I Have Tried https://codex.wordpress.org/Create_A_Network. But this is not helpful for me. Because here only network admin can add theme/plugin. and only network admin can access all sites.

I have already tried this article "https://kinsta.com/blog/share-logins-wordpress/". But With this I am able to share same credential of user. Not any link or option for login in other site.


Solution

Solution :

Our goal is to set up two WordPress websites which will share logins and the same users. Once a user has subscribed one

website, she would be able to access the other website with the same role and capabilities.

step 1: In order to share the same users and usermeta tables, WordPress installations must share the same database. add prefix of first wordpress installation first_ and second wordpress installation table second_. in same database.

step 2: When the first WordPress website is up and running, we can edit its configuration file. Open /first/wp-config.php

and add the following lines above the ‘stop editing’ comment:

 $table_prefix  = 'first_';
 define('WP_DEBUG', true);
 define( 'WP_DEBUG_LOG', true );
 define( 'WP_DEBUG_DISPLAY', false );
 @ini_set( 'display_errors', 0 );  

// custom users and usermeta tables
define( 'CUSTOM_USER_TABLE', $table_prefix . 'users' );
define( 'CUSTOM_USER_META_TABLE', $table_prefix . 'usermeta' ); 

/* That's all, stop editing! Happy blogging. */

step 3: We are done with the first installation. Next we have to copy wp-config.php from the first installation folder and

paste it into the root folder of the second installation. Be careful to change the $table_prefix value accordingly:

open /second/wp-config.php.and add the following lines above the ‘stop editing’ comment:

 $table_prefix  = 'second_';
    define('WP_DEBUG', true);
    define( 'WP_DEBUG_LOG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', 0 );

      // custom users and usermeta tables
     define( 'CUSTOM_USER_TABLE', 'first_users' );
     define( 'CUSTOM_USER_META_TABLE', 'first_usermeta' );

step 4: write in both wp-config.php for sharing cookies.

    //Share cookies
   define('COOKIE_DOMAIN', '.xyz.com');
   define('COOKIEHASH', 'aee53c017c29dc0d3ae37253fc8cbfd8');

step 5: Open table "first_usermeta" and copy from column meta_key - first_capabilities and first_user_level to the second_capabilities and second_user_level.

step 6: When running the second installation, we should set a non-existent email address for admin user as WordPress finds a number of existing users from first_users table.

For more Detail https://kinsta.com/blog/share-logins-wordpress/.

It's work for Me.



Answered By - MageDev
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[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)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to set and get common variable in session for MultiSite WordPress?

 July 03, 2022     multisite, session, wordpress     No comments   

Issue

I am using MultiSite WordPress. I want to set and get common variable in session/cookies for all sites.

My sites are:

NetWrok site:

http://www.sitename.com

SubDomain sites are:

http://hindi.sitename.com

and

http://urdu.sitename.com

The problem is when I set session value in "http://www.sitename.com" but not able to get that value in "http://hindi.sitename.com" and "http://urdu.sitename.com"

Is there any other solution to do this?

Thanks in advance


Solution

Using session cookies across subdomains is a well known problem: PHP Sessions across sub domains

However if you want to share common informations across your wordpress multisite sites the following may work (as :

$some_name = session_name("shared_multisite_sesssion");
session_set_cookie_params(0, '/', '.sitename.com');
session_start();

Use only cookies for sessions

session.use_only_cookies = 1
session.cookie_httponly = 1

Set the following parameteres in your WordPress config:

define( 'COOKIE_DOMAIN', '.sitename.com' ); // Dot prefix
define( 'COOKIEPATH',    '/' );
define( 'COOKIEHASH',    md5( 'sitename.com' ) );

However there are a few warnings you should take into account:

  • WordPress multisite sites are sometimes independent - as soon as they have their own domain this will not work anymore (Share a cookie between two websites)
  • WordPress multisite sites in many setups are intended to be individual sites with similar design. It may not be the best architectural idea to connect those sites via common sessions.


Answered By - Blackbam
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I setup multiple wordpress installs on one domain?

 July 03, 2022     multisite, wordpress     No comments   

Issue

I wish to set up 2 wordpress installs for the same website. One for US english and one for UK english. They need to be more bespoke than just using a language plugin and so I will use 2 similar themes.

Both need to be on the same parent domain "foo.com" one will be foo.com/en-gb and the other foo.com/en-us.

I can't work out how to go about this efficiently.


Solution

A WordPress multisite network allows you to run and manage multiple WordPress sites from a single WordPress installation.

You can create new sites instantly and manage them using the same username and password. You can even allow other users to signup and create their own blogs on your domain.

You can efficiently maintain your two instances with whatever the languages you need

foo.com/en-gb and foo.com/en-us

Please check wordpress codex for more information.



Answered By - charan kumar
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to change default UserName for Network Super Admin WordPress?

 July 03, 2022     multisite, php, wordpress     No comments   

Issue

I have created multisite in WordPress. While creating the site I have given admin username for Network admin. Now I want to change the username of Network admin(Superuser).

I have tried the following steps:

  1. Find wp_users table and change old username with new username;
  2. FInd wp_sitemeta table and and edit the site_admins row as a:1:{i:0;s:5:”new username”;}

After doing this I am able to login successfully but the issue is that the top menubar of wp-admin is not displaying.

Any suggestion will be appreciated.


Solution

You must delete the old one and create a new one. Steps with wp-cli:

1) create a new user:

wp user create superadminuser your@email.com --role=administrator --user_pass=passwordsupersafe

2) grant super admin role to new user

wp super-admin add superadminuser

3) login with superadminuser and delete the old admin. Maybe change the email of superadminuser to the one admin had.



Answered By - Nicola Peluchetti
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to run two sites with single domain on wordpress?

 July 03, 2022     multisite, wordpress     No comments   

Issue

Sorry! I don't know that the question I am asking have a logic or not.

I am not able to figure out what to do. I am stuck up from yesterday.

Make a multi-site network or customize my wp theme.

So what do I mean.

I want my main website and my landing website to be on same domain but my landing page should be in with subdirectories.

for example:

My main website domain is something like this :  mywebsitemain.com

and

My landing page website is as follows : mywebsitemain.com/landing-page

Conclusion

1. Single domain
2. Two websites

Is this is achieve able without using multisite or not. If yes or no then how.


Solution

There is two way. 1)Setup two wordpress First is in the root directory("main wesite domain") And second one steup on the ("landing-page") directory. and when steup the wordpress then you should make both the table prefix different.

2)Make wordpress network Check url : https://codex.wordpress.org/Create_A_Network



Answered By - Ravindra Singh Meyda
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I cancel pending WordPress multi-site installation?

 July 03, 2022     cancellation, multisite, php, wordpress     No comments   

Issue

I'm trying to create a network of WordPress sites but missed selecting my target domain. Now installation wants to proceed on my default domain. I can't seem to return back to the "Create a Network of WordPress Sites - Network Details" screen. It's stuck on "Create a Network of WordPress Sites - Enabling the Network" screen.

I've tried disabling multi-site in wp-config.php file and re-enabling it but it takes me directly to the "Create a Network of WordPress Sites - Enabling the Network" screen.

I need to cancel any pending WordPress multi-site installation and start all over again.


Solution

Resolved this by deleting every row data in the "wp_site" and "wp_sitemeta" tables in my WordPress database. After that, it returned to the "Create a Network of WordPress Sites - Network Details" screen. Please note that I didn't have any active multisite setup.



Answered By - King Ukah
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I host a static website inside a Wordpress multisite installation?

 July 03, 2022     multisite, php, wordpress     No comments   

Issue

I would like to do the following:

Wordpress Multisite
- hosted static site in the directory but not utilising wordpress
  Wordpress additional site
  - /blog subfolder
  Wordpress additional site
  - /jobboard subfolder
  Wordpress additional site
  - /other subfolder

In short, I want to host my static website as the main Wordpress Multisite's site. It's an exported HTML Website ready to go. I haven't got time to convert it into a Wordpress site.

Is this possible, and if so, how do I go about doing it?


Solution

It should be possible to just drop the static website into any WordPress directory.

This is made possible, because of the rewrite rules in the .htaccess file.

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Before rewriting any request, the rewrite engine will check to see whether the request maps to an existent file or directory. If it doesn't, it passes the request to WordPress.



Answered By - fubar
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can a user have user role privileges that the user has in the sub-site, in which the user is member of?

 July 03, 2022     multisite, user-management, wordpress, wordpress-roles     No comments   

Issue

e.g. a User John is registered from and is a member of "SITE A" in a multisite network, where his assigned role is "Charter Member". So, what I want is that when JOHN visits "SITE B" he has the privileges (i.e. I can get his role) as he has in "SITE A". But also I don't want to make JOHN member of "SITE B"

By default WordPress stores user capabilities/role in user_meta table but with site prefix like wp_3. Meaning that user role is site-specific.


Solution

please check the plugin "WP Multisite User Sync" in wordpress codex



Answered By - Pixlogix
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to get magento customer session values in root index file for switching store view

 July 03, 2022     magento, multisite, session     No comments   

Issue

I have created 2 store views for my magento website running under magento 1.9.2, I need to use the same domain name for both of the websites. When a customer logged in, I need to change the store view to the second one. I need to check the customer session in the index.php file in root directory. But when I follow the below changes to index.php, I end up with an error

$store_id = 1;
//Check customer session here 
if(Mage::getSingleton('customer/session')->isLoggedIn()){ // Error occurs here
    $customer       = Mage::getModel('customer/session')->getCustomer();            
    $customerId     = $customer->getId(); 
    // $storeid  get logged in customer storeid may from customer custom attribute value added on admin edit form
    // $store_id value get changed here
}



Mage::app()->setCurrentStore($store_id);
umask(0);
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

if($store_id == 2)
$mageRunCode = 'mysecondshop';

Mage::run($mageRunCode, $mageRunType);

When I check the issue, I find that we cannot use Mage::getSingleton before Mage::run, but for my current situation for switching between stores, I need to get logged in user details before mage run. Is there any way to achieve my requirement?


Solution

In magento it is not possible to check session data unless Mage::run is initilaized. We need to do some temporary storage like cookie to achieve this. Hopefully the below steps will make it works.

Create a custom module with observer for saving, clearing and checking cookie. Your config.xml file is given below

<!--------------------------------------------------------------------->
<customer_login>
  <observers>
    <Company_Modulename_model_customer_login>
      <class>Company_Modulename_Model_Observer</class>
      <method>afterCustomerLoggedIn</method>
    </Company_Modulename_model_customer_login>
  </observers>
</customer_login>
<customer_logout>
  <observers>
    <Company_Modulename_model_customer_logout>
      <class>Company_Modulename_Model_Observer</class>
      <method>afterCustomerLoggedOut</method>
    </Company_Modulename_model_customer_logout>
  </observers>
</customer_logout>
<controller_action_layout_load_before>
  <observers>
    <Company_Modulename_model_layoutload_observer>
      <class>Company_Modulename_Model_Observer</class>
      <method>beforeLoadLayout</method>
    </Company_Modulename_model_layoutload_observer>
  </observers>
</controller_action_layout_load_before>
<!--------------------------------------------------------------------->

Observer implementation is given below

public function afterCustomerLoggedIn(Varien_Event_Observer $observer)
{
    $customer = $observer->getCustomer();
    $cid      = $customer->getid();
    $webId    = $customer->getWebsiteId();
    Mage::getModel('core/cookie')->set('_storeuid',$cid, 60*60*24*1);  // Create cookie
    Mage::getModel('core/cookie')->set('_storeid',$webId, 60*60*24*1); // Create cookie

}


public function afterCustomerLoggedOut(Varien_Event_Observer $observer)
{
    $customer = $observer->getCustomer();
    $cid      = $customer->getid();
    $webId    = $customer->getWebsiteId();  
    Mage::getModel('core/cookie')->set('_storeuid','0', 1); // Clear cookie
    Mage::getModel('core/cookie')->set('_storeid','0', 1);  // Clear cookie

}

Before rendering pages

public function beforeLoadLayout(Varien_Event_Observer $observer)
{


    $cookieValue = Mage::getModel('core/cookie')->get('_storeuid');
    $baseurl = Mage::getBaseUrl();

    if(Mage::getSingleton('customer/session')->isLoggedIn()){ // For more security , if someone change the cookie value


        $customer = Mage::getModel('customer/session')->getCustomer();          
        $webId    = $customer->getWebsiteId();
        $cid      = $customer->getId();

        if( $cookieValue != $cid ){

                Mage::getModel('core/cookie')->set('_storeuid',$cid, 60*60*24*1);
                Mage::getModel('core/cookie')->set('_storeid',$webId, 60*60*24*1);
                header("Location: ".$baseurl); exit;

       }
    }else{

        if( (isset($cookieValue)) && ($cookieValue > 0)  ){ // Clear cookie if session is cleared

            Mage::getModel('core/cookie')->set('_storeuid','0', 1);
            Mage::getModel('core/cookie')->set('_storeid','0', 1);
            header("Location: ".$baseurl); exit;

        }

    }
}

And Finally in index.php , you can check the cookie for switching the store value for loggedin customers

$store_id = 1;
if( (isset($_COOKIE['_storeur'])) && ($_COOKIE['_storeur'] > 0)  ){
    $store_id = $_COOKIE['_storeur'];
}

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

if($store_id == 2 ) $mageRunCode = 'store2';
if($store_id == 3 ) $mageRunCode = 'store3';
//....................
Mage::run($mageRunCode, $mageRunType);


Answered By - Team Techi
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

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
All Comments
Atom
All Comments

Copyright © PHPFixing