The MU forums have moved to WordPress.org

How to access $blog_id from newblog_notify_siteadmin filter hook (3 posts)

  1. prayhumbly
    Member
    Posted 16 years ago #

    I am trying to pull in some blog options using get_blog_option() in the newblog_notify_siteadmin filter for a plugin I am writing.

    I can't seem to figure out how to get the $blog_id of created blog though within my filter function.

    Here is the newblog_notify_siteadmin() function from wpmu-functions.php, line 1233:

    function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) {
    	global $current_site;
    	if( get_site_option( 'registrationnotification' ) != 'yes' )
    		return false;
    
    	$email = get_site_option( 'admin_email' );
    	if( is_email($email) == false )
    		return false;
    
    	$options_site_url = clean_url("http://{$current_site->domain}{$current_site->path}wp-admin/wpmu-options.php");
    
    	$msg = sprintf(__("New Blog: %1s
    URL: %2s
    Remote IP: %3s
    
    Disable these notifications: %4s"), get_blog_option( $blog_id, "blogname" ), get_blog_option( $blog_id, "siteurl" ), $_SERVER['REMOTE_ADDR'], $options_site_url);
    	$msg = apply_filters( 'newblog_notify_siteadmin', $msg );
    
    	wp_mail( $email, sprintf(__("New Blog Registration: %s"), get_blog_option( $blog_id, "siteurl" )), $msg );
    	return true;
    }

    As you can see, $blog_id was accessible on the previous line to the apply_filters( 'newblog_notify_siteadmin', $msg ); call.

    I've tried declaring global $blog_id, tried $current_blog->blog_id, but nothing seems to be in scope within my filter function.

    Is there a way to access this without core code modification?

  2. robclaisse
    Member
    Posted 15 years ago #

    Did you ever find a solution?

  3. jamescollins
    Member
    Posted 15 years ago #

    I just looked at the latest version of this code, and I don't think there's any way to easily obtain the blog id.

    The following line:
    $msg = apply_filters( 'newblog_notify_siteadmin', $msg );

    Should probably be:

    $msg = apply_filters( 'newblog_notify_siteadmin', $msg, $blog_id );

    It should be a simple change that is backwards compatible.

    I suggest creating a trac ticket and it'll probably be added to the next version of WPMU.

About this Topic

  • Started 16 years ago by prayhumbly
  • Latest reply from jamescollins