Help Desk

PHP snippets for Events Calendar create high CPU usage

  • Posts: 4 Topics: 3
    | Permalink

    PHP snippets seem to call to a database for Events Calendar and create extremely high usage to the point the server shuts down the site. They are:

    /*
    * EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR
    * See the codex to learn more about WP text domains:
    * http://codex.wordpress.org/Translating_WordPress#Localization_Technology
    * Example Tribe domains: ‘tribe-events-calendar’, ‘tribe-events-calendar-pro’…
    */
    function tribe_custom_theme_text ( $translation, $text, $domain ) {
    // Put your custom text here in a key => value pair
    // Example: ‘Text you want to change’ => ‘This is what it will be changed to’
    // The text you want to change is the key, and it is case-sensitive
    // The text you want to change it to is the value
    // You can freely add or remove key => values, but make sure to separate them with a comma
    // This example changes the label “Venue” to “Location”, and “Related Events” to “Similar Events”
    $custom_text = array(
    ‘Venue’ => ‘Location’,
    ‘Related %s’ => ‘More %s’,
    );
    // If this text domain starts with “tribe-“, “the-events-“, or “event-” and we have replacement text
    if( (strpos($domain, ‘tribe-‘) === 0 || strpos($domain, ‘the-events-‘) === 0 || strpos($domain, ‘event-‘) === 0) && array_key_exists($translation, $custom_text) ) {
    $translation = $custom_text[$translation];
    }
    return $translation;
    }
    add_filter(‘gettext’, ‘tribe_custom_theme_text’, 20, 3);

    AND

    if ( function_exists( ‘tribe_get_events’ ) ) {
    /**
    * Open event website links in new tab.
    *
    * @since Nov 9 2015
    */
    function tribe_support_1023056() {
    if ( ! wp_script_is( ‘enqueued’, ‘jquery’ ) )
    wp_enqueue_script( ‘jquery’ );
    ?>
    <script type=”text/javascript”>
    jQuery( ‘.tribe-events-event-url, .url’ ).on( ‘click’, ‘a’, function(e) {
    e.preventDefault()

    var in_tab = window.open( e.currentTarget.href, ‘_blank’ );

    if ( in_tab )
    in_tab.focus()
    else
    alert( ‘Please allow popups for this site.’ )
    });
    </script>
    <?php
    }
    add_action( ‘wp_footer’, ‘tribe_support_1023056’ );
    }

    Why is this??

    Posts: 6091 Topics: 2
    | Permalink

    Hello Paul,

    Thanks for getting in touch with us!

    I’m not quite sure why those snippets would be heavy on CPU usage.

    I can offer you some alternatives which will give you the same result.

    Instead of the first snippet you could give the ‘Say What’ plugin a try. (I see you already have that.) It does exactly what that snippet with a nice user interface. Once the plugin is activated go to Tools > Text changes and you can start changing your strings. Note, that the entries need to match exactly the source strings. You can usually find the source strings and the context in the .po translation files. Text domains are ‘the-events-calendar’ and ‘events-calendar-pro’.

     

    Open event website links in new tab

    This should be a bit more simple, this will open a website url from a single event page in a new window / tab.

    add_filter( 'tribe_get_event_website_link', 'open_website_in_new_tab');
    function open_website_in_new_tab( $content ) {
    return str_replace( 'target="_self"', 'target="_blank"', $content );
    }

    If you wanted to achieve something else, let me know.

    Cheers,
    Andras

    Posts: 7
    | Permalink

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

The topic ‘PHP snippets for Events Calendar create high CPU usage’ is closed to new replies.