• Anonymous User 8639124

    (@anonymized-8639124)


    I have a subset of users (defined by the user capability edit_dashboard) for whom I want their email address to appear next to their name on their author.php page:

    <h1><span><?php echo $curauth->display_name; 
    	if (author_can( $post->ID, 'edit_dashboard' )) {
    		echo "(".$curauth->user_email.")";
    	} ?>
    </span></h1>

    The problem I’ve run into is that it doesn’t output the email address if the user has zero posts. Is there a way to tweak that?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    That is not default behavior, there’s no reason for it. I’m guessing your theme or a plugin has suppressed emails for a specific purpose and is applying their filter too broadly. Depending on how the email is suppressed, you may need to identify the source of the filter by deactivating different components until the email shows up again, as it would if everything were deactivated and you used a default theme.

    Before going through that exercise, lets see if we can do an end run around this behavior. Try this variation:

    echo "(". htmlspecialchars( get_user('ID', $curauth->ID )->data->user_email ) .")";
    // ignore this line - single line code is handled in a way that I hate

    What this does is re-retrieves the user object and uses the raw data version of the email, which bypasses a number of filters, one of which sanitizes the data, so we sanitize it ourself with htmlspecialchars(). If this does not help, you’ll need to narrow down which module is causing the problem. Once found, try to identify any filter hooks with tags that include “user” or “email”. Maybe you can add code that removes the hook when it’s not needed.

    Thread Starter Anonymous User 8639124

    (@anonymized-8639124)

    Thanks a bunch for your help. Looks indeed like there’s a conflict somewhere. Just to double-check I’m using your suggested code correctly, does your echo solely replace my third line (my second echo), or does it replace everything from the first echo through to the closing bracket?

    My guess at the moment is there’s a conflict between my theme (Erudito) and my author page URL plugin (SF Author Url Control), but there’s enough funkiness when I test it that I should really wait until my dept finally gets a proper dev site set up.

    I’ll leave this topic open for now in the hopes I have an update soon!

    Moderator bcworkz

    (@bcworkz)

    It just replaces the one echo line complete, nothing else. If that doesn’t help, we can try getting the value straight out of the DB with $wpdb->get_var().

    I suspect the author plugin more than the theme. You could try getting a user object of someone with no posts, assign it to $curauth, then deactivate the plugin. I suspect the email will be output. No doubt having the plugin deactivated will break other things. It’s just a quick test for email output only. Once you’ve determined if the email is output or not, re-acitvate the plugin.

    Thread Starter Anonymous User 8639124

    (@anonymized-8639124)

    Alrighty, got it working. The issue was not having called the necessary info first. In my case, I failed to use the get_query_var function and the line $author_user = $wp_query->get_queried_object(); …

    <?php $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); ?>
    <div class="intro intro-archives">
    	<h1><span><?php echo $curauth->display_name;
    		$author_user = $wp_query->get_queried_object();
    		if (user_can($author_user, 'edit_dashboard')) { 				
    			echo " (".$curauth->user_email.")";
    		}		
    		?>

    etc

    • This reply was modified 7 years, 6 months ago by Anonymous User 8639124.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Generating author.php content when author has zero posts?’ is closed to new replies.