08/01/2016 at 6:15 pm
#385115
Keymaster
@ William
Here’s a working function:
function getFamilyMemberDetailsBlock( $atts, $entry ) {
$defaults = array(
'container_tag' => 'ul',
'item_tag' => 'li',
'item_format' => '<%1$s class="cn-relation"><span class="cn-relation-label">%relation%</span>%separator% <span class="cn-relation-name notranslate">%name%</span></%1$s>',
'name_format' => '',
'separator' => ':',
'before' => '',
'after' => '',
'before_item' => '',
'after_item' => '',
'return' => FALSE,
);
$atts = wp_parse_args( $atts, $defaults );
$html = '';
$search = array( '%relation%', '%name%', '%separator%' );
if ( $relations = $entry->getFamilyMembers() ) {
// Grab an instance of the Connections object.
$instance = Connections_Directory();
foreach ( $relations as $relationData ) {
$relation = new cnOutput();
$replace = array();
if ( $relation->set( $relationData['entry_id'] ) ) {
$replace[] = $instance->options->getFamilyRelation( $relationData['relation'] );
$replace[] = cnURL::permalink(
array(
'type' => 'name',
'slug' => $relation->getSlug(),
'title' => $relation->getName( array( 'format' => $atts['name_format'] ) ),
'text' => $relation->getName( array( 'format' => $atts['name_format'] ) ),
'home_id' => $entry->directoryHome['page_id'],
'force_home' => $entry->directoryHome['force_home'],
'return' => TRUE,
)
);
$replace[] = empty( $atts['separator'] ) ? '' : '<span class="cn-separator">' . $atts['separator'] . '</span>';
$row = str_ireplace(
$search,
$replace,
empty( $atts['item_format'] ) ? $defaults['item_format'] : $atts['item_format']
);
$html .= "\t" . sprintf( $row, $atts['item_tag'] ) . PHP_EOL;
}
if ( $atts['show_phone_numbers'] ) {
$html .= $relation->getPhoneNumberBlock( array( 'format' => $atts['phone_format'], 'type' => $atts['phone_types'], 'return' => TRUE ) );
}
if ( $atts['show_email'] ) {
$html .= $relation->getEmailAddressBlock( array( 'format' => $atts['email_format'], 'type' => $atts['email_types'], 'return' => TRUE ) );
}
if ( $atts['show_dates'] ) {
$html .= $relation->getDateBlock( array( 'format' => $atts['date_format'], 'type' => $atts['date_types'], 'return' => TRUE ) );
}
}
$html = sprintf(
'<%1$s class="cn-relations">' . PHP_EOL . '%2$s</%1$s>',
$atts['container_tag'],
$html
);
$html = $atts['before'] . $html . $atts['after'] . PHP_EOL;
}
echo $html;
}
