tags not being saved in cost field in single event

Home Forums Calendar Products Events Calendar PRO tags not being saved in cost field in single event

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1288666
    Brian
    Participant

    short version: How to make sure that html chars are saved in the cost field.

    Hi there,

    We use <br> tags in our cost field to display various costs in the cost field of single events. I use this snippet to display the <br> tags, but recently the <br> tags don’t appear to be saved on update. So, if they’re already in the database, they render, but on update they seem to be stripped.

    I’m guessing this won’t be helpful to just see the front end, but if so: http://massmoca.org/event/freshgrass-festival-2017/

    Thanks in advance for you help.

    #1289222
    Geoff B.
    Member

    Good evening Brian and welcome back!

    Thank you for reaching out to us.
    I would love to help you with this topic.

    You could apply the following snippet in the functions.php file of your theme (without the PHP tag at the top): https://gist.github.com/ggwicz/ec04f88224651a777c88#file-return-unfiltered-cost-php

    I would experiment with both snippets in place and with only that last one.

    Let me know how that goes.

    Best regards,
    Geoff B.

    #1290421
    Brian
    Participant

    Hi Geoff, thanks so much for the reply. I added the snippet you linked to, as well as the one I had in before, but no luck. I think because both those snippets relate to displaying the content that is stored in the cost field, but from what I can tell the tags are being stripped from the field on save. So when I try to save this:

    “$105 Advance 3-Day Festival Pass <br> $89 Advance 3-Day Student Pass <br> $46 Advance 3-Day Child 7-16 Pass Free Child 6 and under”

    The post saves and when it reloads it shows:

    $105 Advance 3-Day Festival Pass $89 Advance 3-Day Student Pass $46 Advance 3-Day Child 7-16 Pass Free Child 6 and under”

    I’m adding the cost info here:
    https://www.dropbox.com/s/tn38yhybkvz1jz6/Screen%20Shot%202017-05-29%20at%202.38.16%20PM.png?dl=0

    • This reply was modified 8 years, 11 months ago by Brian. Reason: formatting and added screenshot
    #1290638
    Geoff B.
    Member

    Good evening Brian,

    Thank you for writing back.

    I believe you might be 100% right.
    Let me ask the snippet authors and get back to you on this one.

    Hang in there!

    Geoff B.

     

    #1291134
    Geoff B.
    Member

    Good evening Brian,

    As promised, I followed up on this for you.

    The reason why the HTML tags are stripped upon submission to the database is because of they are used for calculations.

    With that in mind, I believe that you can still accomplish your goal with a more flexible solution: WordPress custom fields: http://www.wpbeginner.com/wp-tutorials/wordpress-custom-fields-101-tips-tricks-and-hacks/

    This way you will be able to display the multiple costs exactly to your liking.

    For that purpose, you will simply need to do a view customization of the single event view.
    You might want to read our Themer’s guide to get a sense of how that works.

    Let me know if that helps.

    Have a great day!

    Geoff B.

    #1291229
    Brian
    Participant

    Hi Geoff,

    Thanks so much for your reply. Is there any other way you can think of to solve this? It must be a change in the Events Calendar plugin, because we have around 1300 events already saved in our site that use tags in the cost field and handle the formatting on the frontend. Setting a up a custom field is definitely an option, but will take a lot of work to migrate.

    I’m not sure how the current cost could be used for calculations if you can still store any string, not just numbers, so I’m hoping there’s a way to store html tags with that as well. I might need to roll back to an earlier version and freeze if that’s not an option.

    #1291579
    Geoff B.
    Member

    Good evening Brian,

    I totally see your point.
    You are right, it looks like there might have been some code changes there.

    As such, I will reach out to the Dev team to see if they have suggestion or perhaps some hooks to help you out with this.

    If not, you are absolutely right. Downgrading is certainly worth a shot.

    I recommend reading the following: https://theeventscalendar.com/knowledgebase/downgrading-plugin-past-version/

    Let me check to see if there is not an obvious code change we can pin this on.

    Best regards,

    Geoff B.

    #1291715
    Brian
    Participant

    Great, thanks Geoff.

    #1292670
    Barry
    Member

    Hi Brian,

    Perhaps a snippet like this that you could add to a custom plugin would help, however I warn you that it is not safe in its current form:

    add_action( 'tribe_events_update_meta', function( $event_id, $data ) {
    	if (
    		! isset( $_POST['EventCost'] )
    		|| ! isset( $data['EventCost'] )
    		|| $_POST['EventCost'] === $data['EventCost']
    	) {
    		return;
    	}
    
    	// Warning! This means there is zero sanitization: you should carefully consider
    	// what you do and do not wish to accept here and take the time to implement
    	// suitable safeguards
    	$true_cost = $_POST['EventCost'];
    	update_post_meta( $event_id, '_EventCost', $true_cost );
    }, 10, 2 );
    

    Please take the time to read the comments and implement proper sanitization (or seek the advice of a dev who can help you with this if you are unsure).

    I hope it helps!

    #1302958
    Support Droid
    Keymaster

    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

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘tags not being saved in cost field in single event’ is closed to new replies.