Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  •  potion5
    Participant

    A slightly different approach: register a second, alternate menu for each menu theme location. Then show the alternate menu conditionally on logged-in status. Put it in a plugin and it will work for any theme.

    COPY CODE
    
    <?php
    /*
    Plugin Name: Potion Conditional Menus
    Description: Show alternate menus for logged in users. This plugin will create duplicate theme menu locations; for example, "Primary Menu" will get a counterpart called "Primary Menu for logged in users".
    Author: Denis Collis - Potion Design & Digital
    Version: 1.0
    Author URI: http://www.potion.co.za
    */
    
    /* Register Alternate Menus */
    
    add_action( 'init', 'register_alt_menus', 9999 );
    
    function register_alt_menus() {
      $existing_menus = get_registered_nav_menus();
      foreach ($existing_menus as $location => $description){
    	register_nav_menu( $location . "_logged_in", $description . " for logged in users"); 
      }
    }
    
     /* Show alternate menus if user is logged in */
    
    add_filter('wp_nav_menu_args', 'show_alt_menu');
    
    function show_alt_menu($args){
    	if ( is_user_logged_in() ) {
    		$args['theme_location'] = $args['theme_location'] . '_logged_in';		
    	}	
    	return $args;
    }
    
    in reply to: Membership Levels add extra fields #23825
     potion5
    Participant

    Very nice, thank you. I used a custom post type to allow ordinary admins (not developers) to easily change membership features from the admin back-end. I’ve included the code below. However, I do not think that this should be solved using custom post types. Is there a way to hook into the Theme Options -> Membership admin panel and add an editable list of features there instead?

    COPY CODE
    <?php
    /**
     * @package Membership_Features
     * @version 0.1
     */
    /*
    Plugin Name: Membership Features
    Description: Implements a custom post type, "Feature", which replaces the default features used in the membership pricing table of  the <a href="http://themeforest.net/item/kleo-next-level-premium-wordpress-theme/6776630">Kleo Theme</a>. To use, first create new features as required, then enable or disable them in the Theme Options -> Memberships.
    Author: Potion
    Version: 0.1
    */
    
    /**
     * Register custom post type: membership_feature 
     */
    add_action( 'init', 'create_feature_post_type' );
    function create_feature_post_type() {
    	register_post_type( 'membership_feature',
    		array(
    			'labels' => array(
    				'name'               => _x( 'Features' ),
    				'singular_name'      => _x( 'Feature' ),
    				'add_new'            => _x( 'Add New' ),
    				'add_new_item'       => __( 'Add New Feature' ),
    				'edit_item'          => __( 'Edit Feature' ),
    				'new_item'           => __( 'New Feature' ),
    				'all_items'          => __( 'All Features' ),
    				'view_item'          => __( 'View Feature' ),
    				'search_items'       => __( 'Search Features' ),
    				'not_found'          => __( 'No features found' ),
    				'not_found_in_trash' => __( 'No features found in Trash' ),
    				'parent_item_colon'  => '',
    				'menu_name'          => __( 'Features' ),
    			),
    			'public'             => true,
    			'publicly_queryable' => true,
    			'show_ui'            => true,
    			'show_in_menu'       => true,
    			'query_var'          => true,
    			'rewrite'            => array( 'slug' => 'feature' ),
    			'capability_type'    => 'post',
    			'has_archive'        => true,
    			'hierarchical'       => false,
    			'menu_position'      => 120,
    			'supports'           => array( 'title')
    		)
    	);
    }
    
    /**
     * Use membership_feature posts to populate features for Kleo Theme Membership Level Pricing Table
     */
    add_filter('kleo_pmpro_level_restrictions', 'kleo_my_levels_checkmarks');
    function kleo_my_levels_checkmarks($settings) {
    
    	$args = array(
    		'post_type' => 'membership_feature',
    		'posts_per_page' => -1);
    
    	query_posts( $args );
    
    	if (have_posts) {
    	
    		$settings = array ();
    		
    		while (have_posts()) : the_post();
    
    			array_push( $settings, array(
    					'title' => __('Restrict ' . get_the_title(), 'kleo_framework'),
    					'front' => __( get_the_title(), 'kleo_framework'),
    					'name' => basename(get_permalink($post->ID))
    				)
    			);
    			
    		endwhile;
    	}
    
    	wp_reset_query();
    	
        return $settings;
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

Log in with your credentials

Forgot your details?