Skip Navigation

[Gelöst] Wrapping Types field in a (registered) third-party shortcode not working

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I would like to use the Email Encoder Bundle plugin to encode a phone number from a Types field.

Solution: Use a custom shortcode to apply the EEB plugin API and the Types field API together:

function ts_eeb_field_func($atts) {
  global $post;
  $a = shortcode_atts( array(
      'field' => '',
      'id' => $post->ID,
  ), $atts );
  $field = types_render_field( $a['field'], array( 'id'=>$a['id'] ));
  return eeb_content( $field );
}
add_shortcode("ts-eeb-field", "ts_eeb_field_func");

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/

This support ticket is created vor 5 Jahre, 7 Monate. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 Antworten, has 2 Stimmen.

Last updated by Eric vor 5 Jahre, 7 Monate.

Assisted by: Christian Cox.

Author
Artikel
#1103710
Screen Shot 2018-09-09 at 11.03.26 AM.png

I am trying to:
Use a plugin (Email Encoder Bundle) to encode email addresses and phone numbers in a table that is dynamically generated in a view. My client is concerned about bots harvesting email and phones....

The email encoding happens automatically (supposedly—I haven't confirmed yet), but the phone numbers need to be wrapped in a shortcode [eeb_content][/eeb_content]. From my View I have:

[eeb_content][types field="phone"][/types][/eeb_content]

I'm uploading a cropped screen grab so the names and email addresses aren't fully visible. I can send you a link to the page, privately.

Thanks,
Eric

#1103735

It's possible the Email Encoder Bundle plugin isn't able to interpret any shortcodes, not just Types shortcodes. If that is the case, you will need a custom shortcode that uses the eeb_content function with the types_render_field function. Add this code to your child theme's functions.php file:

function ts_eeb_field_func($atts) {
  global $post;
  $a = shortcode_atts( array(
      'field' => '',
      'id' => $post->ID,
  ), $atts );
  $field = types_render_field( $a['field'], array( 'id'=>$a['id'] ));
  return eeb_content( $field );
}
add_shortcode("ts-eeb-field", "ts_eeb_field_func");

Then instead of using the eeb_content and types field shortcodes, use the new custom shortcode:

[ts-eeb-field field='your-field-slug'][/ts-eeb-field]
#1103816

That worked! Had to double-check the shortcode names though; one read "ts-eeb-field" and the other was "ts-eeb-content". Once those were consistent, bingo!

Thank you very much!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.