WordPress.org

Ready to get started?Download WordPress

Forums

Multisite User Management
Patch MSUM to only work with select blogs (8 posts)

  1. UmkaDK
    Member
    Posted 2 years ago #

    This patch is released for those who ran a large multi-site network (100+), where out of all user blogs only a few have a special meaning and need automatic registration of all users with a specific role.

    In other words this patch allows you to restrict operation of the MultiSite User Management plugin to a list of specific blogs. This is achieved in two steps:

    a) Define a coma separated list of blog ids for all blogs which you wish to be managed by the plugin

    define('MSUM_MANAGED_BLOGS', '1');

    b) Save the following code into a file msum.patch. Then apply it to ms-user-management.php by running patch -p0 < /path/to/msum.patch from the command line, in the same directory.

    --- ms-user-management.php	2012-01-17 05:07:14.000000000 -0800
    +++ ms-user-management.php	2012-01-17 05:07:14.000000000 -0800
    @@ -162,7 +162,10 @@
     function msum_get_blog_list( $start = 0, $num = 10 ) {
     	global $wpdb;
    
    -	$blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
    +    if ( defined('MSUM_MANAGED_BLOGS') )
    +        $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' AND blog_id IN (". MSUM_MANAGED_BLOGS .") ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
    +    else
    +        $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
    
     	foreach ( (array) $blogs as $details ) {
     		$blog_list[ $details[ 'blog_id' ] ] = $details;

    http://wordpress.org/extend/plugins/multisite-user-management/

  2. thenbrent
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks for sharing Dmytro.

  3. greatkanishka
    Member
    Posted 1 year ago #

    @Dmytro
    I am sorry , but the instructions are not clear to me.
    I get this code below and replace the ID's by my own say 12 in my case.
    define('MSUM_MANAGED_BLOGS', '1'); ,

    now, where do i put this define element.

    Secondly, can you please let me know, how have you yourself called the patch file. ?

    help please

  4. UmkaDK
    Member
    Posted 1 year ago #

    Hey greatkanishka,

    Apologies if anything I say seems a bit basic but I have no idea of how familiar you are with WP or PHP, so please bear with me... Also, I'm assuming that your WP runs on a Unix server and that you have command line access to that server.

    The first thing you want to do is to edit your wp-config.php, which is located in the root directory of your WP installation, and add define('MSUM_MANAGED_BLOGS', '12'); just above the /* That's all, stop editing! Happy blogging. */ line.

    On it's own, MSUM_MANAGED_BLOGS constant does absolutely nothing, so now you need to modify Multisite User Management plugin to look for it.

    Go to the plugin directory (cd wp-content/plugins/multisite-user-management) and save the above patch into a file called msum.patch. Now, you can apply that patch by running the following from the command line (stay in the plugin's directory!):

    patch -p0 < /path/to/msum.patch

    This will effectively replace line 196 (version 1.1 of the MSUM) of the ms-user-management.php file with the four lines prefixed with + above.

    Hope it helps,

    Dmytro

  5. greatkanishka
    Member
    Posted 1 year ago #

    Thanks for your quick reply !
    I am above average familiar with WP and PHP .. :)
    lol !! learn from you guys he he..
    Well , I am using cpanel to edit the file ..and I belive , i can do it now.
    I can see that function you listed above. What I am doing after you kind reply is.
    1. Add those blog id's to my config file.
    2. Replace the function by the one you gave above.

    I was just confusing with the unix server commands. Thats close book for me.
    Thanks Buddy !! Will update you if everything works fine.

  6. UmkaDK
    Member
    Posted 1 year ago #

    DO NOT replace the entire function!!

    Take out only line 196 (it should match the line prefixed with - in the patch above) and replace it with:

    if ( defined('MSUM_MANAGED_BLOGS') )
        $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' AND blog_id IN (". MSUM_MANAGED_BLOGS .") ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
    else
        $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
  7. greatkanishka
    Member
    Posted 1 year ago #

    Yup!!
    Done it Bro!! Thanks a ton.
    Now for others who are not familiar with UNIX commands and get confused like me.

    1. Add, this to your wp-config file
    define('MSUM_MANAGED_BLOGS', '12'); // blog ID, fresh IDs in each line

    2. Search for the function function msum_get_blog_list in multisite-user-management/ms-user-management.php and replace replace the following line of code

    $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );

    with this one

    if ( defined('MSUM_MANAGED_BLOGS') )
        $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' AND blog_id IN (". MSUM_MANAGED_BLOGS .") ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
    else
        $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND archived = '0' AND spam = '0' AND deleted = '0' ORDER BY registered DESC", $wpdb->siteid ), ARRAY_A );
  8. UmkaDK
    Member
    Posted 1 year ago #

    Nice one! :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic