forked from alleyinteractive/fieldmanager-bylines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
166 lines (154 loc) · 4.46 KB
/
functions.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
162
163
164
165
166
<?php
/**
* Plugin functions
*
* @package Fieldmanager_Bylines
*/
/**
* Get a list of byline ids for a post
*
* @param int $post_id Post ID.
* @param string $type Defaults to author.
* @return array
*/
function fm_get_byline_ids( $post_id = null, $type = 'author' ) {
if ( empty( $post_id ) ) {
$post_id = get_the_ID();
}
return FM_Bylines()->get_byline_ids( $post_id, $type );
}
/**
* Get a list of byline objects for a post
*
* @param int $post_id Post ID.
* @param string $type Defaults to author.
* @param array $args Byline arguments.
* @return string
*/
function fm_get_byline( $post_id = null, $type = 'author', $args = array() ) {
if ( empty( $post_id ) ) {
$post_id = get_the_ID();
}
return FM_Bylines()->get_byline( $post_id, $type, $args );
}
/**
* Get the posts for a byline user
*
* @param int $byline_id The byline guest user id.
* @param string $type Byline type.
* @param array $args Byline arguments.
* @return array.
*/
function fm_get_byline_posts( $byline_id, $type = 'author', $args = array() ) {
return FM_Bylines()->get_byline_posts( $byline_id, $type, $args );
}
/**
* Get the WP Posts Query for a byline user.
*
* @param int $byline_id Defaults to current displayed byline id.
* @param string $type Defaults to current display byline type.
* @param array $args Byline arguments.
* @return mixed. WP Query object.
*/
function fm_get_byline_posts_query( $byline_id = null, $type = null, $args = array() ) {
return FM_Bylines()->get_byline_posts_query( $byline_id, $type, $args );
}
/**
* Get the html byline url for all bylines of a given type for a single post
*
* @param int $post_id Post ID.
* @param string $type Byline type.
* @return string
*/
function fm_get_bylines_posts_links( $post_id = null, $type = 'author' ) {
if ( empty( $post_id ) ) {
$post_id = get_the_ID();
}
return FM_Bylines()->get_bylines_posts_links( $post_id, $type );
}
/**
* Get the html markup for a single byline link
* Takes a single byline id
*
* @param int $byline_id Byline ID.
* @param string $type Byline type.
* @return string
*/
function fm_get_byline_link( $byline_id, $type = 'author' ) {
return FM_Bylines()->get_byline_link( $byline_id, $type );
}
/**
* Get the byline url
* Takes a single byline id
*
* @param int $byline_id Byline ID.
* @param string $type Byline type.
* @return string
*/
function fm_get_byline_url( $byline_id = null, $type = 'author' ) {
if ( ! empty( $byline_id ) ) {
return FM_Bylines()->get_byline_url( $byline_id, $type );
}
return '';
}
/**
* Add in a FM_Byline meta box w/ all it's bells and whistles
*
* @param string $type Byline type.
* @param string $label Optional label.
* @param array $args Byline arguments.
*/
function fm_add_byline_meta_box( $type = 'author', $label = null, $args = array() ) {
FM_Bylines()->add_byline_meta_box( $type, $label, $args );
}
/**
* Check if we are on a byline archive page. Equivalent of is_author().
*
* @param string $type Byline type.
* @param int $byline_id Byline ID.
* @return boolean
*/
function fm_is_byline( $type = 'author', $byline_id = null ) {
return FM_Bylines()->is_byline( $type, $byline_id );
}
/**
* Get Byline meta data. Equivalent of get_the_author_meta().
*
* @param string $field Byline meta field.
* @param int $byline_id Byline ID.
* @return mixed
*/
function fm_get_the_byline_meta( $field, $byline_id ) {
if ( in_array( $field, array( 'about', 'contact_info', 'names' ), true ) ) {
$meta_field = 'fm_bylines_' . $field;
} else {
$meta_field = $field;
}
return FM_Bylines()->get_the_byline_meta( $meta_field, $byline_id );
}
/**
* Get Byline avatar
*
* @param int $byline_id Byline ID.
* @param mixed $size Avatar size.
* @param array $args Byline arguments.
* @return string
*/
function fm_get_byline_avatar( $byline_id, $size, $args ) {
return FM_Bylines()->get_byline_avatar( $byline_id, $size, $args );
}
/**
* This function exists to attempt to create a label from a slug.
* If the label is complex you can use the filter hook to create a label lookup or modify single slugs.
*
* @param string $slug Slug to convert.
* @param string $callback Callback function to perform on wordified slug.
* @return string
*/
function fm_bylines_wordify_slug( $slug, $callback = 'ucwords' ) {
$label = str_replace( array( '-', '_' ), ' ', $slug );
if ( function_exists( $callback ) ) {
$label = $callback( $label );
}
return apply_filters( 'fm_bylines_slug_label', $label, $slug, $callback );
}