New Lines in iCal Feed Descriptions

WordPress Event Management, Calendars & Registration Forums General Question New Lines in iCal Feed Descriptions

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 5 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #34542

    I was hoping to use the eventorganiser_ical_description filter to add a bunch of content to event descriptions in the calendar feed. Is there a way to add line breaks when using this filter without having to modify ical.php?

    I noticed that eventorganiser_escape_ical_text() is removing my \n‘s. But there is a note in the code that says:

    An intentional formatted text line break MUST only be included in a “TEXT” property value by representing the line break with the character sequence of BACKSLASH (US-ASCII decimal 92), followed by a LATIN SMALL LETTER N (US-ASCII decimal 110) or a LATIN CAPITAL LETTER N (US-ASCII decimal 78), that is “\n” or “\N”.

    Unfortunately, that ^ doesn’t make sense to me… Does it mean that somehow I should be able to use \n‘s? How exactly is that done?

    Thanks!

    Dan Brubaker
    #34557

    eventorganiser_escape_ical_text() doesn’t remove the \n is just escapes the backslash (otherwise it’ll appear as a new line in the feed itself – which you don’t want).

    To add new lines:

    add_filter('eventorganiser_ical_description', function(){ 
        return 'Line one\n Line two';
    });.
    

    Incidentally if you find you need to modify ical.php, copy it to your theme first, so that it’ll survive plug-in updates. The ical.php template is like all the other templates in the plug-in – overridable by the theme.

    Stephen Harris
    #34629

    Well, that is the behavior that I expected, but something still is not working right…is there a bug? I don’t know what I’m missing here.

    This…

    add_filter('eventorganiser_ical_description', function(){ 
        return 'Line one\n Line two';
    });
    

    Outputs this in Apple Calendar’s event descriptions…

    Line one\n Line two
    

    Not this…

    Line one
    Line two
    

    It only works when I comment out $description = eventorganiser_escape_ical_text( $description ); on line 129 in ical.php.

    Dan Brubaker
    #34818

    Sorry, try

    add_filter('eventorganiser_ical_description', function(){ 
        return "Line one" . PHP_EOL .  "Line two";
    });
    

    or using double quotes

    add_filter('eventorganiser_ical_description', function(){ 
        return "Line one \n Line two";
    });
    
    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.