|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Custom template tags for this theme |
|
4
|
|
|
* |
|
5
|
|
|
* Eventually, some of the functionality here could be replaced by core features. |
|
6
|
|
|
* |
|
7
|
|
|
* @package bitsy |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
View Code Duplication |
if ( ! function_exists( 'bitsy_posted_on' ) ) : |
|
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Prints HTML with meta information for the current post-date/time and author. |
|
13
|
|
|
*/ |
|
14
|
|
|
function bitsy_posted_on() { |
|
15
|
|
|
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; |
|
16
|
|
|
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { |
|
|
|
|
|
|
17
|
|
|
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$time_string = sprintf( $time_string, |
|
21
|
|
|
esc_attr( get_the_date( 'c' ) ), |
|
|
|
|
|
|
22
|
|
|
esc_html( get_the_date() ), |
|
|
|
|
|
|
23
|
|
|
esc_attr( get_the_modified_date( 'c' ) ), |
|
|
|
|
|
|
24
|
|
|
esc_html( get_the_modified_date() ) |
|
25
|
|
|
); |
|
26
|
|
|
|
|
27
|
|
|
$posted_on = sprintf( |
|
28
|
|
|
/* translators: %s: post date. */ |
|
29
|
|
|
esc_html_x( 'Posted on %s', 'post date', 'bitsy' ), |
|
|
|
|
|
|
30
|
|
|
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>' |
|
|
|
|
|
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
$byline = sprintf( |
|
34
|
|
|
/* translators: %s: post author. */ |
|
35
|
|
|
esc_html_x( 'by %s', 'post author', 'bitsy' ), |
|
36
|
|
|
'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>' |
|
|
|
|
|
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK. |
|
40
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
endif; |
|
43
|
|
|
|
|
44
|
|
|
if ( ! function_exists( 'bitsy_entry_footer' ) ) : |
|
45
|
|
|
/** |
|
46
|
|
|
* Prints HTML with meta information for the categories, tags and comments. |
|
47
|
|
|
*/ |
|
48
|
|
|
function bitsy_entry_footer() { |
|
49
|
|
|
// Hide category and tag text for pages. |
|
50
|
|
|
if ( 'post' === get_post_type() ) { |
|
|
|
|
|
|
51
|
|
|
/* translators: used between list items, there is a space after the comma */ |
|
52
|
|
|
$categories_list = get_the_category_list( esc_html__( ', ', 'bitsy' ) ); |
|
|
|
|
|
|
53
|
|
|
if ( $categories_list ) { |
|
54
|
|
|
/* translators: 1: list of categories. */ |
|
55
|
|
|
printf( '<span class="cat-links">' . esc_html__( 'Posted in %1$s', 'bitsy' ) . '</span>', $categories_list ); // WPCS: XSS OK. |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/* translators: used between list items, there is a space after the comma */ |
|
59
|
|
|
$tags_list = get_the_tag_list( '', esc_html_x( ', ', 'list item separator', 'bitsy' ) ); |
|
|
|
|
|
|
60
|
|
|
if ( $tags_list ) { |
|
61
|
|
|
/* translators: 1: list of tags. */ |
|
62
|
|
|
printf( '<span class="tags-links">' . esc_html__( 'Tagged %1$s', 'bitsy' ) . '</span>', $tags_list ); // WPCS: XSS OK. |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { |
|
|
|
|
|
|
67
|
|
|
echo '<span class="comments-link">'; |
|
68
|
|
|
comments_popup_link( |
|
|
|
|
|
|
69
|
|
|
sprintf( |
|
70
|
|
|
wp_kses( |
|
|
|
|
|
|
71
|
|
|
/* translators: %s: post title */ |
|
72
|
|
|
__( 'Leave a Comment<span class="screen-reader-text"> on %s</span>', 'bitsy' ), |
|
|
|
|
|
|
73
|
|
|
array( |
|
74
|
|
|
'span' => array( |
|
75
|
|
|
'class' => array(), |
|
76
|
|
|
), |
|
77
|
|
|
) |
|
78
|
|
|
), |
|
79
|
|
|
get_the_title() |
|
|
|
|
|
|
80
|
|
|
) |
|
81
|
|
|
); |
|
82
|
|
|
echo '</span>'; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
edit_post_link( |
|
|
|
|
|
|
86
|
|
|
sprintf( |
|
87
|
|
|
wp_kses( |
|
88
|
|
|
/* translators: %s: Name of current post. Only visible to screen readers */ |
|
89
|
|
|
__( 'Edit <span class="screen-reader-text">%s</span>', 'bitsy' ), |
|
90
|
|
|
array( |
|
91
|
|
|
'span' => array( |
|
92
|
|
|
'class' => array(), |
|
93
|
|
|
), |
|
94
|
|
|
) |
|
95
|
|
|
), |
|
96
|
|
|
get_the_title() |
|
97
|
|
|
), |
|
98
|
|
|
'<span class="edit-link">', |
|
99
|
|
|
'</span>' |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
endif; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Returns true if a blog has more than 1 category. |
|
106
|
|
|
* |
|
107
|
|
|
* @return bool |
|
108
|
|
|
*/ |
|
109
|
|
|
function bitsy_categorized_blog() { |
|
110
|
|
|
if ( false === ( $all_the_cool_cats = get_transient( 'bitsy_categories' ) ) ) { |
|
|
|
|
|
|
111
|
|
|
// Create an array of all the categories that are attached to posts. |
|
112
|
|
|
$all_the_cool_cats = get_categories( array( |
|
|
|
|
|
|
113
|
|
|
'fields' => 'ids', |
|
114
|
|
|
'hide_empty' => 1, |
|
115
|
|
|
// We only need to know if there is more than one category. |
|
116
|
|
|
'number' => 2, |
|
117
|
|
|
) ); |
|
118
|
|
|
// Count the number of categories that are attached to the posts. |
|
119
|
|
|
$all_the_cool_cats = count( $all_the_cool_cats ); |
|
120
|
|
|
set_transient( 'bitsy_categories', $all_the_cool_cats ); |
|
|
|
|
|
|
121
|
|
|
} |
|
122
|
|
|
if ( $all_the_cool_cats > 1 ) { |
|
123
|
|
|
// This blog has more than 1 category so components_categorized_blog should return true. |
|
124
|
|
|
return true; |
|
125
|
|
|
} else { |
|
126
|
|
|
// This blog has only 1 category so components_categorized_blog should return false. |
|
127
|
|
|
return false; |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Flush out the transients used in bitsy_categorized_blog. |
|
133
|
|
|
*/ |
|
134
|
|
|
function bitsy_category_transient_flusher() { |
|
135
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
|
|
|
|
|
136
|
|
|
return; |
|
137
|
|
|
} |
|
138
|
|
|
// Like, beat it. Dig? |
|
139
|
|
|
delete_transient( 'bitsy_categories' ); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
add_action( 'edit_category', 'bitsy_category_transient_flusher' ); |
|
|
|
|
|
|
143
|
|
|
add_action( 'save_post', 'bitsy_category_transient_flusher' ); |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Left sidebar loading logic |
|
147
|
|
|
*/ |
|
148
|
|
View Code Duplication |
if ( ! function_exists( 'bitsy_left_sidebar' ) ) { |
|
|
|
|
|
|
149
|
|
|
|
|
150
|
|
|
function bitsy_left_sidebar() { |
|
151
|
|
|
$sidebar_position = get_theme_mod( 'bitsy_sidebar_position' ); |
|
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
if ( ! is_page_template( 'page-templates/full-width.php' ) ) { |
|
|
|
|
|
|
154
|
|
|
if ( is_page_template( 'page-templates/left-sidebar.php' ) || is_page_template( 'page-templates/both-sidebars.php' ) || 'left' === $sidebar_position || 'both' === $sidebar_position ) { |
|
155
|
|
|
get_sidebar( 'left' ); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Right sidebar loading logic |
|
164
|
|
|
*/ |
|
165
|
|
View Code Duplication |
if ( ! function_exists( 'bitsy_right_sidebar' ) ) { |
|
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
function bitsy_right_sidebar() { |
|
168
|
|
|
$sidebar_position = get_theme_mod( 'bitsy_sidebar_position' ); |
|
|
|
|
|
|
169
|
|
|
|
|
170
|
|
|
if ( ! is_page_template( 'page-templates/full-width.php' ) ) { |
|
|
|
|
|
|
171
|
|
|
if ( is_page_template( 'page-templates/right-sidebar.php' ) || is_page_template( 'page-templates/both-sidebars.php' ) || 'right' === $sidebar_position || 'both' === $sidebar_position ) { |
|
172
|
|
|
get_sidebar( 'right' ); |
|
|
|
|
|
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Content classes loading logic |
|
181
|
|
|
*/ |
|
182
|
|
|
if ( ! function_exists( 'bitsy_content_classes' ) ) { |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Prints classes for content area div depending on active sidebars. |
|
186
|
|
|
* |
|
187
|
|
|
* Usage add this function between the class quotes like so |
|
188
|
|
|
* <div class="<?php bitsy_content_classes(); ?>" id="primary"> |
|
189
|
|
|
*/ |
|
190
|
|
|
function bitsy_content_classes() { |
|
191
|
|
|
$sidebar_position = get_theme_mod( 'bitsy_sidebar_position' ); |
|
|
|
|
|
|
192
|
|
|
$html = ''; |
|
193
|
|
|
|
|
194
|
|
|
if ( is_page_template( 'page-templates/left-sidebar.php' ) && is_active_sidebar( 'left-sidebar' ) ) { |
|
|
|
|
|
|
195
|
|
|
$html .= 'left-sidebar-template 8u 12u(small) content-area'; |
|
196
|
|
|
echo $html; // WPCS: XSS OK. |
|
197
|
|
|
|
|
198
|
|
|
} elseif ( is_page_template( 'page-templates/right-sidebar.php' ) && is_active_sidebar( 'right-sidebar' ) ) { |
|
199
|
|
|
$html .= 'right-sidebar-template 8u 12u(small) content-area'; |
|
200
|
|
|
echo $html; // WPCS: XSS OK. |
|
201
|
|
|
|
|
202
|
|
View Code Duplication |
} elseif ( is_page_template( 'page-templates/both-sidebars.php' ) && ( is_active_sidebar( 'left-sidebar' ) ) && is_active_sidebar( 'right-sidebar' ) ) { |
|
|
|
|
|
|
203
|
|
|
$html .= 'both-sidebar-template 6u 12u(small) content-area'; |
|
204
|
|
|
echo $html; // WPCS: XSS OK. |
|
205
|
|
|
|
|
206
|
|
|
} elseif ( is_page_template( 'page-templates/full-width.php' ) ) { |
|
207
|
|
|
$html .= 'full-width-template 12u content-area'; |
|
208
|
|
|
echo $html; // WPCS: XSS OK. |
|
209
|
|
|
|
|
210
|
|
|
} elseif ( 'right' === $sidebar_position || 'left' === $sidebar_position ) { |
|
211
|
|
|
|
|
212
|
|
|
if ( is_active_sidebar( 'right-sidebar' ) || is_active_sidebar( 'left-sidebar' ) ) { |
|
213
|
|
|
$html .= '8u 12u(small) content-area'; |
|
214
|
|
|
} else { |
|
215
|
|
|
$html .= '12u content-area'; |
|
216
|
|
|
} |
|
217
|
|
|
echo $html; // WPCS: XSS OK. |
|
218
|
|
|
|
|
219
|
|
|
} elseif ( is_active_sidebar( 'right-sidebar' ) && is_active_sidebar( 'left-sidebar' ) ) { |
|
220
|
|
|
$html = ''; |
|
221
|
|
|
if ( 'both' === $sidebar_position ) { |
|
222
|
|
|
$html .= '6u 12u(small) content-area'; |
|
223
|
|
|
} else { |
|
224
|
|
|
$html .= '12u content-area'; |
|
225
|
|
|
} |
|
226
|
|
|
echo $html; // WPCS: XSS OK. |
|
227
|
|
|
|
|
228
|
|
|
} else { |
|
229
|
|
|
echo '12u content-area'; |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Sidebar classes |
|
236
|
|
|
*/ |
|
237
|
|
|
if ( ! function_exists( 'bitsy_sidebar_classes' ) ) { |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Prints classes for sidebars area div depending on active sidebars. |
|
241
|
|
|
* |
|
242
|
|
|
* Add this function between the class quotes like so |
|
243
|
|
|
* <div class="<?php bitsy_sidebar_classes(); ?>"> |
|
244
|
|
|
*/ |
|
245
|
|
|
function bitsy_sidebar_classes() { |
|
246
|
|
|
$sidebar_position = get_theme_mod( 'bitsy_sidebar_position' ); |
|
|
|
|
|
|
247
|
|
|
$html = ''; |
|
248
|
|
|
|
|
249
|
|
|
if ( is_page_template( 'page-templates/both-sidebars.php' ) && ( is_active_sidebar( 'left-sidebar' ) ) && is_active_sidebar( 'right-sidebar' ) ) { |
|
|
|
|
|
|
250
|
|
|
$html .= '3u 12u(small) widget-area'; |
|
251
|
|
|
echo $html; // WPCS: XSS OK. |
|
252
|
|
View Code Duplication |
} elseif ( ( is_page_template( 'page-templates/left-sidebar.php' ) && is_active_sidebar( 'left-sidebar' ) ) || |
|
|
|
|
|
|
253
|
|
|
( is_page_template( 'page-templates/right-sidebar.php' ) && is_active_sidebar( 'right-sidebar' ) ) ) { |
|
254
|
|
|
$html .= '4u 12u(small) widget-area'; |
|
255
|
|
|
echo $html; // WPCS: XSS OK. |
|
256
|
|
|
} elseif ( ( 'right' === $sidebar_position || 'left' === $sidebar_position ) && ( is_active_sidebar( 'right-sidebar' ) || is_active_sidebar( 'left-sidebar' ) ) ) { |
|
257
|
|
|
$html .= '4u 12u(small) content-area'; |
|
258
|
|
|
echo $html; // WPCS: XSS OK. |
|
259
|
|
|
} elseif ( ( 'both' === $sidebar_position ) && ( is_active_sidebar( 'right-sidebar' ) && is_active_sidebar( 'left-sidebar' ) ) ) { |
|
260
|
|
|
$html .= '3u 12u(small) content-area'; |
|
261
|
|
|
echo $html; // WPCS: XSS OK. |
|
262
|
|
|
} else { |
|
263
|
|
|
$html .= '12u widget-area'; |
|
264
|
|
|
echo $html; // WPCS: XSS OK. |
|
265
|
|
|
} |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
|
|
272
|
|
|
|
|
273
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.