-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
321 lines (284 loc) · 9.38 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
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
313
314
315
316
317
318
319
320
321
<?php
/**
* Functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Fredo
* @since 1.0
*/
/**
* Assign the theme version to a var
*/
$theme = wp_get_theme( 'fredo' );
$fredo_version = $theme['Version'];
require 'inc/class-fredo-customizer.php';
/**
* Sets actions.
*/
add_action( 'after_setup_theme', 'fredo_setup' );
add_action( 'wp_enqueue_scripts', 'fredo_scripts' );
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function fredo_setup() {
// Make theme ready for translation.
load_theme_textdomain( 'fredo' );
// Add theme supports.
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_image_size( 'single', 660, 420, true );
add_action( 'init', 'disable_emojis' );
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
add_filter( 'excerpt_more', 'new_excerpt_more' );
add_action( 'widgets_init', 'widgets_init' );
remove_filter( 'init', 'get_avatar' );
// Content specific to remicorson.com
// Use remove_action() to disable those sections.
add_action( 'fredo_after_home_content', 'fredo_promote_theme_box' );
add_action( 'fredo_before_home_content', 'fredo_home_intro' );
add_action( 'walker_nav_menu_start_el', 'fredo_apply_button_class_to_last_menu_item', 10, 4 );
}
/**
* Enqueue scripts and styles.
*/
function fredo_scripts() {
global $fredo_version;
// Theme stylesheets.
wp_enqueue_style( 'fredo-main', get_theme_file_uri( '/assets/css/main.css' ), array(), $fredo_version, 'screen' );
// Fonts.
$google_fonts = apply_filters(
'fredo_google_font_families', array(
'lato' => 'Lato:300,300italic,700,700italic',
)
);
$query_args = array(
'family' => implode( '|', $google_fonts ),
'subset' => rawurlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
wp_enqueue_style( 'fredo-fonts', $fonts_url, array(), $fredo_version, 'screen' );
}
/**
* Shorten the excerpt.
*
* @param integer $length The excerpt default length.
*/
function custom_excerpt_length( $length ) {
return apply_filters( 'fredo_excerpt_length', 20 );
}
/**
* Replace [...] by ... in the excerpt.
*
* @param string $more The "more"" default value.
*/
function new_excerpt_more( $more ) {
return apply_filters( 'fredo_excerpt_length_more', '...' );
}
/**
* Display post thumbnail
*
* @var $size thumbnail size. thumbnail|medium|large|full|$custom
* @uses has_post_thumbnail()
* @uses the_post_thumbnail
* @param string $size the post thumbnail size.
*/
function fredo_post_thumbnail( $size = 'full' ) {
if ( has_post_thumbnail() ) {
the_post_thumbnail( $size );
}
}
/**
* Apply custom button class to the last menu item.
*
* Learn more: https://developer.wordpress.org/reference/hooks/walker_nav_menu_start_el/
*
* @param string $item_output The menu item's starting HTML output.
* @param object $item Menu item data object.
* @param integer $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
function fredo_apply_button_class_to_last_menu_item( $item_output, $item, $depth, $args ) {
if ( apply_filters( 'fredo_last_menu_item_name', 'buy-a-coffee' ) === $item->post_name ) {
$item_output = preg_replace( '/<a.*?>(.*)<\/a>/', '<a href="' . $item->url . '" class="button button-black" target="_blank" rel="noopener">$1</a>', $item_output );
}
return $item_output;
}
/**
* Register widget area.
*
* @link https://codex.wordpress.org/Function_Reference/register_sidebar
*/
function widgets_init() {
$sidebar_args['sidebar'] = array(
'name' => __( 'Sidebar', 'fredo' ),
'id' => 'sidebar-1',
'description' => '',
);
$sidebar_args = apply_filters( 'fredo_sidebar_args', $sidebar_args );
foreach ( $sidebar_args as $sidebar => $args ) {
$widget_tags = array(
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<span class="widget-title">',
'after_title' => '</span>',
);
}
$filter_hook = sprintf( 'fredo_%s_widget_tags', $sidebar );
$widget_tags = apply_filters( $filter_hook, $widget_tags );
if ( is_array( $widget_tags ) ) {
register_sidebar( $args + $widget_tags );
}
}
/**
* Custom function to display comments.
*
* Learn more: https://codex.wordpress.org/Function_Reference/wp_list_comments
*
* @param string $comment The comment.
* @param object $args The args.
* @param integer $depth Depth of menu item. Used for padding.
*/
function list_comments( $comment, $args, $depth ) {
if ( 'div' === $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
} ?>
<<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
<?php
if ( 'div' !== $args['style'] ) {
?>
<div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<?php } ?>
<div class="comment-author vcard">
<?php
if ( 0 !== $args['avatar_size'] ) {
echo get_avatar( $comment, $args['avatar_size'] );
}
printf( __( '<cite class="fn">%s</cite>:' ), get_comment_author_link() );
?>
</div>
<?php
if ( 0 === $comment->comment_approved ) {
?>
<em class="comment-awaiting-moderation"><?php esc_attr_e( 'Your comment is awaiting moderation.', 'fredo' ); ?></em><br/>
<?php
}
?>
<div class="comment-meta commentmetadata">
<a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf(
__('%1$s at %2$s'),
get_comment_date(),
get_comment_time()
);
?>
</a>
<?php
edit_comment_link( __( '<span class="button button-small float-right button-outline">' . __( 'Edit', 'fredo' ) . '</span>' ), ' ', '' );
?>
</div>
<?php comment_text(); ?>
<div class="reply">
<?php
comment_reply_link(
array_merge(
$args,
array(
'add_below' => $add_below,
'depth' => $depth,
'max_depth' => $args['max_depth'],
'reply_text' => '<span class="button button-small">' . __( 'Reply', 'fredo' ) . '</span>',
)
)
);
?>
</div>
<?php
if ( 'div' !== $args['style'] ) :
?>
</div>
<?php
endif;
}
/**
* Disable emojis, please.
*/
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
}
/**
* Apply button style to last menu item.
*
* @param array $items The menu item.
*/
function fredo_add_menu_class_to_last_item( $items ) {
$items[ count( $items ) ]->classes[] = 'button button-black';
return $items;
}
/**
* Display home introduction text.
*/
function fredo_home_intro() {
?>
<div class="row content">
<div class="column">
<h1><?php esc_attr_e( 'Looking for some WordPress and WooCommerce related stuff? I got you covered! I\'m Remi, nice to meet you.', 'fredo' ); ?></h1>
<p>
<?php esc_attr_e( 'Here is my blog, where I write from to time to time, where I give free snippets, where I share my skills. I work at Automattic, and guess what? We\'re hiring!', 'fredo' ); ?>
</p>
</div>
</div>
<?php
}
/**
* Promote theme.
* add remove_action( 'fredo_after_home_content', 'fredo_promote_theme_box' ); to remove this.
*/
function fredo_promote_theme_box() {
?>
<div class="row section-title">
<div class="column">
<h2><span><?php esc_attr_e( ' Like this theme?', 'fredo' ); ?></span></h2>
</div>
</div>
<div class="row theme">
<div class="column">
<span class="title"><?php esc_attr_e( 'It\'s free an open source!', 'fredo' ); ?></span>
<span class="description"><?php esc_attr_e( 'This theme is clean, fast and doesn\'t rely on any heavy technology. I wanted it to be simple to use, clearly readable and focusing on content. No need for useless stuff, visual effects, preloaders or any other fancy trendy stuff. Nobody cares about this anymore.', 'fredo' ); ?></span>
</div>
</div>
<div class="row">
<div class="column">
<span><a class="button button-outline" href="https://github.com/corsonr/fredo/archive/master.zip" target="_blank" rel="noopener"><?php esc_attr_e( 'Download', 'fredo' ); ?></a></span>
</div>
<div class="column">
<span><a class="button button-outline" href="https://github.com/corsonr/fredo/issues" target="_blank" rel="noopener"><?php esc_attr_e( 'Report a bug', 'fredo' ); ?></a></span>
</div>
<div class="column">
<span><a class="button button-outline" href="https://github.com/corsonr/fredo/blob/master/CONTRIBUTING.md" target="_blank" rel="noopener"><?php esc_attr_e( 'Contribute', 'fredo' ); ?></a></span>
</div>
<div class="column">
<span class="support"><a class="button button-outline" href="<?php echo esc_url( fredo_buy_me_a_coffee_url() ); ?>" target="_blank" rel="noopener"><?php esc_attr_e( 'Buy me a coffee', 'fredo' ); ?></a></span>
</div>
</div>
<?php
}
/**
* Buy me a coffee URL.
*/
function fredo_buy_me_a_coffee_url() {
return apply_filters( 'fredo_buy_me_a_coffee_url', 'https://www.buymeacoffee.com/u8Mr47vGJ' );
}