Multisite Global Search

While searching for WordPress’ Search method on Google, I came across this useful Multisite Search Plugin by Grial. It’s a simple plugin that utilizes database views for it’s search routine.

Basically, it enables you to search your site and your network using WordPress’ native search methods. The Plugin’s features include:

  • Search on posts and pages.
  • Clean database when the plugin is deactivated.
  • Put search form into your code.
  • Insert search form in templates using a shortcode:
  • Use type attribute to select vertical form or horizontal form. Default attribute value: vertical.
  • Use page attribute to change results page URI. Default attribute value: globalsearch.
  • Show excerpted results
  • Multisite Global Search Widget. Show a search form in your sidebar.
  • Customizable relative URI for results page.
  • Two different form types, vertical and horizontal.
  • Search across all network blogs or only in your blogs if you are logged.

A very useful Plugin indeed. If you need a Plugin that let’s you search your network, I suggest that you get this.

A very interesting note to remember, while this uses Database Views as it’s method for querying, some hosting accounts might not be able to install this plugin. Your database user should have the CREATE VIEW privilege to be able to activate this wonderful plugin. You can execute this SQL statement logged in as root to be able to achieve this. Surprisingly, Cpanel’s All Privileges isn’t enough.

GRANT CREATE VIEW ON {databasename}.* TO {databaseuser}@{host}
change databasename, databaseuser and host accordingly

Visit the Plugin’s Homepage for more information, or download directly from WordPress.org/extend.

Have a great day everyone.

Recent Comments from All Blogs from your Network

Howdy, we’re here again to share a simple snippet of code to create a widget for your WordPress Blog Network. This piece of code will fetch comments from every site and show it as a simple widget on your sidebar. Very useful for Multisite Installations.

Here is the code. Paste it to your functions.php file on your theme folder and you’re all set.


			

    get_results("SELECT blog_id FROM $wpdb->blogs", ARRAY_A); $old = $wpdb->blogid; $comments = array(); foreach ($blogs as $blog) { $wpdb->set_blog_id($blog['blog_id']); $query = get_comments(array('status' => 'approve', 'number' => 3, 'type' => 'comment')); $count = count($query); for ($i = 0;$i < $count;$i++) { $post = get_post($query[$i]->comment_post_ID); $query[$i]->permalink = get_blog_permalink($blog['blog_id'], $post->ID); $query[$i]->post_title = $post->post_title; } $comments = array_merge($comments, $query); } $wpdb->set_blog_id($old); function cmp($a, $b) { if (strtotime($a->comment_date) == strtotime($b->comment_date)) { return 0; } return (strtotime($a->comment_date) < strtotime($b->comment_date)) ? -1 : 1; } usort($comments, "cmp"); $comments = array_slice($comments, 0, $limit); if ($comments) { foreach ($query as $value) { ?>
  • comment_content; ?> on post_title; ?>

    comment_date)); ?>
  • } } else { ?>
  • There are no Comments in this Network

Have a great day 🙂

WordPress Multisite Custom Registration

There are quite a few plugins that solve this problem, mainly because WordPress’ Multi Site implementation isn’t as flexible and as documented as it’s single installation counterpart. We will try to make a basic custom Multisite Registration with Custom Passwords and ReCaptcha.

Warning: This is a Core Hack. This solution is messy and might break on upgrade. Since, there are no hooks that support this at the time of this writing.

First, you add registration.php to your Theme file. This piece of code hooks to WordPress’ current registration method which is in wp-signup.php


get_error_message('empty_password') ) { ?>
	

get_error_message('empty_confirm') ) { ?>

get_error_message('empty_captcha') ) { ?>

add('empty_password', "Please enter your desired Password below"); } if ($_POST['user_pass'] != $_POST['user_confirm_password'] || $_POST['user_confirm_password'] == '') { $result['errors']->add('empty_confirm', "Please enter your Password again"); } if (!$resp->is_valid) { $result['errors']->add('empty_captcha', "Please enter the letters you see below"); } } return $result; } function show_blogform($result) { $reg = get_option('signup_registration'); $reg[$_POST['user_email']] = $_POST['user_pass']; update_option('signup_registration', $reg); return $result; } ?>

This basically hooks the code to your WordPress installation and let’s it run when the user is on the sign up page. It also validates the passwords and the Captcha so that we don’t get any spam registrations or wrong input.

For this to work though, you need to include this file from your functions.php. Add this line anywhere on your function.php.

include 'registration.php';

You will also need the ReCaptcha PHP Library on the same directory as your registration.php file. You can download at Google. Directory must be named “recaptcha” to work, recaptchalib.php must be directly under the recaptcha directory.

Add this Snippet of code starting at line 698 on ms-functions.php on your wp-includes folder. This line is after $user_id = username_exists($user_login);

...
$reg = get_option('signup_registration');
$password = $reg[$user_email];
unset($reg[$user_email]);
update_option('signup_registration', $reg);
...

This tells WordPress that we will set our own password from our password store.

After doing everything here, you should be bale to see your custom MultiSite Registration Page. You can download the files used here.

I will update the code as neccessary when this can be done as a full blown plugin.

For suggestions or modifications to the existing code. Please comment below.