"Discourse Username" in WP - what does it do?

AI 生成的摘要

The “Discourse Username” field in WordPress (WP) allows specifying the username for publishing posts from WP into Discourse. If left blank, it defaults to the plugin settings. For Single Sign-On (SSO) setups, it’s recommended to match the WP username.

Grex315 explained that this field is particularly relevant when allowing users to publish posts from WP into Discourse. However, if only admins can publish posts, this field can be ignored for regular users.

To hide this field from users, simon provided a PHP code snippet that can be added to the theme’s functions.php file, offering a more robust solution than hiding it via CSS.

What is the purpose of the “Discourse Username” field which is editable in the user’s profile in WP?

I sign up as a test user in WP and all is well - user is automatically created in Discourse with the same user name as in WP. Discourse Username in WP is blank at this point. Then I changed the Discourse Username in WP, logged out and logged in again - no changes.

This is all fine, but will probably confuse some users, so is it OK to hide that field in WP from the user? And, what is the best way to hide it?

Thanks.

If you allow users to publish posts from WP into Discourse this will assign the post in Discourse to the user specified in that field. Otherwise it will use the default from the plugin settings. You have to enter this field manually. If you are using sso this should match the wp username.

Thanks, @Grex315. Only an admin can publish posts in my setup, so I will ignore it for regular users.

Is there a better way to hide if than via CSS?

Yes, you can add something like this to your theme’s functions.php file:

add_filter( 'user_contactmethods', 'my_namespace_remove_discourse_user' );
function my_namespace_remove_discourse_user( $contact_methods ) {
    unset( $contact_methods['discourse_username'] );

    return $contact_methods;
}

Excellent! Thanks very much @simon.