Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

Protect specific page

Simple Membership Plugin › Forums › Simple Membership Plugin › Protect specific page

  • This topic has 5 replies, 2 voices, and was last updated 11 years, 6 months ago by Mogwai.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • February 11, 2015 at 10:45 am #983
    Mogwai
    Participant

    Hi there,

    I know that it’s something specific but i’ve look everywhere on the source code of Simple Membership plugin and could not find it.

    I’ve a plugin (Smartplaylist from CodeCanyon) and i need to do something.

    Is there a way to completly protect the content of a page ?

    If i protect this page which show my playlist, the player is available and the text of the article is protected.
    So seen the smartplaylist plugin use a specific template page to load his stuff, i was wondering if we can setup something on this page to check if the user is registered with his Simple membership account before loading the content of the page ?

    Is there a piece of code that we can use to check with PHP if a user is already registered with a SMP account or not before loading the page ?

    Thanks !

    I really need that to finished my setup.

    Thanks,

    (Latest SMP version & wordpress 3.9.2)

    February 14, 2015 at 1:21 am #994
    nur
    Participant

    a user can login indicates that she is registered. assuming that, following piece of code may work for you:

    
    $auth = BAuth::get_instance();
    
    if ($auth->is_logged_in()){
    // user is registered
    }
    else{
    // user is not registered.
    }
    
    February 16, 2015 at 9:46 am #1033
    Mogwai
    Participant

    Hi,

    Thanks for your reply.
    Sorry, but i’m not at ease with php code.

    So i have this on my file :

    <?php
    
    if (!defined('ABSPATH')) exit;
    
    function sap_script_playlist_templates() { ?>
    
    <script type="text/html" id="tmpl-sap-playlist-current-item">
        <# if ( data.image ) { #>
        <img src="{{ data.thumb.src }}"/>
        <# } #>
        <div class="sap-playlist-caption">
            <span class="sap-playlist-item-meta sap-playlist-item-title">“{{ data.title }}”</span>
            <# if ( data.meta.artist ) { #><span class="sap-playlist-item-meta sap-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
            <# if ( data.meta.album ) { #><span class="sap-playlist-item-meta sap-playlist-item-album">{{ data.meta.album }}</span><# } #>
            <# if ( data.meta.year ) { #><span class="sap-playlist-item-meta sap-playlist-item-year">{{ data.meta.year }}</span><# } #>
        </div>
    </script>
    

    So how can i ask to the user that he need to be registered with SMP to let it show the player ?

    February 17, 2015 at 4:16 am #1035
    nur
    Participant

    i am not sure what you are trying to achieve. give this a try:

    
    if (!defined('ABSPATH')) exit;
    
    function sap_script_playlist_templates() { 
    $auth = BAuth::get_instance();
    
    if ($auth->is_logged_in()){
    ?>
    <script type="text/html" id="tmpl-sap-playlist-current-item">
        <# if ( data.image ) { #>
        <img src="{{ data.thumb.src }}"/>
        <# } #>
        <div class="sap-playlist-caption">
            <span class="sap-playlist-item-meta sap-playlist-item-title">“{{ data.title }}”</span>
            <# if ( data.meta.artist ) { #><span class="sap-playlist-item-meta sap-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
            <# if ( data.meta.album ) { #><span class="sap-playlist-item-meta sap-playlist-item-album">{{ data.meta.album }}</span><# } #>
            <# if ( data.meta.year ) { #><span class="sap-playlist-item-meta sap-playlist-item-year">{{ data.meta.year }}</span><# } #>
        </div>
    </script>
    <?php
    }
    else{
      echo 'You need to login';
    }
    
    February 17, 2015 at 10:35 am #1039
    Mogwai
    Participant

    Hi there,

    I’ll be more precise, since i think you’re close to the solution.

    Here my player.php file that need to be protected.

    
    
    <?php
    
    if (!defined('ABSPATH')) exit;
    
    function sap_script_playlist_templates() { ?>
    $auth = BAuth::get_instance();
    if ($auth->is_logged_in()){
    ?>
    <script type="text/html" id="tmpl-sap-playlist-current-item">
        <# if ( data.image ) { #>
        <img src="{{ data.thumb.src }}"/>
        <# } #>
        <div class="sap-playlist-caption">
            <span class="sap-playlist-item-meta sap-playlist-item-title">“{{ data.title }}”</span>
            <# if ( data.meta.artist ) { #><span class="sap-playlist-item-meta sap-playlist-item-artist">{{ data.meta.artist }}</span><# } #>
            <# if ( data.meta.album ) { #><span class="sap-playlist-item-meta sap-playlist-item-album">{{ data.meta.album }}</span><# } #>
            <# if ( data.meta.year ) { #><span class="sap-playlist-item-meta sap-playlist-item-year">{{ data.meta.year }}</span><# } #>
        </div>
    </script>
    <script type="text/html" id="tmpl-sap-playlist-item">
        <div class="sap-playlist-item">
            <a class="sap-playlist-item-play" href="{{ data.src }}">
                <# if ( data.tracks ) { #>
                    <span class="sap-playlist-item-index">
                        {{ data.index ? ( data.index + '. ' ) : '' }}
                    </span>
                <# } #>
    
                <# if ( data.caption ) { #>
                    {{ data.caption }}
                <# } else { #>
                    <span class="sap-playlist-item-title">“{{ data.title }}”</span>
                    <# if ( data.artists && data.va && data.meta.artist ) { #>
                    <span class="sap-playlist-item-artist"> &mdash; {{ data.meta.artist }}</span>
                    <# } #>
                <# } #>
            </a>
    
            <# if ( data.meta.length_formatted ) { #>
            <div class="sap-playlist-item-length">
                {{ data.meta.length_formatted }}
            </div>
            <# } #>
    
            <# if ( data.download ) { #>
            <div class="sap-playlist-item-download">
                <a title="<?php _e("Download This Track", "smart-audio-playlists"); ?>" href="{{ data.src }}"><span class="dashicons dashicons-download"></span></a>
            </div>
            <# } #>
    
            <# if ( data.played ) { #>
            <div class="sap-playlist-item-played">
                <a title="<?php _e("Show Track Statistics", "smart-audio-playlists"); ?>" href="#"><span class="dashicons dashicons-chart-bar"></span></a>
            </div>
    
            <div class="sap-playlist-item-statistics">
                <?php _e("Track Played Total", "smart-audio-playlists"); ?>: <span>{{ data.played.total }}</span> | 
                <?php _e("Today", "smart-audio-playlists"); ?>: <span>{{ data.played.today }}</span> | 
                <?php _e("This Week", "smart-audio-playlists"); ?>: <span>{{ data.played.week }}</span> | 
                <?php _e("This Month", "smart-audio-playlists"); ?>: <span>{{ data.played.month }}</span>
            </div>
            <# } #>
        </div>
    </script>
    <?php }
    
    function sap_render_player($playlist, $args = array(), $echo = true) {
        static $instance = 0;
        $instance++;
    
        if (is_numeric($playlist)) {
            $playlist = sap_playlist($playlist);
        }
    
        $initial_volume = number_format(smart_sap_core()->get('player_initial_volume') / 100, 1);
    
        $defaults = array(
            'source' => 'page',
            'tracklist' => true,
            'artists' => true,
            'autoplay' => false,
            'playlist_class' => '',
            'max_width' => '',
            'link_playlist' => false,
            'volume' => $initial_volume,
            'thumbnail' => 'sap-track-image',
            'skin' => smart_sap_core()->get('player_skin'),
            'style' => smart_sap_core()->get('player_style'),
            'trackstats' => $playlist->show_track_statistics,
            'tracknumbers' => $playlist->show_track_numbers,
            'images' => $playlist->show_track_images,
            'download' => $playlist->show_track_download,
            'metadata' => $playlist->show_metadata,
            'native_ipad' => smart_sap_core()->get('player_native_ipad'),
            'native_iphone' => smart_sap_core()->get('player_native_iphone'),
            'native_android' => smart_sap_core()->get('player_native_android'),
            'track_use_playlist_image' => smart_sap_core()->get('track_use_playlist_image'),
            'track_use_default_image' => smart_sap_core()->get('track_use_default_image'),
            'tracklist_autohide' => smart_sap_core()->get('player_autohide_playlist'),
            'tracklist_toggle' => smart_sap_core()->get('player_toggle'),
            'tracklist_toggle_nohide' => smart_sap_core()->get('player_toggle_nohide'),
            'tracklist_toggle_default' => smart_sap_core()->get('player_toggle_hidden') ? 'hide' : 'show',
            'link_playlist_text' => smart_sap_core()->get('player_link_playlist_text'),
            'tracklist_toggle_open' => smart_sap_core()->get('player_tracklist_toggle_open'),
            'tracklist_toggle_close' => smart_sap_core()->get('player_tracklist_toggle_close'),
            'features' => smart_sap_core()->player_controls()
        );
    
        $args = wp_parse_args($args, $defaults);
    
        $args['variousartists'] = $playlist->various_artists == 1;
        $args['compilation'] = $playlist->compilation == 1;
    
        extract($args);
    
        $json = array('type' => 'audio', 
            'skin' => 'mejs-'.$skin, 
            'metadata' => $metadata,
            'playlist' => $playlist->id,
            'source' => $source,
            'volume' => $volume,
            'log' => 0,
            'features' => smart_sap_core()->arrange_player_controls($features)
        );
    
        foreach (array('autoplay', 'tracklist', 'tracknumbers', 'images', 'artists', 'download', 'variousartists', 'compilation', 'native_ipad', 'native_iphone', 'native_android') as $key) {
            $json[$key] = filter_var($$key, FILTER_VALIDATE_BOOLEAN);
        }
    
        $tracks = array();
        $noscript = array();
    
        $input = $playlist->get_tracks();
    
        foreach ($input as $track) {
            $url = ''; $link = '';
    
            if ($track->type == 'remote') {
                $url = $track->url;
                $link = '<a href="'.$url.'">'.$url.'</a>';
            } else if ($track->type == 'local') {
                $url = wp_get_attachment_url($track->post);
                $link = wp_get_attachment_link($track->post);
            }
    
            if ($url == '' || $url === false) {
                continue;
            }
    
            $noscript[] = '<li>'.$link.'</li>';
    
            $track_title = trim($track->title);
    
            if ($track_title == '') {
                $track_title = pathinfo($url, PATHINFO_FILENAME);
            }
    
            $T = array(
                'src' => $url,
                'track' => $track->id,
                'type' => 'audio',
                'title' => $track_title,
                'download' => $download,
                'tracks' => $tracknumbers,
                'va' => $variousartists,
                'plays' => 0,
                'caption' => '',
                'meta' => array(
                    'album' => $track->album,
                    'artist' => $track->artist,
                    'year' => $track->year,
                    'length_formatted' => $track->length
                )
            );
    
            if ($trackstats) {
                $stats = $track->stats();
    
                $T['played'] = array(
                    'total' => $stats['played_total'].' '._n("time", "times", $stats['played_total'], "smart-audio-playlists"),
                    'month' => $stats['played_month'].' '._n("time", "times", $stats['played_month'], "smart-audio-playlists"),
                    'week' => $stats['played_week'].' '._n("time", "times", $stats['played_week'], "smart-audio-playlists"),
                    'today' => $stats['played_day'].' '._n("time", "times", $stats['played_day'], "smart-audio-playlists")
                );
            }
    
            if ($images) {
                $thumb = $track->thumb_id();
    
                if ($thumb > 0) {
                    list($src, $width, $height) = wp_get_attachment_image_src($thumb, 'full');
                    $T['image'] = compact('src', 'width', 'height');
    
                    list($src, $width, $height) = wp_get_attachment_image_src($thumb, $thumbnail);
                    $T['thumb'] = compact('src', 'width', 'height');
                } else {
                    if ($track_use_playlist_image) {
                        list($src, $width, $height) = wp_get_attachment_image_src($playlist->id, 'full');
                        $T['image'] = compact('src', 'width', 'height');
    
                        list($src, $width, $height) = wp_get_attachment_image_src($playlist->id, $thumbnail);
                        $T['thumb'] = compact('src', 'width', 'height');
                    }
    
                    if (!isset($T['image']) || $T['image']['src'] == '' && $track_use_default_image) {
                        $src = wp_mime_type_icon('audio/mpeg');
                        $width = 48; $height = 64;
    
                        $T['image'] = compact('src', 'width', 'height');
                        $T['thumb'] = compact('src', 'width', 'height');
                    }
                }
    
                if (isset($T['image']) && $T['image']['src'] == '') {
                    unset($T['image']);
                    unset($T['thumb']);
                }
            }
    
            $tracks[] = $T;
        }
    
        $json['tracks'] = apply_filters('sap-playlist-player-tracks', $tracks, $playlist);
    
        $hide_tracklist = count($json['tracks']) == 1 && $tracklist_autohide;
    
        $classes = array('sap-playlist-player', 'sap-playlist-'.$playlist->id, 'sap-instance-'.$instance, $style, $playlist_class);
        $classes = apply_filters('sap-playlist-player-css', $classes, $playlist);
        $classes = array_filter($classes);
    
        if ($hide_tracklist) {
            $tracklist_toggle = false;
            $classes[] = 'sap-hide-tracklist';
            $json['features'] = array_diff($json['features'], array('prevtrack', 'nexttrack'));
        }
    
        $styles = array();
        if ($max_width != '') {
            $styles[] = 'max-width: '.$max_width.';';
            $styles[] = 'width: 100%;';
        }
    
        $track_styles = $toggle_open = $toggle_close = '';
        if ($tracklist_toggle) {
            if ($tracklist_toggle_default == 'hide') {
                $track_styles = ' style="display: none;"';
                $toggle_close = ' style="display: none;"';
            } else {
                $toggle_open = ' style="display: none;"';
            }
        }
    
        $json = apply_filters('sap-playlist-player-object', $json, $playlist);
    
        $render = '<div class="'.join(' ', $classes).'" style="'.join('', $styles).'">';
            $render.= '<script type="application/json">'.json_encode($json).'</script>';
            $render.= '<noscript><ol>'.join('', $noscript).'</ol></noscript>';
            $render.= '<div class="sap-playlist-header">';
                if ($metadata) {
                    $render.= '<div class="sap-playlist-current-item"></div>';
                }
            $render.= '</div>';
    
            if ($tracklist_toggle) {
                $render.= '<div class="sap-playlist-ctrl sap-ctrl-open"'.$toggle_open.'><a class="sap-tracklist-open" href="#">'.$tracklist_toggle_open.'</a></div>';
            }
    
            $render.= '<div class="sap-playlist-tracks"'.$track_styles.'></div>';
    
            if ($tracklist_toggle && !$tracklist_toggle_nohide) {
                $render.= '<div class="sap-playlist-ctrl sap-ctrl-close"'.$toggle_close.'><a class="sap-tracklist-close" href="#">'.$tracklist_toggle_close.'</a></div>';
            }
    
            if ($link_playlist) {
                $render.= '<div class="sap-playlist-ctrl sap-ctrl-link"><a href="'.get_permalink($playlist->id).'">'.$link_playlist_text.'</a></div>';
            }
    
        $render.= '</div>';
    
        do_action('sap_playlist_scripts', $skin);
    
        if ($echo) {
            echo $render;
        } else {
            echo 'You need to login';
        }
    }
    
    ?>

    Like this, it doesn’t work.
    I can see the player without being logged in with my SMP account.

    If i change echo $render; to echo ‘You need to login’; i’ve the message “You need to login” even if i’m logged with my SMP account.

    I think i’ve to change a little thing to make it worked !

    Thanks for your help.

    February 17, 2015 at 3:16 pm #1040
    Mogwai
    Participant

    Hi there !

    I’ve found a solution but need a few tweaks to work properly.

    At the moment, this page is blocked to non logged-in user.

    I’ve got this type of code

    <?php if(is_user_logged_in()):?>
    ....
    <?php else:
    wp_die('you must be registered');
    endif; ?>

    If i log in with an account, i can see the page.

    But i want that the logged user is part of a membership protection ID !

    Like access for Gold member and not Siver one.
    Do i need to specify something on this line <?php if(is_user_logged_in()):?> ?
    Maybe specify somehow a Membership ID ?

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy