• Resolved kvenugopal

    (@kvenugopal)


    Hi,

    I have created a page for user registration on my site http://dealscarrier.com & would like to restrict access to the coupons displayed on my site only to registered users.
    The “Coupons” menu is a link(url) http://dealscarrier.com/coupon/, on my site , NOT a page.
    What should I do to to restrict access to this link, i.e any one clicking on this link should be logged-in as a registered user.
    You have mentioned shortcodes to restrict access only to pages.
    My site runs on the Starter theme of Happy Themes?
    The coupons are “special posts”, as far as I know.
    Regards-Venu

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Rustaurius

    (@rustaurius)

    Hi Venu,

    It looks like the “Coupons” page is an archive page? The easiest way to restrict access to an entire set of custom post types would be to create a custom filter on “the_content” in your functions.php file, and then use the “do_shortcode” function to restrict access to the content. I think something like this might work:

    $content = do_shortcode("[restricted]" . $content . "[/restricted]");
    

    You would need some kind of conditional check based on the name of the custom post type.

    Thread Starter kvenugopal

    (@kvenugopal)

    Hey Rustarius,
    Thanks for the kind reply.
    The coupons page is a menu link & the coupons are custom posts, as far as my limited knowledge goes. Probably in WP, it is called an Archive page?
    Now, since I am not a programmer, I am not sure about editing the functions.php file.
    I don’t see a way to attach a notepad file, hence I have copied the code of “functions.php” as below. Kindly take a look & see if you can make any sense of it.

    <?php
    /**
    * starter functions and definitions.
    *
    * @link https://developer.wordpress.org/themes/basics/theme-functions/
    *
    * @package starter
    */

    if ( ! function_exists( ‘starter_setup’ ) ) :

    function starter_setup() {

    load_theme_textdomain( ‘starter’, get_template_directory() . ‘/languages’ );

    // Add default posts and comments RSS feed links to head.
    add_theme_support( ‘automatic-feed-links’ );

    /*
    * Let WordPress manage the document title.
    * By adding theme support, we declare that this theme does not use a
    * hard-coded <title> tag in the document head, and expect WordPress to
    * provide it for us.
    */
    add_theme_support( ‘title-tag’ );

    /*
    * Enable support for Post Thumbnails on posts and pages.
    *
    * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
    */
    add_theme_support( ‘post-thumbnails’ );

    // This theme uses wp_nav_menu() in one location.
    register_nav_menus( array(
    ‘primary’ => esc_html__( ‘Primary Menu’, ‘starter’ ),
    ‘footer’ => esc_html__( ‘Footer Menu’, ‘starter’ ),
    ) );

    /*
    * Switch default core markup for search form, comment form, and comments
    * to output valid HTML5.
    */
    add_theme_support( ‘html5’, array(
    ‘search-form’,
    ‘comment-form’,
    ‘comment-list’,
    ‘gallery’,
    ‘caption’,
    ) );

    // Set up the WordPress core custom background feature.
    add_theme_support( ‘custom-background’, apply_filters( ‘starter_custom_background_args’, array(
    ‘default-color’ => ‘ffffff’,
    ‘default-image’ => ”,
    ) ) );

    add_editor_style();
    }
    endif;
    add_action( ‘after_setup_theme’, ‘starter_setup’ );

    /**
    * Set the content width in pixels, based on the theme’s design and stylesheet.
    *
    * Priority 0 to make it available to lower priority callbacks.
    *
    * @global int $content_width
    */
    function starter_content_width() {
    $GLOBALS[‘content_width’] = apply_filters( ‘starter_content_width’, 760 );
    }
    add_action( ‘after_setup_theme’, ‘starter_content_width’, 0 );

    /**
    * Register widget area.
    *
    * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
    */
    function starter_sidebar_init() {

    register_sidebar( array(
    ‘name’ => esc_html__( ‘Sidebar’, ‘starter’ ),
    ‘id’ => ‘sidebar-1’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘starter’ ),
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h2 class=”widget-title”>’,
    ‘after_title’ => ‘</h2>’,
    ) );

    register_sidebar( array(
    ‘name’ => esc_html__( ‘Header Newsletter’, ‘starter’ ),
    ‘id’ => ‘header-newsletter’,
    ‘description’ => esc_html__( ‘Drag the “Newsletter” widget here.’, ‘starter’ ),
    ‘before_widget’ => ‘<div id=”%1$s” class=”header-promo %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3 class=”widget-title”>’,
    ‘after_title’ => ‘</h3>’,
    ) );

    register_sidebar( array(
    ‘name’ => esc_html__( ‘Footer Column 1’, ‘starter’ ),
    ‘id’ => ‘footer-1’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘starter’ ),
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget footer-widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3 class=”widget-title”>’,
    ‘after_title’ => ‘</h3>’,
    ) );
    register_sidebar( array(
    ‘name’ => esc_html__( ‘Footer Column 2’, ‘starter’ ),
    ‘id’ => ‘footer-2’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘starter’ ),
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget footer-widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3 class=”widget-title”>’,
    ‘after_title’ => ‘</h3>’,
    ) );
    register_sidebar( array(
    ‘name’ => esc_html__( ‘Footer Column 3’, ‘starter’ ),
    ‘id’ => ‘footer-3’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘starter’ ),
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget footer-widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3 class=”widget-title”>’,
    ‘after_title’ => ‘</h3>’,
    ) );
    register_sidebar( array(
    ‘name’ => esc_html__( ‘Footer Column 4’, ‘starter’ ),
    ‘id’ => ‘footer-4’,
    ‘description’ => esc_html__( ‘Add widgets here.’, ‘starter’ ),
    ‘before_widget’ => ‘<div id=”%1$s” class=”widget footer-widget %2$s”>’,
    ‘after_widget’ => ‘</div>’,
    ‘before_title’ => ‘<h3 class=”widget-title”>’,
    ‘after_title’ => ‘</h3>’,
    ) );
    }
    add_action( ‘widgets_init’, ‘starter_sidebar_init’ );

    /**
    * Implement the Custom Header feature.
    */
    require get_template_directory() . ‘/inc/custom-header.php’;

    /**
    * Custom template tags for this theme.
    */
    require get_template_directory() . ‘/inc/template-tags.php’;

    /**
    * Custom functions that act independently of the theme templates.
    */
    require get_template_directory() . ‘/inc/extras.php’;

    /**
    * Customizer additions.
    */

    require get_template_directory() . ‘/admin/customizer-library.php’;

    require get_template_directory() . ‘/admin/customizer-options.php’;

    require get_template_directory() . ‘/admin/styles.php’;

    require get_template_directory() . ‘/admin/mods.php’;

    require get_template_directory() . ‘/inc/customizer.php’;

    /**
    * Load Jetpack compatibility file.
    */
    require get_template_directory() . ‘/inc/jetpack.php’;

    /**
    * Load plugins.
    */
    require get_template_directory() . ‘/inc/plugins.php’;

    /**
    * Enqueues scripts and styles.
    */
    function starter_scripts() {

    // load jquery if it isn’t

    //wp_enqueue_script(‘jquery’);
    wp_enqueue_script(‘jquery’, get_stylesheet_directory_uri() . ‘/assets/js/jquery.js’, array(), ”, true );

    // Enqueues Javascripts
    wp_enqueue_script( ‘superfish’, get_stylesheet_directory_uri() . ‘/assets/js/superfish.js’, array(), ”, true );
    wp_enqueue_script( ‘slicknav’, get_stylesheet_directory_uri() . ‘/assets/js/jquery.slicknav.min.js’, array(), ”, true );
    wp_enqueue_script( ‘modernizr’, get_stylesheet_directory_uri() . ‘/assets/js/modernizr.min.js’,array(), ”, true );
    wp_enqueue_script( ‘html5’, get_template_directory_uri() . ‘/assets/js/html5.js’, array(), ”, true );
    wp_enqueue_script( ‘clipboard’, get_template_directory_uri() . ‘/assets/js/clipboard.min.js’, array(), ”, true );
    wp_enqueue_script( ‘modal’, get_template_directory_uri() . ‘/assets/js/jquery.modal.min.js’, array(), ”, true );
    wp_enqueue_script( ‘custom’, get_stylesheet_directory_uri() . ‘/assets/js/jquery.custom.js’, array(), ‘20170604’, true );

    // Enqueues CSS styles
    wp_enqueue_style( ‘starter-style’, get_stylesheet_uri(), array(), ‘20161209’ );
    wp_enqueue_style( ‘superfish-style’, get_template_directory_uri() . ‘/assets/css/superfish.css’ );
    wp_enqueue_style( ‘genericons-style’, get_template_directory_uri() . ‘/genericons/genericons.css’ );
    wp_enqueue_style( ‘modal-style’, get_template_directory_uri() . ‘/assets/css/jquery.modal.css’ );

    if ( get_theme_mod( ‘site-layout’, ‘choice-1’ ) == ‘choice-1’ ) {
    wp_enqueue_style( ‘responsive-style’, get_template_directory_uri() . ‘/responsive.css’, array(), ‘20161209’ );
    }

    if ( is_singular() && comments_open() && get_option( ‘thread_comments’ ) ) {
    wp_enqueue_script( ‘comment-reply’ );
    }
    }
    add_action( ‘wp_enqueue_scripts’, ‘starter_scripts’ );

    /**
    * Post Thumbnails.
    */
    if ( function_exists( ‘add_theme_support’ ) ) {
    add_theme_support( ‘post-thumbnails’ );
    set_post_thumbnail_size( 300, 300, true ); // default Post Thumbnail dimensions (cropped)
    add_image_size( ‘single_thumb’, 600, 360, true );
    }

    /**
    * Registers custom widgets.
    */
    function starter_widgets_init() {

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-popular.php’;
    register_widget( ‘starter_Popular_Widget’ );

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-recent.php’;
    register_widget( ‘starter_Recent_Widget’ );

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-random.php’;
    register_widget( ‘starter_Random_Widget’ );

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-views.php’;
    register_widget( ‘starter_Views_Widget’ );

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-social.php’;
    register_widget( ‘starter_Social_Widget’ );

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-ad.php’;
    register_widget( ‘starter_Ad_Widget’ );

    require trailingslashit( get_template_directory() ) . ‘inc/widgets/widget-newsletter.php’;
    register_widget( ‘starter_Newsletter_Widget’ );

    }
    add_action( ‘widgets_init’, ‘starter_widgets_init’ );

    /* Fix PHP warning */
    function _get($str){
    $val = !empty($_GET[$str]) ? $_GET[$str] : null;
    return $val;
    }

    Regards-Venu

    Plugin Author Rustaurius

    (@rustaurius)

    Hi Venu,

    We’re not able to customize people’s themes unfortunately, so if you’re not comfortable programming, you would need to look for a developer who can help you to customize your site.

    Thread Starter kvenugopal

    (@kvenugopal)

    Hi Rustaurius,
    Thanks. But for a small change, I can’t go look for a developer because he/she needs to understand the theme & plugin functionality etc. Since there are other plugin options like Restrict Content, Membership plugins etc available in the directory that could serve my purpose, I would rather NOT use Front-End Only Users plugin.
    Anyway thanks for sparing time for me.
    Regards-Venu

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Restrict Access to Special Posts’ is closed to new replies.