I have a wordpress multisite install with 100+ users with blogs. Some users have more than one blog.
Users can pay for their blogs (think of it as a donation scenario), or they can choose to have a free blog. If they have a free blog then there is a variable in wp_Blog-ID_options called is_free_site
and it is set to 1. (Blog-ID relates to the users blog)
If the user is paying for their site, is_free_site
will either be set to 0 or the variable won't exist in the db at all. See screenshot:
http://www.awesomescreenshot.com/image/1657353/0238f2bf2d49f0b165170be6c64ba3a3
I am trying to write a function called does_user_pay
this will look to see if the current logged in user pays for any of their sites and if they do it returns true. This is so I can feed premium content to those who choose to pay
So for example, user A might have 2 sites, one which they pay for, one which they don't - so does_user_pay()
should be true
User B might have 1 site which they don't pay for, so does_user_pay()
will be false
user C might have 1 site which they pay for, so does_user_pay()
will be true.
I am coding this into a custom plugin, here is what I have so far:
function does_user_pay() {
global $current_user;
$user_id = get_current_user_id();
$user_blogs = get_blogs_of_user($user_id);
// Need to write a function here that checks if any of the user blogs are paid for
if(is_user_logged_in() && USER_HAS_PAID_SITE) {
return true;
} else {
return false;
}
}
Any help would be really appreciated
You can do this check in this way (assuming user is logged and his id is stored in $user_id):
$blogs = get_blogs_of_user($user_id); // array with all user blogs
foreach($blogs as $blog){
switch_to_blog($blog->userblog_id); // switch the blog
$is_free_site = get_option('is_free_site', 0); // get the option value (if not exists, so the user paid, we'll get 0)
restore_current_blog(); // it's important to restore after a switch blog
if($is_free_site == 0) return true; // found a paid blog
}
return false; // not found a paid blog