• Resolved laiconsulting

    (@laiconsulting)


    I have a multisite setup, would like to change the Events URL slug from /events to something else programmatically, so subsite owners don’t need to bother with it.
    Is this doable?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi @laiconsulting,
    Thanks for reaching out,

    If I understand correctly you don’t want to have the site owners to change the slug but instead changing it automatically by code?

    The events slug is stored in the table wp_options (for each subsite wp_x_options) under the option name ‘tribe_events_calendar_options’ in a serialized array. Changing that manually would be highly discouraged unless you know exactly what you are doing.

    Now, there you could use the method set_option wraped in a function and hooked in your functions.php
    Something like this would work to keep the slug set to ‘mySlug’ everytime the site loads.

    add_filter(‘init’, ‘tribe_set_events_slug’);
    function tribe_set_events_slug (){
    Tribe__Settings_Manager::set_option( ‘eventsSlug’, ‘mySlug’ );
    }

    Let me know if this helps

    Best
    Santiago

    Thread Starter laiconsulting

    (@laiconsulting)

    @sjaure
    many thanks for the code snippet. That’s very helpful.
    May I ask one more question.

    How do I change the default google map api key without editing plugin code?
    I’d like subsites to inherit one key without users having to deal with setting. If there is a constant to define, that would be ideal.

    I have come up with the following code, but it doesn’t work somehow.

    add_filter( 'tribe_field_value', 'bv_populate_field_with_default_api_key' , 8, 2 );
    function bv_populate_field_with_default_api_key( $value_string, $field_name ) {                                                                                                                                 
    if ( ! isset( $field_name ) || 'google_maps_js_api_key' !== $field_name ) {
            return $value_string;
    }
    
    if ( ($value_string == "AIzaSyDNsicAsP6-VuGtAb1O9riI3oc_NOb7IOU" || empty( $value_string )) && function_exists('tribe_update_option') ) {
    
            remove_filter( 'tribe_field_value', array( $this, 'bv_populate_field_with_default_api_key' ), 8, 2 );
            $value_string = GOOG_MAP_KEY;
            tribe_update_option(  'google_maps_js_api_key', GOOG_MAP_KEY );
    
            add_filter( 'tribe_field_value', array( $this, 'bv_populate_field_with_default_api_key' ), 8, 2 );
    }

    Hey @laiconsulting ,

    I’m happy to hear it helped.
    The following snippet will set the default API key whenever a custom one is not set.

    add_filter(‘init’, ‘tribe_set_google_api_key’);
    function tribe_set_google_api_key(){
    Tribe__Events__Google__Maps_API_Key::$default_api_key = ‘asdasdasdasdasdasdasdasd’;
    }

    Let me know how it goes
    Best

    Thread Starter laiconsulting

    (@laiconsulting)

    Many thanks again for the help!

    Thread Starter laiconsulting

    (@laiconsulting)

    @sjaure
    I have a strange problem regarding to setting the default api key
    When I run Tribe__Events__Google__Maps_API_Key::$default_api_key, it displays the key I want to be used, however when I look in the DB directly, it is still the default TEC key. And what is used by the map widget is still the TEC api key, not mine.

    Is that a way to remedy it?
    Or filter it to my key somehow?

    Thread Starter laiconsulting

    (@laiconsulting)

    Nevermind.
    Based on your previous snippet, I added this line.
    if( Tribe__Settings_Manager::get_option("google_maps_js_api_key") != GOOG_MAP_KEY ) Tribe__Settings_Manager::set_option("google_maps_js_api_key",GOOG_MAP_KEY);
    It does the job

    Hi @laiconsulting,

    I’m happy to hear you sorted it out.
    Thanks for sharing the solution.

    Cheers

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change Events URL Slug programmatically’ is closed to new replies.