WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] 5.1.1 breaks conditional placeholders (26 posts)

  1. webaware
    Member
    Posted 2 years ago #

    The new regex for conditional placeholder removals in EM_Event::output breaks conditional placeholders such as {has_location}. Reverting to the old regex (or partially reverting) fixes it.

    @1036 classes/em-event.php:
    - preg_match_all('/\{([a-zA-Z0-9_]+)\}(.+)\{\/\1\}/s', $event_string, $conditionals);
    + preg_match_all('/\{([a-zA-Z0-9_]+)\}([^{]+)\{\/\1\}/s', $event_string, $conditionals);

    http://wordpress.org/extend/plugins/events-manager/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    thx, will fix, must be because it's not catching new lines (trying to make this consider nested placeholders).

  3. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    actually, I was wrong, it does thanks to the /s, this works for me. What's your format breaking this?

  4. webaware
    Member
    Posted 2 years ago #

    G'day Marcus, I'm offline tonight but can tell you that the format had {has_location} on a line by itself, then some html, then the closing tag. I'll post the while thing tomorrow morning my time.

  5. webaware
    Member
    Posted 2 years ago #

    G'day Marcus, here's the whole Single Event Page format. As you can see, there's a couple of custom placeholders and conditionals, but I turned off my hooks and I still get the problem with the new regex. It seems to be the nesting thing that's doing it.

    <h2>#_NAME</h2>
    
    <aside>
    {has_location}
    <div style="float:right; margin:0px 0px 15px 15px;">#_MAP</div>
    {/has_location}
    <div class="em-mmm-links">#_MMMLINKS</div>
    </aside>
    
    <p>
    	<strong>Date/Time</strong><br/>
    	Date(s) - #j #M #Y #@_{ \u\n\t\i\l j M Y}<br />
    	{has_time}<i>#_12HSTARTTIME - #_12HENDTIME</i>{/has_time}
    	{all_day}all day event{/all_day}
    </p>
    
    {has_location}
    <p>
    	<strong>Location</strong><br/>
    	#_LOCATIONLINK
    </p>
    {/has_location}
    
    {has_att_website}
    <p>
    	<strong>Website</strong><br/>
    	<a href="http://#_ATT{Website}" target="_blank">#_ATT{Website}</a>
    </p>
    {/has_att_website}
    
    {has_att_organisation}
    <p>
    	<strong>Organiser</strong><br/>
    	#_ATT{Name of Organisation}
    </p>
    {/has_att_organisation}
    
    {has_att_rsvp_dates}
    <p>
    	<strong>RSVP dates</strong><br/>
    	#_ATT{RSVP dates}
    </p>
    {/has_att_rsvp_dates}
    
    {has_att_cost}
    <p>
    	<strong>Cost</strong><br/>
    	#_ATT{Cost}
    </p>
    {/has_att_cost}
    
    {has_att_org_contact}
    <p>
    	<strong>Contact Details</strong><br/>
    	#_ATT{Event Organiser Contact Details}
    </p>
    {/has_att_org_contact}
    
    <p><strong>Event Region(s)</strong>
    {nl2br}
    #_ATT{Event Region}
    {/nl2br}
    </p>
    
    <p>	<strong>Category(ies)</strong>	#_CATEGORIES </p>
    
    <br style="clear:both" />
    #_NOTES
    {has_bookings}
    <h3>Bookings</h3>
    #_BOOKINGFORM
    {/has_bookings}
  6. rontarson
    Member
    Posted 2 years ago #

    As mentioned in another post, I too am having conditional placeholder issues with formats. Mine seems to be centered around the {has_location} holder.

    Also, on 5.1.2 my custom formats only seem to work if I copy and paste into the settings page windows. The hooks no longer function - function my_em_custom_formats( $array ){

  7. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    I'm getting the same issue, will play around with the regex to see if there's a better way... otherwise, I'm ok with reverting it back.

    @rontarson, can you send me a mail via the contact page on the plugin site - http://wp-events-plugin.com/contact-us/

  8. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    aha! it's a question of one ? in the regex.... otherwise, it will break if you include more than one of the same set of placeholders.

    so now it's /\{([a-zA-Z0-9_]+)\}(.+?)\{\/\1\}/s

    any chance one of you know how to use (?R) in regex to get recursions working?

  9. webaware
    Member
    Posted 2 years ago #

    G'day Marcus, 5.1.3 looks good.

    cheers,
    Ross

  10. webaware
    Member
    Posted 2 years ago #

    And no, I've never used recursion (and I am once again reminded of the old "I know, I'll use regular expressions!" joke :)

  11. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    i gave up on using regex for recursions (at least for now) and left a for loop with an option for how many loops to go through. 1 loop (default) = 1 recursion.

  12. webaware
    Member
    Posted 2 years ago #

    Yes, I saw that in the code. If I need some distraction from other code, I might have a play with that regex and see what I can come up with. But right now, I'm fighting with some Classic ASP that needs to be tarted up with a little jQuery :)

  13. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    ASP... glad those days are behind me ;)

  14. clivewalker
    Member
    Posted 2 years ago #

    @webaware: I'm trying to create a conditional placeholder like your {has_att_website} example. I'm following the EM Event conditional placeholder example which has been really useful but my code is getting more and more for something that I'm sure should be less. Would you mind sharing how you created the {has_att_website} conditional and posting some simplified code for this?

  15. webaware
    Member
    Posted 2 years ago #

    @clivewalker: To simplify explaining how to go about this, I just blogged it. Take a look and let me know if it doesn't give enough detail.

  16. clivewalker
    Member
    Posted 2 years ago #

    @webaware: Many thanks, didn't expect a blog post! that's a nice explanation. I'm adding this to a single location page so I think I will need to change $EM_EVENT to $EM_Location as far as I can see. Something like this?

    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
        if (is_object($EM_Location)) {
    
            switch ($condition) {
    
                // replace LF with HTML line breaks
                case 'nl2br':
                    $replacement = nl2br(preg_replace('/\{\/?nl2br\}/', '', $match));
                    break;
    
                // #_LATT{Website}
                case 'has_Latt_website':
                    if (is_array($EM_Location->location_attributes) && !empty($EM_Location->location_attributes['Website']))
                        $replacement = preg_replace('/\{\/?has_Latt_website\}/', '', $match);
                    else
                        $replacement = '';
                    break;
    
            }
    
        }
    
        return $replacement;
    }
    
    add_filter('em_location_output_condition', 'filterLocationOutputCondition', 10, 4);
  17. webaware
    Member
    Posted 2 years ago #

    G'day clivewalker, not quite. You can't change the parameter of the filter, as the caller will always provide $EM_Event (changing its name won't change the fact that it's an EM_Event object!)

    However, you can ask the event if it has a location, and if it does, you can grab it:

    if ($EM_Event->location)
        $EM_Location = $EM_Event->location;

    [NB: bear in mind that you can have events with no location, e.g. a so-named "webinar"]

  18. clivewalker
    Member
    Posted 2 years ago #

    My first two lines should be like this, is that what you are saying?

    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Event){
        if (is_object($EM_Event))
  19. webaware
    Member
    Posted 2 years ago #

    OK, sorry, my bad. I've just knocked off work and now have a small glass next to me, so I can think straight. What you had should be good, I didn't notice that you were hooking em_location_output_condition which does indeed give you an EM_Location object.

    So, have you tried it?

  20. clivewalker
    Member
    Posted 2 years ago #

    Not quite getting it to work yet. My code (in theme functions.php file) is as follows. Have removed line break switch for the moment and changed to my field name. Nothing is removed and the {has_Latt_location_url} tag appears on my single location page.

    function filterLocationOutputCondition($replacement, $condition, $match, $EM_Location){
        if (is_object($EM_Location)) {
    
            switch ($condition) {
    
                // #_LATT{location_url}
                case 'has_Latt_location_url':
                    if (is_array($EM_Location->location_attributes) && !empty($EM_Location->location_attributes['location_url']))
                        $replacement = preg_replace('/\{\/?has_Latt_location_url\}/', '', $match);
                    else
                        $replacement = '';
                    break;
    
            }
         }
    
        return $replacement;
    }
    
    add_filter('em_location_output_condition', 'filterLocationOutputCondition', 10, 4);
  21. clivewalker
    Member
    Posted 2 years ago #

    I'm starting to think that my custom field in not in the $EM_Location object. It's a WordPress custom field and is displayed on the page if it exists but cannot be removed by conditional above. Is that likely?

  22. webaware
    Member
    Posted 2 years ago #

    G'day clivewalker, I've had a bit of a look but can't get your code working here. However, it's past my "brain functioning" time so will take a little look again tomorrow.

    One thing I can tell you is that location filter has the $condition and $match parameters transposed with respect to the event filter, i.e. your function should start with this:

    function filterLocationOutputCondition($replacement, $match, $condition, $EM_Location){

    Off to eat dinner and watch mindless telly with a nice cider in hand, will check in again tomorrow :)

  23. clivewalker
    Member
    Posted 2 years ago #

    Thanks for your help. Will try a couple more things here.

  24. webaware
    Member
    Posted 2 years ago #

    @clivewalker: it's a bug. Open a new forum topic for it.

    EM_Location::output() mixes it up between $location_string and $format, but finally outputs $location_string. The problem is, your filter is called on $format, and your changes are never output.

    As a hack, to check what was happening, I added this line above line 544, and everything worked:

    $location_string = $format;

    So open a new forum topic and post the above information with your filter code, so that Marcus knows where to look for the bug.

    cheers,
    Ross

  25. clivewalker
    Member
    Posted 2 years ago #

  26. webaware
    Member
    Posted 2 years ago #

    In the EM_Location class,

    /wp-content/plugins/events-manager/classes/em-location.php

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic