-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions-takeoff.php
315 lines (289 loc) · 10.9 KB
/
functions-takeoff.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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
/**
* Hide or show admin bar on frontend, false = hide
*/
show_admin_bar( false );
/**
* Register Custom Navigation Walker for Bootstrap
*/
require_once get_template_directory() . '/inc/wp-bootstrap-navwalker.php';
/**
* Enqueue scripts and styles.
*/
function takeoff_scripts() {
wp_enqueue_style( 'bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
wp_enqueue_style( 'takeoff-style', get_stylesheet_uri() );
wp_enqueue_style( 'fontawesome-css', 'https://use.fontawesome.com/releases/v5.0.0/css/all.css' );
wp_enqueue_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js', array(), '3.2.1', true );
wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(), '3', true );
wp_enqueue_script( 'takeoff-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
wp_enqueue_script( 'takeoff-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'takeoff_scripts' );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function takeoff_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'takeoff' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'takeoff' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Left', 'takeoff' ),
'id' => 'footer-left',
'description' => esc_html__( 'Add widgets here.', 'takeoff' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Middle', 'takeoff' ),
'id' => 'footer-middle',
'description' => esc_html__( 'Add widgets here.', 'takeoff' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Right', 'takeoff' ),
'id' => 'footer-right',
'description' => esc_html__( 'Add widgets here.', 'takeoff' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>',
'after_title' => '</h4>',
) );
}
add_action( 'widgets_init', 'takeoff_widgets_init' );
/**
* Insert google fonts
*/
function takeoff_google_fonts($str_fonts = false)
{
if ($str_fonts) {
// build output
$arr_fonts = explode('|', $str_fonts); // break apart each font set
foreach ($arr_fonts as $font) {
if (false === strpos($font, ':')) {
$arr_sets[] = $font . ':400'; // has no specific type, use 400
} else {
if (false === strpos($font, ',')) {
$arr_sets[] = $font; // has only one specific type
} else {
// has multiple types
$arr_family = explode(':', $font);
$arr_types = explode(',', $arr_family[1]);
foreach ($arr_types as $type) {
$arr_sets[] = $arr_family[0] . ':' . $type;
}
}
}
}
echo "<!--[if gt IE 8]><!--> \n"
. "<link rel='stylesheet' href='//fonts.googleapis.com/css?family=" . $str_fonts . "' /> \n"
. "<!--<![endif]--> \n"
. "<!--[if lte IE 8]> \n";
foreach ($arr_sets as $set) {
echo "<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=" . $set . "' /> \n";
}
echo "<![endif]--> \n";
}
}
/**
* Breadcrumbs array
*
* @return array Breadrumbs string name, optional string link
*/
function takeoff_get_breadcrumbs()
{
$breadcrumbs = array();
$page_on_front = get_option('page_on_front');
$page_for_posts = get_option('page_for_posts', true);
// if exists, initialize with front page
if ($page_on_front && !is_front_page()) {
$breadcrumbs[] = array(
'name' => get_the_title($page_on_front),
'link' => get_permalink($page_on_front)
);
}
if ($page_for_posts && is_home()) {
$breadcrumbs[] = array(
'name' => get_the_title($page_for_posts)
);
} elseif (is_404()) {
$breadcrumbs[] = array(
'name' => 'Page Not Found'
);
} elseif (is_search()) {
$breadcrumbs[] = array(
'name' => 'Search Results'
);
} elseif ($page_for_posts && (is_single() || is_category() || is_tag() || is_author() || is_day() || is_month() || is_year())) {
// set blog for single and archives
$breadcrumbs[] = array(
'name' => get_the_title($page_for_posts),
'link' => get_permalink($page_for_posts)
);
if (is_category()) {
$breadcrumbs[] = array(
'name' => single_cat_title('', false)
);
} elseif (is_tag()) {
$breadcrumbs[] = array(
'name' => single_tag_title('', false)
);
}
} elseif (!is_front_page()) {
$ancestors = array_reverse(get_ancestors(get_the_ID(), 'page'));
foreach ($ancestors as $ancestor) {
$breadcrumbs[] = array(
'name' => get_the_title($ancestor),
'link' => get_permalink($ancestor)
);
}
$breadcrumbs[] = array(
'name' => get_the_title()
);
}
return $breadcrumbs;
}
/**
* Display an alternate title
*
* These are for seo when we need one "menu" title and another via title_alternate custom field
*
* @param string for output before title
* @param string for output after title
* @param bool will echo on true
*
* @return string title in some cases
*/
function takeoff_the_alternate_title($before = '', $after = '', $echo = true)
{
// based on the_title() in /wp-includes/post-template.php
$title = takeoff_get_the_alternate_title();
if (0 == strlen($title)) {
return;
}
$title = $before . $title . $after;
if ($echo) {
echo $title;
} else {
return $title;
}
}
/**
* Determine the alternate title
*
* @param mixed post that should be checked
*
* @return string alternate title
*/
function takeoff_get_the_alternate_title($post = 0)
{
// based on get_the_title() in /wp-includes/post-template.php
$post = get_post($post);
$title = isset($post->post_title) ? $post->post_title : '';
$id = isset($post->ID) ? $post->ID : 0;
// alternate is found here
$title_alternate = get_post_meta($id, 'title_alternate', true);
$title = ('' != $title_alternate) ? $title_alternate : $title;
if (!is_admin()) {
if (!empty($post->post_password)) {
$protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
$title = sprintf($protected_title_format, $title);
} elseif (isset($post->post_status) && 'private' == $post->post_status) {
$private_title_format = apply_filters('private_title_format', __('Private: %s'));
$title = sprintf($private_title_format, $title);
}
}
return apply_filters('the_title', $title, $id);
}
/**
* Comments Callback / Layout of the Comments List
*/
function takeoff_comments_callback($comment, $args, $depth){
//checks if were using a div or ol|ul for our output
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
?>
<<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $args['has_children'] ? 'parent' : '', $comment ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<div class="comment-author-avatar">
<?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
</div>
<div class="comment-content">
<div class="comment-author-name">
<?php printf( __( '%s ' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link( $comment ) ) ); ?>
</div>
<div class="comment-meta">
<time datetime="<?php comment_time( 'c' ); ?>">
<?php
/* translators: 1: comment date, 2: comment time */
printf( __( '%1$s' ), get_comment_date( '', $comment ), get_comment_time() );
?>
</time>
<p><?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?></p>
<?php if ( '0' == $comment->comment_approved ) : ?>
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
<?php endif; ?>
</div>
<div class="comment-details">
<?php comment_text(); ?>
</div><!-- .comment-content -->
<div class="comment-reply">
<?php
comment_reply_link( array_merge( $args, array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '<p class="reply call-to-action">',
'after' => '</p>'
) ) );
?>
</div>
</div>
</article><!-- .comment-body -->
<?php
}
/**
* Move Comment Field below Name & Email
*/
function takeoff_move_comment_field_to_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'takeoff_move_comment_field_to_bottom' );
/**
* Edit comment notification for non-logged in users
*/
function takeoff_pre_comment_text( $arg ) {
$arg['comment_notes_before'] = "Your email address will not be published.";
return $arg;
}
add_filter( 'comment_form_defaults', 'takeoff_pre_comment_text' );
/**
* Add ACF Options for Theme Settings
*/
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
}