Skip to content

Commit

Permalink
Implemented return information template tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarst committed Jan 12, 2014
1 parent f9f4f95 commit 1afebe4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion archive-wpapi-function.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<?php the_content(); ?>
</section>

<section class="return"><strong>Return:</strong> TODO</section>
<section class="return"><strong>Return:</strong> <?php echo get_return(); ?></section>

<?php
$since = get_since();
Expand Down
28 changes: 28 additions & 0 deletions template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ function get_current_version() {
return $version[0];
}

/**
* Retrieve return type and description if available
*
* @param int $post_id
*
* @return string
*/
function get_return( $post_id = null ) {

if ( empty( $post_id ) ) {
$post_id = get_the_ID();
}

$tags = get_post_meta( $post_id, '_wpapi_tags', true );
$return = wp_filter_object_list( $tags, array( 'name' => 'return' ) );

if ( empty( $return ) ) {
$description = '';
$type = 'void';
} else {
$return = array_shift( $return );
$description = empty( $return['content'] ) ? '' : esc_html( $return['content'] );
$type = empty( $return['types'] ) ? '' : esc_html( implode( '|', $return['types'] ) );
}

return "<span class='return-type'>{$type}</span> $description";
}

/**
* Retrieve URL to since version archive
*
Expand Down

0 comments on commit 1afebe4

Please sign in to comment.