Skip Navigation

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

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 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.

Marqué : ,

This topic contains 2 réponses, has 2 voix.

Last updated by Eric Il y a 2 années et 10 mois.

Assigned support staff: Christian Cox.

Auteur
Publications
#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

Christian Cox
Supporter

Languages: Anglais (English )

Timezone: America/New_York (GMT-04:00)

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!