pay to blog filter

Hi all :slight_smile:

I’m trying to add a column to wpmu-blogs.php via manage_blogs_custom_column, but I can’t get that to work. So, since the deadline for this project is coming closer, I decided to hardcode that column in wpmu-blogs.php

The next problem is that I can’t filter on the new column (the column is the date when the blog expires btw) since the value of this is not in the wp_blogs table, but in the wp_X_options..

I’m not that into MySQL (the easy queries are not a problem, but I can’t seem to get the joins and all into my head :wink:), so I was hoping someone here could help me a little further.

The idea is to add the possibility sort on blog expiration date.

Btw, is there a way to add the possibility to search on (custom) user-fields? Like searching on lastname and get a list of all blogs that have users with that lastname (preferably only the administrators).

  • Andrew
    • Champion of Loops

    Hiya,

    The idea is to add the possibility sort on blog expiration date.

    As of 2.6.5 there’s not a filter on the query which is what I think you’d need to pull that off.

    Btw, is there a way to add the possibility to search on (custom) user-fields?

    I don’t believe there is a hook for that either.

    Thanks,

    Andrew

  • Hiranthi
    • Recruit

    I thought of a solution.. I’ve added a table, something like wp_blogs_two. Added the fields blog_id and blog_expire and I’ve edited the wpmu-blogs.php to sort on expiration date.

    Also added a field for user in put which should hold first- and lastname (perhaps more data in the future) and managed to add a search-query for that too.

    Still have to figure out how to update the user-field in the new table when data is updated in the profile, but I guess I’ll figure that out too :wink:

  • Hiranthi
    • Recruit

    Hmm.. apparently I should use add_action( ‘profile_update’, ‘function_name’ ) and/or add_action( ‘personal_options_update’, ‘function_name’ ) to be able to update the extra wp_blogs table, but I can’t get it to work..

    Unfortunately I also can’t find any specific data about those hooks that can help me further.

    Does anyone here know which one I’m supposed to use and how I should use it?

  • Hiranthi
    • Recruit

    I figured out what the problem was. To update the new table (and to be sure the user data was added to the right blog in that table) I was using the function get_blogs_of_user( $user_ID );

    The default of that function is get_blogs_of_user( $user_ID, $all = false ); and for some reason changing the second argument doesn’t change anything (I only want to extract the first blog, the site-admin blog is of no use to me in this case).. It always returns for all blogs (which I don’t want).

    Oh well, back to the thinking-table :wink:

  • Hiranthi
    • Recruit

    Ok, seems it was a good thing I had wpmu-functions.php opened :wink:

    My eye fell on the function get_active_blog_for_user( $user_id ) and I saw that the primary blog was retrieved like this: get_usermeta( $user_ID, "primary_blog" ). Used that in my function and now I can actually ‘extract’ the blog_id I need :smiley:

    Unfortunately the query still isn’t executed, so I’m still not done with this.. :slight_frown:

  • Hiranthi
    • Recruit

    Well, to be honest: the problem is solved now :slight_smile: My husband came downstairs and looked with me as I explained the problem and went exploring it more and I suddenly fixed it :slight_smile:

    The problem was how the filter/action was called. I now use: add_filter( 'profile_update', 'pay_to_blog_save_userinfo', 99 ); instead of add_action.

    The pest is that there are numerous hits on google when you look for profile_update wp and that every hit implements it different.. Tried everyone of ’em and this one works for me :slight_smile:

    Function is like this btw:

    function pay_to_blog_save_userinfo()

    {

    global $wpdb, $current_user, $user_ID;

    $blog = get_usermeta( $user_ID, "primary_blog" );

    $wpdb->query(" UPDATE {$wpdb->base_prefix}blogs_2 SET user = '{$_POST} {$_POST}' WHERE blog_id = '{$blog}' ");

    }

    Tried it with get_currentuserinfo(); but with that function the data in the blogs_2 table was constantly a step behind. Adding the 99 didn’t help, so now I’m using the post values to save the correct data :slight_smile: