0

Is it possible make search widget/plugin/search form which you can find is the worpress multisite subdomain or username already exist or free?

Any tips where i can find it? Or code?

0

This function, which I use in my "Multisite Media Display" plugin, will put all subsites into an array. Note that there are two ways that are required to do this, depending on the WP versin, since wp_get_sites is deprecated as of 4.6+, but is still allowed in 4.6+, even though it doesn't return site names properly.

function mmd_get_sites_array($atts, $xedit=0) {
// needed since wp_get_sites deprecated as of 4.6+, but can't use replacement get_sites in < 4.6
global $wp_version;

// WordPress 4.6
if ( $wp_version >= 4.6 ) {     // instead of looking for deprecated functions that might still exist
    $subsites_object = get_sites();
    $subsites = objectToArray($subsites_object);
    foreach( $subsites as $subsite ) {
          $subsite_id = $subsite ["blog_id"];
          $subsite_name = get_blog_details($subsite_id)->blogname;
          $subsite_path = $subsite[path];
          $subsite_domain = $subsite[domain];
        switch_to_blog( $subsite_id );
        // show site id and path
        echo "<hr>Site:<strong> $subsite_id - $subsite_name</strong> ;   Path: <strong>$subsite_path</strong><hr>";
        $xsiteurl = $subsite_domain . $subsite_path;
        // do something here; previous creates the url of the site
        restore_current_blog();
    }
}
if ( $wp_version <= 4.5 ) {     // WordPress < 4.6
    $sites = wp_get_sites();

    // and this is how we loop through blogs with <4.6
    foreach ( $sites as $site ) {
        switch_to_blog( $site['blog_id'] );
        // following echos site id and path
        echo "<hr>Site:<strong> $site[blog_id]</strong> ;   Path: <strong>$site[path]</strong><hr>";
        $xsiteurl = $site[domain] . $site[path];
        // do something here, previous creates the URL of the site
        restore_current_blog();
    }
}

return ;        // return empty array due to fail
}

The $site array will contain site attributes.

Probably could be more efficient, or 'classed', but it works for my purposes.

Hope this helps you get started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.