Using HTML-code in explaining text for Additional Fields

Home Forums Calendar Products Community Events Using HTML-code in explaining text for Additional Fields

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1325140
    Oliver
    Participant

    Hi,

    for the additional fields a text can be typed in to explain it.
    Inside this text I want to add HTML-code (e.g. to insert a link to another page).

    Unfortunately every HTML code I inserted is automatically deleted (maybe for security – injection – reasons).
    Is it possible to use HTML code there, too? (by a tweak?)

    Best regards,
    Oliver

    #1326082
    Barry
    Member

    Hi Oliver,

    Thanks for contacting us.

    add_filter( 'tribe-events-save-options', function( $options ) {
    	if ( ! isset( $_POST['custom-field'] ) ) {
    		return $options;
    	}
    
    	foreach ( $_POST['custom-field-options'] as $key => $values ) {
    		$key = absint( substr( $key, 1 ) );
    
    		if ( ! $key ) {
    			continue;
    		}
    
    		if ( ! isset( $options['custom-fields'][ $key ] ) ) {
    			continue;
    		}
    
    		$options['custom-fields'][ $key ]['values'] = wp_kses_data( $values );
    	}
    
    	return $options;
    } );

    The code I outlined above, which could be added to a custom plugin or potentially even to your theme’s functions.php file ought to help.

    It does strip away a layer of protection, but should be pretty safe.

    Might that work for you?

    #1326571
    Oliver
    Participant

    Hi Barry!

    thanks for the super fast reply!

    The code works to input HTML in the custom field, but unfortunately the HTML is not executed in the frontend – see screenshot.

    Best regards,
    Oliver

    #1326597
    Barry
    Member

    Ahh, right you are – sorry for missing that. There are a few steps needed to workaround this side of the problem.

    First, copy events-calendar-pro/src/admin-views/event-meta.php to a custom location. Then, tell Events Calendar PRO to actually use your new replacement – which can be done using code like this:

    add_filter( 'tribe_events_event_meta_template', function() {
        return '/path/to/your/custom-override/event-meta.php';
    } );

    Within that template, look out for code like this (this example can be found on line 36 of the current template):

    <?php echo esc_html( stripslashes( $option ) ) ?>

    Remove the esc_html( … ) wrapper so that you have:

    <?php echo stripslashes( $option ) ?>

    And that should, hopefully, get you on track. It may be a comparable change is needed for frontend output, too – and similar principles would need to be followed if so.

    #1330327
    Oliver
    Participant

    Thanks Barry, that looks good! 🙂

    Best regards,
    Oliver

    #1330328
    Oliver
    Participant

    #1330515
    Barry
    Member

    Great!

    #1340352
    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 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Using HTML-code in explaining text for Additional Fields’ is closed to new replies.