Skip Navigation

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por Eric hace 6 años, 2 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#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!