Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By tbase

Thread: Restrictive content shortcodes

  1. #1
    Expired Customer gonesmith's Avatar
    Join Date
    Jun 2012
    Posts
    764
    Thanks
    50
    Thanked 202 Times in 137 Posts

    Restrictive content shortcodes

    I've been playing around with shortcodes recently and have a few that I thought Vantage users might be able to use. These shortcodes allow you to display content based on whether a user is logged in, has a post, or has a listing. For example;

    [member_only]Only logged in members can see this content.[/member_only]

    [contributor_only]Only members who have contributed an article/post can see this content.[/contributor_only]

    [listing_owner_only]Only members who own a listing can see this content.[/listing_owner_only]

    Here is the code;
    Code:
    /*---------------- Member Only Content ------------------*/
    
    function member_only( $atts, $content = null ) {
    
    	if ( is_user_logged_in() ) {
    		return '<div class="member-only">' .$content. '</div>' ;
    	}
    
    }
    
    add_shortcode('member_only', 'member_only');
    
    /*---------------- Contributor Only Content ------------------*/
    
    function contributor_only( $atts, $content = null ) {
    
    	$user_ID = get_current_user_id();
    	$articles = count_user_posts( $user_ID );
    
    	if ( is_user_logged_in() && $articles > 0 ) {
    		return '<div class="contributor-only">' .$content. '</div>' ;
    	}
    
    }
    
    add_shortcode('contributor_only', 'contributor_only');
    
    /*---------------- Listing Owner Only Content ------------------*/
    
    function tmm_count_user_listing( $user_id ) {
    	global $wpdb;
    
    	return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = %d AND post_type = %s", $user_id, VA_LISTING_PTYPE ) );
    }
    
    function listing_owner_only( $atts, $content = null ) {
    
    	$user_ID = get_current_user_id();
    	$listings = tmm_count_user_listing($user_ID);
    
    	if ( is_user_logged_in() && $listings > 0 ) {
    		return '<div class="lister-only">' .$content. '</div>' ;
    	}
    
    }
    
    add_shortcode('listing_owner_only', 'listing_owner_only');
    There are two ways to implement this;
    1. Put the above code in your child theme's functions.php, or
    2. Put include 'child-shortcodes.php'; in your child theme's functions.php, then create a new file called "child-shortcodes.php" and put that in your child theme's folder.

    I have only tested this briefly and everything seems to work but if anyone can find a problem with it please let me know.

  2. The Following User Says Thank You to gonesmith For This Useful Post:

    akemx (March 30th, 2013)

  3. #2
    Veteran tbase's Avatar
    Join Date
    Feb 2010
    Location
    Idaho
    Posts
    2,018
    Thanks
    246
    Thanked 67 Times in 64 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!
    akemx likes this.
    [CENTER]


    TreasureValleyBusiness.com

    [/CENTER]

  4. #3
    Expired Customer gonesmith's Avatar
    Join Date
    Jun 2012
    Posts
    764
    Thanks
    50
    Thanked 202 Times in 137 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  5. #4
    Expired Customer gonesmith's Avatar
    Join Date
    Jun 2012
    Posts
    764
    Thanks
    50
    Thanked 202 Times in 137 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  6. The Following User Says Thank You to gonesmith For This Useful Post:

    akemx (April 2nd, 2013)

  7. #5
    luxor's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    599
    Thanks
    8
    Thanked 141 Times in 74 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Shortcodes
    By localhint in forum Report Vantage Bugs (Legacy)
    Replies: 1
    Last Post: August 11th, 2012, 10:59 AM
  2. Column Shortcodes - Is there any???
    By liquidpixels in forum JobRoller General Discussion
    Replies: 1
    Last Post: November 6th, 2011, 07:45 AM
  3. Column Shortcodes - Is there any???
    By liquidpixels in forum Report JobRoller Bugs
    Replies: 1
    Last Post: November 6th, 2011, 07:45 AM
  4. Using shortcodes in excerpt
    By moabi in forum ClassiPress General Discussion
    Replies: 3
    Last Post: January 20th, 2011, 10:19 AM
  5. Using shortcodes in excerpt
    By moabi in forum Report ClassiPress Bugs
    Replies: 1
    Last Post: January 20th, 2011, 03:50 AM