admin管理员组

文章数量:1323730

I have a shortcode that fetches some values, first_name, last_name and email from a remote database. I'm trying to write a shortcode that will allow me to print 2 or more of those values within output between shortcode tags. For example, I may call my shortcode like this:

[user_data]{{firist_name}} {{last_name}}'s email address is {{email}}[/user_data]

or maybe

[user_data]The email address is {{email}} belongs to {{firist_name}} {{last_name}}.[/user_data]

I know I can write a shortcode that prints 1 of the individual values and call it 3 times like this:

[user_data field="first_name"] [user_data field="last_name"]'s email address is [user_data field="email"] 

But that seems rather inefficient to me. Suppose i have the shortcode:

function user_data($atts, $content=null) {
  $a = shortcode_atts( array(
    'uid' => 0
  ), $atts );

  // get an array with all of user's data
  $fetched_data = my_data_fetching_function($a['uid']);
  $out = $content;
  return $out;
}

Is there any way to make $fetched_data somehow available to $content?

本文标签: How to use multiple (or array) values in content of shortcode