-
Notifications
You must be signed in to change notification settings - Fork 15
/
template-tags.php
161 lines (124 loc) · 3.68 KB
/
template-tags.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
namespace DevHub;
function wp_doc_comment( $comment, $args, $depth ) {
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<article id="comment-<?php comment_ID(); ?>" class="comment">
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your example is awaiting moderation.', 'wporg' ); ?></em>
<br />
<?php endif; ?>
<pre class="example-content"><?php echo htmlentities( get_comment_text() ); ?></pre>
<footer class="comment-meta">
<div class="comment-author vcard">
<?php
echo get_avatar( $comment );
/* translators: 1: comment author, 2: date and time */
printf( __( 'Contributed by %1$s on %2$s', 'wporg' ),
sprintf( '<span class="fn">%s</span>', get_comment_author_link() ),
sprintf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
esc_url( get_comment_link( $comment->comment_ID ) ),
get_comment_time( 'c' ),
/* translators: 1: date, 2: time */
sprintf( __( '%1$s at %2$s', 'wporg' ), get_comment_date(), get_comment_time() )
)
);
?>
<?php edit_comment_link( __( 'Edit', 'wporg' ), '<span class="edit-link">', '</span>' ); ?>
</div>
<!-- .comment-author .vcard -->
</footer>
</article>
<!-- #comment-## -->
<?php
}
/**
* Get current (latest) since version
*
* @return object
*/
function get_current_version() {
$version = get_terms( 'wpapi-since', array(
'number' => '1',
'order' => 'DESC',
) );
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 ( is_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
*
* @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
*
* @param string $name
*
* @return string
*/
function get_since_link( $name = null ) {
$since_object = get_term_by( 'name', empty( $name ) ? get_since() : $name, 'wpapi-since' );
return empty( $since_object ) ? '' : esc_url( get_term_link( $since_object ) );
}
/**
* Retrieve name of since version
*
* @param int $post_id
*
* @return string
*/
function get_since( $post_id = null ) {
$since_object = wp_get_post_terms( empty( $post_id ) ? get_the_ID() : $post_id, 'wpapi-since', array( 'fields' => 'names' ) );
return empty( $since_object ) ? '' : esc_html( $since_object[0] );
}