How to filter the _access_denied_splash() function, to change the wording.

The function is located in the wp-admin/includes/ms.php file. Here's what it looks like:

function _access_denied_splash() {
	if ( ! is_user_logged_in() || is_network_admin() )
		return;

	$blogs = get_blogs_of_user( get_current_user_id() );

	if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
		return;

	$blog_name = get_bloginfo( 'name' );

	if ( empty( $blogs ) )
		wp_die( sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ), 403 );

	$output = '<p>' . sprintf( __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>';
	$output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>';

	$output .= '<h3>' . __('Your Sites') . '</h3>';
	$output .= '<table>';

	foreach ( $blogs as $blog ) {
		$output .= '<tr>';
		$output .= "<td>{$blog->blogname}</td>";
		$output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' .
			'<a href="' . esc_url( get_home_url( $blog->userblog_id ) ). '">' . __( 'View Site' ) . '</a></td>';
		$output .= '</tr>';
	}

	$output .= '</table>';

	wp_die( $output, 403 );
}

I'd like to change the wording in the splash, without hacking the original file, so that the changes withstand wordpress updates. Planning on putting the code in the function.php file of my multisite theme, but need some coding guidance. Any ideas?

  • Kasia Swiderska

    Hello xbladerunner,

    You can use our plugin Ultimate Branding to do that https://premium.wpmudev.org/project/ultimate-branding and it's module for replacing text strings.

    If you prefer to use code, than you use filter gettext:

    add_filter( 'gettext', 'change_spash_text', 20, 3 );
    
    function change_spash_text( $translated_text, $text, $domain ) {
    
            switch ( $translated_text ) {
    
                case 'Your Sites' :
    
                    $translated_text = 'Replacement for new sites';
                    break;
            }
    
        return $translated_text;
    }

    Other method is to use fake translation file. So if you site is in English - you create files po and mo for English and then as "translation" you use change strings form this file.

    kind regards,
    Kasia

  • xbladerunner

    Thanks Kasia!

    I am familiar with the Ultimate Branding plugin and use it on all my networks. In this specific case, I find it better to use code to change the function output. I'm specifically trying to change the two instances of the output strings "You attempted to access..." and the output string "If you reached this..."

    I apologize that I am unclear about how to do this with the code you provided. For example, where would I put the first complex string, 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ...and where would I put its replacement? Does the get text method work in this instance, or do I need to essentially redefine the function?

    Thank you for your patience with me.

  • Nithin

    Hi @xbladerunner,

    Hope you are doing good today. :slight_smile:

    Since you are already using Ultimate Branding plugin, the above code makes it easier to implement your desired changes throughout your website. The value given in switch is compared to the value of each case, the case is where you need to add your string which you want to change.

    function change_spash_text( $translated_text, $text, $domain ) {
    
            switch ( $translated_text ) {
    
                case 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' :
    
                    $translated_text = 'Please, add your new string here';
                    break;
    
    	    case 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.':
    
    	    	$translated_text = 'Please, add your new string here';
    	    	break;
            }
    
        return $translated_text;
    }

    The value given to $translated_text as shown above, is where your string gets replaced.

    Take care and have a nice weekend. :slight_smile:

    Kind Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.