jeudi 18 août 2016

What is the better approach to displaying a different page for logged in users in Wordpress?

I'm working on a wordpress-based webapp, in which I'd like to serve logged in users with a differnet front page (i.e a profile page instead of the marketing landing page).

There are 2 ways (I can currently think of) to achieve this effect in Wordpress:

1 - Settings the 'page' to show. The advantage is that it uses built in Wordpress functionality and is less patchy than #2. However, it requires having a page manually created and hardcoded into the theme functions.php file.

if( is_user_logged_in() ) {
    $page = get_page_by_title( 'Profile' );
    update_option( 'page_on_front', $page->ID );
    update_option( 'show_on_front', 'page' );
}

2 - Using a conditional in the beginning of index.php, which includes either A.php or B.php based on the current user status (logged in or logged out). The advantage of this approach is that it is less reliant on Wordpress and its pages feature, which in turn makes the theme more generic and more easily adjusted to non-wordpress environments if that ever becomes a requirement.
With that being said, this approach may also be considered an 'hack' (which isn't necessarily bad, but might have its flaws).

if (is_user_logged_in()) {
    include_once( 'A.php' );
} else {
    include_once( 'B.php' );
}

Is there any usability/performance/security concern I may not be aware of which could potentially make one approach better than the other?




Aucun commentaire:

Enregistrer un commentaire