I am not really sure I understand the question. You would like to display different markup depending on which fields are set in the $atts
array? If this is the case, then this should work:
// Check so fields are set in the `$atts` array.
if (isset($atts['img'], $atts['user'], $atts['text'])) {
return '<div class="hire-equipment-item">
<div class="hire-equipment-item-img">
<img src="' . esc_url($atts['img']) . '" height=200px" width="200px" alt="">
</div><br />
<div class="hire-equipment-item-user">' . $atts['user'] . '</div>
<div class="hire-equipment-item-text">' . sanitize_text_field($atts['text']) . '</div>
</div>';
}
elseif (isset($atts['img'], $atts['text'], $atts['length'], $atts['material'], $atts['power'])) {
// Second output goes here.
}
Notice that user
may not be set in the second case else the first condition will always be true.
Since the markup for both conditions are very similar a better approach might be:
function hire_equipment_func($atts) {
// Store merged result.
$atts = shortcode_atts(array(
'img' => '',
'user' => '',
'text' => '',
'length' => '',
'material' => '',
'power' => '',
), array_change_key_case($atts, CASE_LOWER));
$output="<div class="hire-equipment-item>";
// Check if image should be appended to output.
if (isset($atts['img'])) {
$output .= '<div class="hire-equipment-item-img">
<img src="' . esc_url($attribs['img']) . '" height="200" width="200" alt="" />
</div>';
}
// Check if user should be appended to output.
if (isset($atts['user'])) {
$output .= '<div class="hire-equipment-item-user">' . $atts['user'] . '</div>';
}
// Check if text should be appended to output.
if (isset($atts['text'])) {
$output .= '<div class="hire-equipment-item-text">' . $atts['text'] . '</div>';
}
// Check if we need to output more-information table.
if (isset($atts['length']) || isset($atts['material']) || isset($atts['power'])) {
$output .= '<div class="hire-equipment-more-information">
<table class="hire-equipment-more-information-table" cellpadding="15px">
<tr>
<th>Length:</th>
<th>Material:</th>
<th>Power:</th>
</tr>
<tr>
<td> ' . (isset($atts['length']) ? $atts['length'] : '') . ' </td>
<td> ' . (isset($atts['material']) ? $atts['material'] : '') . ' </td>
<td> ' . (isset($atts['power']) ? $atts['power'] : '') . ' </td>
</tr>
</table>
</div>';
}
$output .= '</div>';
return $output;
}
You might also need to use some sanitazion for your output. For instance use esc_url()
for urls and sanitize_text_field()
for strings and so on.