• Hi @netweblogic,
    First of all, do you already have a dedicated repository where I can easily report this type of code change? Have you ever thought about github? I tried to check your plugin on svn, but it doesn’t seem possible to contribute directly…

    Patch Description:
    Currently the slugs for sub-components in BuddyPress profiles are hardcoded within the Events Manager plugin, this patch ensure that they can be easily modified or translated by a developer.

    Changes:

    events-manager\buddypress\bp-em-templatetags.php (additional paramater in the “em_bp_get_slug” function)

    /**
     * Echo the Events Manager BuddyPresss component's slug
     *
     * @since 5.0
     */
    function em_bp_slug( $nav_item = '' ) {
    	echo em_bp_get_slug( $nav_item );
    }
    /**
     * Return the Events Manager BuddyPresss component's slug
     *
     * @since 5.0
     * @uses apply_filters() Filter 'em_bp_get_slug' to change the output
     * @param  str $nav_item Default BuddyPress compontent's slug
     * @return str $slug The slug from $bp->events->slug, if it exists
     */
    function em_bp_get_slug( $nav_item = '' ) {
    
    	$slug = $nav_item;
    
    	if ( $nav_item === '' ) {
    		global $bp;
    		// Avoid PHP warnings, in case the value is not set for some reason
    		$slug = ! empty( $bp->events->slug ) ? $bp->events->slug : BP_EM_SLUG;
    	}
    
    	return apply_filters( 'em_bp_get_slug', $slug, $nav_item );
    }
    

    events-manager\buddypress\bp-em-core.php#L111 (example of replaced hardcoded strings)

    if( $can_manage_events ){
    	$sub_nav[] = array(
    		'name' => __( 'My Events', 'events-manager'),
    		// 'slug' => 'my-events',
    		'slug' => em_bp_get_slug( 'my-events' ),
    		'parent_slug' => em_bp_get_slug(),
    		'parent_url' => $em_link,
    		'screen_function' => 'bp_em_my_events',
    		'position' => 30,
    		'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
    	);
    }
    
    if( $can_manage_locations && get_option('dbem_locations_enabled') ){
    	$sub_nav[] = array(
    		'name' => __( 'My Locations', 'events-manager'),
    		// 'slug' => 'my-locations',
    		'slug' => em_bp_get_slug( 'my-locations' ),
    		'parent_slug' => em_bp_get_slug(),
    		'parent_url' => $em_link,
    		'screen_function' => 'bp_em_my_locations',
    		'position' => 40,
    		'user_has_access' => bp_is_my_profile() // Only the logged in user can access this on his/her profile
    	);
    }
    // and so on...
    

    How to use:

    add_filter(
    	'em_bp_get_slug',
    	function ( $slug, $nav_item ) {
    		switch ( $nav_item ) {
    			case 'my-events':
    				return 'custom-name-1';
    			case 'my-locations':
    				return 'custom-name-2';
    			break;
    			default:
    				return $slug;
    		}
    	},
    	10,
    	2
    );
    
    • This topic was modified 5 years, 1 month ago by Raruto.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[PATCH] Custom BuddyPress navigation slugs’ is closed to new replies.