Renaming Views not behaving :(

Home Forums Calendar Products Events Calendar PRO Renaming Views not behaving :(

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #971212
    Simon
    Participant

    I’m trying to rename some views, in line with this article in the Knowledgebase: https://theeventscalendar.com/knowledgebase/renaming-views/

    The only difference is that I want to ‘Photos’ renamed to ‘All Events’, rather than ‘List’ to ‘All Events’ like the KB article.

    So what I’ve done is replace ‘List’ with ‘Photos’ and ‘list’ with ‘photos’ where they appear respectively. It seems to have worked in the little drop-down menu on the /events pages, but not in the backend or the slug. Renaming Month to Calendar has worked though…

    Suggestions?

    Thanks for your time 🙂

    #971375
    Geoff
    Member

    Hi Simon, and welcome to the forums! I hope you’ve been enjoying the PRO plugin so far. 🙂

    Good question. The article you mention there is great, but it will only change names on specific calendar views. Try using this article instead to rename “Events” to something else throughout the entire plugin (front and back end).

    The other article will still be good for renaming specific views, but this article will help change the term Events globally.

    You can also update the calendar slug to anything you’d like under Events > Settings and match the slug to your new term from there. 🙂

    Does this help? Please let me know.

    Cheers!
    Geoff

    #972055
    Simon
    Participant

    Hi Geoff, thanks for the quick reply.

    I think you’re misunderstanding what I’m trying to do – sorry! Let me try again 🙂

    I’m trying to do exactly what’s discribed in this article:
    https://theeventscalendar.com/knowledgebase/renaming-views/

    The only difference is that one of the views I want to rename is the ‘photos’ view, instead of the ‘list’ view used in the article.

    I’ve added the following code into my functions.php file:

    
    // ===========================
    // EVENTS CALENDAR STUFF
    // ===========================
    
    //PART ONE: adapt the names of views listed within the Tribe Events Bar
    add_filter( 'tribe-events-bar-views', 'rename_tribe_views_in_selector' );
     
    function rename_tribe_views_in_selector( $views ) {
        // This lists the original view names you wish to change along
        // with the substitutes to wish to use in their place
        $to_change = array(
            'Photo'  => 'All Events',
            'Month' => 'Calendar',
        );
     
        // Look through the list of active views and modify names accordingly
        foreach ( $views as &$view )
            if ( isset( $to_change[ $view['anchor'] ] ) )
                $view['anchor'] = $to_change[ $view['anchor'] ];
     
        // Return our revised list
        return $views;
    }
    
    // PART TWO: Slug rewrite rules
    add_filter( 'tribe_events_rewrite_rules', 'rename_event_view_slugs', 10, 2 );
    
    function rename_event_view_slugs( $rules, $new_rules = null ) {
    	if ( null === $new_rules ) return $rules;
    
    	// Original event view slugs and what we want to change each to
    	$to_change = array(
    		'photo'  => 'all-events',
    		'month' => 'calendar'
    	);
    
    	// Scan for rules relating to the views in question and update accordingly
    	foreach ( $new_rules as $added_rule => $query_string ) {
    		foreach ( $to_change as $look_for => $change_to ) {
    			// Skip if we don't have a match
    			if ( false === strpos( $added_rule, "/$look_for" ) ) continue;
    
    			// Form the revised rule
    			$revised_rule = array(
    				str_replace( "/$look_for", "/$change_to", $added_rule ) => $query_string
    			);
    
    			// Remove the old rule and insert the new one
    			unset( $rules[$added_rule] );
    			$rules = $revised_rule + $rules;
    		}
    	}
    
    	return $rules;
    }
    
    // PART THREE: Whenever The Events Calendar displays a link to month/list view, we need to update it in respect of our new slug
    add_filter( 'tribe_events_getLink', 'modify_month_list_link_urls', 10, 2 );
    
    function modify_month_list_link_urls( $url, $type ) {
    	if ( 'month' === $type ) return str_replace( 'month', 'calendar', $url );
    	if ( 'photo' === $type ) return str_replace( 'photo', 'all-events', $url );
    	return $url;
    }
    

    Now, what’s happened is:
    The ‘Month’ => ‘Calendar’ stuff has worked perfectly – it’s renamed in the back end, the events bar, and slug.
    The ‘Photo’ => ‘All Events’ stuff has not worked, it’s still called photo in the back end, or the ‘event bar’ at the top of events pages and typing heading to /events/photo shows the photo view, so it hasn’t changed the slug. It’s like what I’ve entered hasn’t touched it :/.

    Thanks again for taking a look!

    #972250
    Geoff
    Member

    Hey Simon,

    Oh man, my bad–I definitely misunderstood and appreciate the clarification here. That makes much more sense. 🙂

    Turns out that the snippet is a little off and needs to be updated–which we just did. You can use this instead:

    https://gist.github.com/theeventscalendar/800ce8f9fafae49f2182

    Let me know if that doesn’t do the trick for some reason and I’d be happy to take another look. 🙂

    Cheers!
    Geoff

     

    #972469
    Simon
    Participant

    Hey!

    That’s partially fixed it :). So it was just a case of adding that priority number to that first part?

    *

    The issue now is that /events/all-events leads us to a 404, despite following the KB article (I’ve opened up the ‘Permalinks’ page pretty regularly to make sure that’s not the issue, as mentioned in the KB article).

    So ‘All Events’ now displays in the dropdown at the top of Events pages, but clicking it leads to a 404 :(.

    *

    Keen to hear your feedback :).

    #972640
    Geoff
    Member

    Hey Simon!

    Yeah, the priority was the missing piece. The KB article was looking specifically at non-PRO views which wouldn’t necessarily need that. 🙂

    The slug redirects were apparently also written for non-PRO views. I don’t have a solution right off the bat, but am looking into it and will give you an update.

    Cheers!
    Geoff

    #972908
    Geoff
    Member

    Hi Simon,

    Just wanted to poke in and let you know I’m still looking at this and will report back when I have more to share — thanks for waiting!

    Geoff

    #972974
    Geoff
    Member

    Alright, I have something for you. 🙂

    You can still use the first snippet I gave you yesterday (with the updated priority), but get rid of the last snippet for rewrites and use these two instead (changing the values as you see fit):

    https://gist.github.com/barryhughes/16f4ad68201593583ba0

    https://gist.github.com/barryhughes/2be50bc69c29bd5747dc#file-change-event-slugs-in-links-php

    I gave the three snippets a whirl (after flushing permalinks) and everything seemed to be renamed and redirect as expected. Let me know if this helps!

    Geoff

    #973086
    Simon
    Participant

    Geoff! You’re a gentleman and a scholar.

    Worked flawlessly ;). Thanks heaps for your time and efforts on this!

    #973158
    Geoff
    Member

    Awesome! I’m so stoked this worked out — thanks so much for bearing with me and thanks for bringing this up. I know others will definitely find this useful for PRO views. 🙂

    Cheers,
    Geoff

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Renaming Views not behaving :(’ is closed to new replies.