show content to the person with the new site ONLY

I am finishing up a default template for the new bloggers plugin.

there is a few things that need explanation though so i want to add a couple videos on each new site.

These videos should only be shown to them IF they are logged in to their own site and no one else. also no way for someone else to register to see them.

I tried the membership plugin and it has way to many options and im not even sure if those settings would carry over with the new blog plugin.

i looked in to the password protect one but that doesnt really work.

any input on how to do what i need done?

thanks much!

  • idevguy
    • Design Lord, Child of Thor

    Depending on what you want to do, you can check if they are an admin and only show content based on that like so in your template (if you want this on one page only you will want to make a custom page template for this purpose to keep it separate from your regular page.php template)

    <?php global $user_ID; if( $user_ID ) : ?>
    <?php if( current_user_can('level_10') ) : ?>
    
    Stuff you want admins to see here
    
    <?php else : ?>
    
    Stuff for anyone else (or remove)
    
    <?php endif; ?>
    <?php endif; ?>
  • Philip John
    • DEV MAN’s Apprentice

    Hiya!

    I think the best way for you to do this would be to create a custom shortcode.

    So... your template would contain the sample post which includes your shortcode (for example, [introductory_videos])

    Then, you'd have a custom plugin (or you could use functions.php in your default theme) which prints out the videos in place of the shortcode.

    // [introductory_videos]
    function introvids_shortcode( $atts ) {
        $output = ' ... code for embedding videos goes here ... ';
        return $output;
    }
    add_shortcode( 'introductory_videos', 'introvids_shortcode' );

    Then, wrap the output in is_user_logged_in to make sure only a logged in user can see the output, like so;

    // [introductory_videos]
    function introvids_shortcode( $atts ) {
        if (is_user_logged_in()){
            $output = ' ... code for embedding videos goes here ... ';
        } else {
            $output = 'Please <a href="/wp-login.php">login</a>.';
        }
        return $output;
    }
    add_shortcode( 'introductory_videos', 'introvids_shortcode' );

    Hope that helps.

  • thinkmarketact
    • Site Builder, Child of Zeus

    so i add the bottom section of code to functions with the videos

    and then with in the new tutorial page on the new blog template i add [introductory_videos]

    is_user_logged_in means what exactly? any logged in user or just the admin of the new blog?

  • Philip John
    • DEV MAN’s Apprentice

    is_user_logged_in means what exactly? any logged in user or just the admin of the new blog?
    Any logged in user. I looked for a way to detect the admin only but there's not a clear way that I was comfortable with. You might wanna research that further though.

    Phil

  • Jonathan
    • The Incredible Code Injector

    I agree with phil, in regards to steering clear of using level_10 as a method of detection...

    Rather use a capability that only admins have
    <?php if( current_user_can('delete_users') ) : ?>

    List of admin capabilities:
    http://codex.wordpress.org/Roles_and_Capabilities#Administrator

    Other than that, pretty decent advice :wink:

    @Phil

    I'd steered away from that because I thought that method of detection was being phased out... I may be mistaken though!

    Are you referring to using capabilities as a method of detection or the use of levels?
    I presume you mean levels (They've been on the chopping block for ever - lol)

  • idevguy
    • Design Lord, Child of Thor

    Yes, removing levels have been "talked about" for ever but I don't see anything ever actually happening with it until WordPress actually incorporates some form of user "role" or capability control in core lol...

    so what you are saying is that my advice which its exactly what you just said is "pretty decent" :wink:

  • Jonathan
    • The Incredible Code Injector

    so what you are saying is that my advice which its exactly what you just said is "pretty decent" :wink:

    @idevguy,
    Yip, that is what I am saying :wink: - your advice is spot on - lol.

    ----

    Thought I would leave it open as a conversation might be brewing?

    That's why I love wordpress, there are loads of ways to achieve the same effect. Some better than others, but what idevguy and Phil were recommending are probably the best ways to handle it :wink:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.