-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
242 lines (196 loc) · 6.92 KB
/
functions.php
File metadata and controls
242 lines (196 loc) · 6.92 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
/**
* Define Constants
*/
if( !defined( 'BTP_DIR_PATH' ) ) {
define( 'BTP_DIR_PATH', untrailingslashit( get_template_directory() ) );
}
if( !defined( 'BTP_DIR_URI' ) ) {
define( 'BTP_DIR_URI', untrailingslashit( get_template_directory_uri() ) );
}
/**
* Include Files
*/
$inc_files = [
'lib/class-btp-singleton.php',
'lib/class-btp-theme.php',
'lib/btp-cpt/btp-cpt.php',
'lib/class-btp-taxonomy-field.php',
'lib/class-btp-shortcode.php',
'lib/filters/class-btp-filters.php',
'lib/class-btp-theme-customize.php'
];
foreach ($inc_files as $file_to_include ) {
require_once( $file_to_include );
}
/**
* Add extra fields into orbit query attributes
*/
add_filter('orbit_query_atts', function( $atts ){
$atts['button'] = '0';
$atts['button_title'] = '';
$atts['button_slug'] = '';
$atts['posts_per_frame'] = 6;
return $atts;
});
/**
* Returns list of categories the post belongs to
*/
function btp_get_categories($post_id)
{
$categories = get_the_category($post_id);
if( $categories && count($categories)) {
echo '<ul class="category-pills">';
foreach ($categories as $cat) {
echo '<li>'.$cat->name.'</li>';
}
echo '</ul>';
}
}
function btp_get_categories_with_type( $post_id, $type ){
$categories = get_the_category( $post_id );
echo '<ul class="category-pills">';
if( $categories && count( $categories ) ){
foreach ($categories as $cat) {
echo '<li>'.$cat->name.'</li>';
}
}
echo '<li>'.$type.'</li>';
echo '</ul>';
}
function add_query_vars_filter( $vars ){
$vars[] = "type";
return $vars;
}
add_filter( 'query_vars', 'add_query_vars_filter' );
/**
* Returns list of episodes for a given podcast series
*/
function btp_get_episodes_list( $podcast_id ) {
if( ! $podcast_id ) {
return false;
}
$episodes = get_children( [
'post_parent' => $podcast_id,
'order' => 'ASC',
], ARRAY_A );
foreach ($episodes as $key => $episode) {
$episodes[$key]['episode_number'] = get_post_meta($episode['ID'], 'btp_episode_number', true);
}
return $episodes;
}
/**
* Reuturns list of videos exluding the currently passed id
*/
function btp_get_videos( $id ) {
$args = [
'post_type' => 'video',
'post_status' => 'publish',
'posts_per_page' => 4,
'post__not_in' => [$id],
];
$query = new WP_Query($args);
if( isset($query->posts) ) {
return $query->posts;
}
return [];
}
/** RETURNS UNIQUE ID **/
function getUniqueID( $data ){
return substr( md5( json_encode( $data ) ), 0, 8 );
}
/**
* Add og-meta tags on single post template
*/
function btp_single_template_og_tags() {
global $post;
if( is_single() ) {
$url = get_post_permalink();
$title = get_the_title();
$image = BTP_DIR_URI . '/assets/images/BP_with_tagline.png';
$desc = strip_shortcodes( strip_tags( $post->post_content) );
$desc = str_replace(array("\n", "\r", "\t"), ' ', $desc);
$desc = substr( $desc, 0, 153) . '...';
if( has_post_thumbnail($post->ID) ) {
$image = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'full', false)[0];
}
ob_start(); ?>
<meta property="og:url" content="<?php _e($url); ?>">
<meta property="og:title" content="<?php _e($title); ?>">
<meta property="og:description" content="<?php _e($desc); ?>">
<meta property="og:type" content="article">
<meta property="og:image" content="<?php _e($image); ?>">
<meta property="og:site_name" content="<?php bloginfo(); ?>">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:creator" content="@PopuliBot">
<meta name="twitter:site" content="@PopuliBot">
<meta name="twitter:url" content="<?php _e($url); ?>">
<meta name="twitter:title" content="<?php _e($title); ?>">
<meta name="twitter:description" content="<?php _e($desc); ?>">
<meta name="twitter:image" content="<?php _e($image); ?>">
<?php
ob_end_flush();
} else {
return '';
}
}
add_action('wp_head', 'btp_single_template_og_tags', 4);
/**
* Load facebook js sdk for sharing on single post template
*/
add_action('wp_body_open', function(){
if(is_single() ) {
echo '
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v11.0" nonce="lI5IEiFW"></script>
';
};
});
/**
* Return list of social share icons
*/
function btp_get_social_share_links( $aside = true ) {
global $post;
$permalink = get_the_permalink();
$title = get_the_title();
$desc = strip_shortcodes( strip_tags( $post->post_content) );
$desc = str_replace(array("\n", "\r", "\t"), ' ', $desc);
$desc = substr( $desc, 0, 153) . '...';
ob_start(); ?>
<ul class="btp-social-icons list-unstyled <?php !$aside ? _e('list-inline') : ''; ?>">
<!-- link -->
<li class="<?php !$aside ? _e('list-inline-item ') : ''; ?>social-icon">
<a href="<?php _e($permalink);?>" class="btp-copy-link"><ion-icon name="link"></ion-icon></a>
</li>
<!-- facebook -->
<li class="<?php !$aside ? _e('list-inline-item ') : ''; ?>social-icon" data-href="<?php _e($permalink);?>">
<a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php _e($permalink);?>&src=sdkpreparse" class="fb-xfbml-parse-ignore"><ion-icon name="logo-facebook"></ion-icon></a>
</li>
<!-- email -->
<li class="<?php !$aside ? _e('list-inline-item ') : ''; ?>social-icon">
<a href="mailto:?&subject=<?php _e($title);?>&body=<?php _e($permalink);?>"><ion-icon name="mail-outline"></ion-icon></a>
</li>
<!-- twitter -->
<li class="<?php !$aside ? _e('list-inline-item ') : ''; ?>social-icon">
<a target="_blank" href="https://twitter.com/intent/tweet?text=<?php _e($desc);?>&url=<?php _e($permalink);?>&via=PopuliBot"><ion-icon name="logo-twitter"></ion-icon></a>
</li>
</ul>
<?php ob_end_flush();
}
// RETURNS ORBIT SHORTCODE
function btp_get_author_posts( $current_author, $per_page = 6 ) {
$shortcode_str = '[orbit_query post_type="post" pagination="1" style="card" posts_per_page="'.$per_page.'" ';
if( isset( $current_author->type ) && $current_author->type == 'wpuser' ){
$shortcode_str .= 'author="'. $current_author->ID .'"';
} else{
$shortcode_str .= 'tax_query="author:cap-'.$current_author->user_nicename.'"';
}
$shortcode_str .= ']';
return $shortcode_str;
}
// ENABLE COAUTHOR METABOX
add_filter( 'coauthors_count_published_post_types', function( $post_types ) {
$coauthor_cpt_support = array('episode','video','podcast');
array_push( $coauthor_cpt_support );
return $post_types;
} );