• Resolved shngrdnr_fctry

    (@shngrdnr_fctry)


    I want to setup a page that will display different content for each registered user of my site who falls within a specially-created user role (‘map_user’). So, for example, if a site user who is in the ‘map_user’ category logs into the site they’re automatically forwarded to a specific page. This page then refers to their username, calls specific external content (html) based on that username and includes it in the page.

    I’ve managed to solve the first problem (forwarding users based on their user role) through a combination of plugins and functions. But I’m struggling with the second part, once they’ve arrived at the destination page.

    I’ve created a template for the page and included the following php within it:

    <?php if ( is_array( $user->roles ) && in_array( 'map_user', $user->roles ) ) : ?>
    	<div id="mapContent">
    		<?php require("/mapping/{$user->data->user_login}.html/"); ?>
    	</div>
    <?php endif; ?>

    Where am I going wrong? (My php skills are very much of the copy/paste or “steal and adapt” variety, so I’m prepared to have stupid mistakes pointed out to me ?? )

Viewing 1 replies (of 1 total)
  • Thread Starter shngrdnr_fctry

    (@shngrdnr_fctry)

    Resolved at stackexchange – here’s the answer:

    <?php global $current_user;?>
    <?php if(is_user_logged_in()) :?>
        <?php get_currentuserinfo();?>
        <?php if(is_array( $current_user->roles ) && in_array( 'map_user', $current_user->roles  ) ) : ?>
            <div id="mapContent">
                <?php require("/mapping/".$current_user->user_login.".html"); ?>
            </div>
        <?php endif; ?>
    <?php endif; ?>

    Note that the code above will link to a folder called ‘mapping’ in the website’s root folder – change the ‘require’ line to fit your needs (along with the other necessary fields o’ course).

Viewing 1 replies (of 1 total)
  • The topic ‘How can I call a specific file (via php) by referencing the logged-in username?’ is closed to new replies.