Skip to content

Commit

Permalink
Implemented signature template tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rarst committed Jan 13, 2014
1 parent 462a23f commit f71a43d
Show file tree
Hide file tree
Showing 2 changed files with 47 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 @@ -14,7 +14,7 @@

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<h1><?php the_title(); ?></h1>
<h1><a href="<?php the_permalink() ?>"><?php echo get_signature(); ?></a></h1>

<section class="description">
<?php the_excerpt(); ?>
Expand Down
46 changes: 46 additions & 0 deletions template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,52 @@ function get_current_version() {
return $version[0];
}

/**
* Retrieve function name and arguments as signature string
*
* @param int $post_id
*
* @return string
*/
function get_signature( $post_id = null ) {

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

$signature = get_the_title( $post_id ) . '(';
$args = get_post_meta( $post_id, '_wpapi_args', true );
$args_strings = array();

foreach ( $args as $arg ) {

$arg_string = '';
if ( ! empty ( $arg['type'] ) ) {
$arg_string .= $arg['type'];
}

if ( ! empty ( $arg['name'] ) ) {
$arg_string .= ' ' . $arg['name'] . ' ';
}

if ( array_key_exists( 'default', $arg ) ) {

if ( null === $arg['default'] ) {
$arg['default'] = 'null';
}

$arg_string .= '= ' . $arg['default'];
}

$args_strings[] = $arg_string;
}


$signature .= implode( ', ', $args_strings ) . ' )';

return esc_html( $signature );
}

/**
* Retrieve return type and description if available
*
Expand Down

0 comments on commit f71a43d

Please sign in to comment.