-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
493 lines (411 loc) · 20.3 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?php
/*
Author: Paul Grieselhuber, Eddie Machado
URL: https://sepalandseed.com/
This is where you can drop your custom functions or
just edit things like thumbnail sizes, header images,
sidebars, comments, etc.
*/
// LOAD SEPAL AND SEED CORE (if you remove this, the theme will break)
require_once( 'library/sepal-and-seed.php' );
// CUSTOMIZE THE WORDPRESS ADMIN (off by default)
// require_once( 'library/admin.php' );
/*********************
LAUNCH SEPAL AND SEED
Let's get everything up and running.
*********************/
function sepal_and_seed_ahoy() {
//Allow editor style.
add_editor_style( get_stylesheet_directory_uri() . '/library/css/editor-style.css' );
// let's get language support going, if you need it
load_theme_textdomain( 'sepalandseedtheme', get_template_directory() . '/library/translation' );
// launching operation cleanup
add_action( 'init', 'sepal_and_seed_head_cleanup' );
// remove WP version from RSS
add_filter( 'the_generator', 'sepal_and_seed_rss_version' );
// remove pesky injected css for recent comments widget
add_filter( 'wp_head', 'sepal_and_seed_remove_wp_widget_recent_comments_style', 1 );
// clean up comment styles in the head
add_action( 'wp_head', 'sepal_and_seed_remove_recent_comments_style', 1 );
// clean up gallery output in wp
add_filter( 'gallery_style', 'sepal_and_seed_gallery_style' );
// enqueue base scripts and styles
add_action( 'wp_enqueue_scripts', 'sepal_and_seed_scripts_and_styles', 999 );
// ie conditional wrapper
// launching this stuff after theme setup
sepal_and_seed_theme_support();
// adding sidebars to Wordpress (these are created in functions.php)
add_action( 'widgets_init', 'sepal_and_seed_register_sidebars' );
// cleaning up random code around images
add_filter( 'the_content', 'sepal_and_seed_filter_ptags_on_images' );
// cleaning up excerpt
add_filter( 'excerpt_more', 'sepal_and_seed_excerpt_more' );
} /* end sepal and seed ahoy */
// let's get this party started
add_action( 'after_setup_theme', 'sepal_and_seed_ahoy' );
/************* Remove emoji *************/
function disable_wp_emojicons() {
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_styles' );
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_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
// filter to remove TinyMCE emojis
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
}
add_action( 'init', 'disable_wp_emojicons' );
function disable_emojicons_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
/************* Remove embed.js *************/
function disable_embeds_init() {
// Remove the REST API endpoint.
remove_action('rest_api_init', 'wp_oembed_register_route');
// Turn off oEmbed auto discovery.
// Don't filter oEmbed results.
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
// Remove oEmbed discovery links.
remove_action('wp_head', 'wp_oembed_add_discovery_links');
// Remove oEmbed-specific JavaScript from the front-end and back-end.
remove_action('wp_head', 'wp_oembed_add_host_js');
}
add_action('init', 'disable_embeds_init', 9999);
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
/************* OEMBED SIZE OPTIONS *************/
if ( ! isset( $content_width ) ) {
$content_width = 680;
}
/************* THUMBNAIL SIZE OPTIONS *************/
// Thumbnail sizes
add_image_size( 'sepal-and-seed-thumb-600', 600, 150, true );
add_image_size( 'sepal-and-seed-thumb-300', 300, 100, true );
/************* Add Title Tag Support *************/
add_theme_support( 'title-tag' );
/*
to add more sizes, simply copy a line from above
and change the dimensions & name. As long as you
upload a "featured image" as large as the biggest
set width or height, all the other sizes will be
auto-cropped.
To call a different size, simply change the text
inside the thumbnail function.
For example, to call the 300 x 100 sized image,
we would use the function:
<?php the_post_thumbnail( 'sepal-and-seed-thumb-300' ); ?>
for the 600 x 150 image:
<?php the_post_thumbnail( 'sepal-and-seed-thumb-600' ); ?>
You can change the names and dimensions to whatever
you like. Enjoy!
*/
add_filter( 'image_size_names_choose', 'sepal_and_seed_custom_image_sizes' );
function sepal_and_seed_custom_image_sizes( $sizes ) {
return array_merge( $sizes, array(
'sepal-and-seed-thumb-600' => __('600px by 150px', 'sepalandseedtheme'),
'sepal-and-seed-thumb-300' => __('300px by 100px', 'sepalandseedtheme'),
) );
}
/*
The function above adds the ability to use the dropdown menu to select
the new images sizes you have just created from within the media manager
when you add media to your content blocks. If you add more image sizes,
duplicate one of the lines in the array and name it according to your
new image size.
*/
/************* THEME CUSTOMIZE *********************/
/*
A good tutorial for creating your own Sections, Controls and Settings:
http://code.tutsplus.com/series/a-guide-to-the-wordpress-theme-customizer--wp-33722
Good articles on modifying the default options:
http://natko.com/changing-default-wordpress-theme-customization-api-sections/
http://code.tutsplus.com/tutorials/digging-into-the-theme-customizer-components--wp-27162
To do:
- Create a js for the postmessage transport method
- Create some sanitize functions to sanitize inputs
- Create some boilerplate Sections, Controls and Settings
*/
function sepal_and_seed_theme_customizer($wp_customize) {
// $wp_customize calls go here.
//
// Uncomment the below lines to remove the default customize sections
// $wp_customize->remove_section('title_tagline');
// $wp_customize->remove_section('colors');
// $wp_customize->remove_section('background_image');
// $wp_customize->remove_section('static_front_page');
// $wp_customize->remove_section('nav');
// Uncomment the below lines to remove the default controls
// $wp_customize->remove_control('blogdescription');
// Uncomment the following to change the default section titles
// $wp_customize->get_section('colors')->title = __( 'Theme Colors' );
// $wp_customize->get_section('background_image')->title = __( 'Images' );
}
add_action( 'customize_register', 'sepal_and_seed_theme_customizer' );
/************* ACTIVE SIDEBARS ********************/
// Sidebars & Widgetizes Areas
function sepal_and_seed_register_sidebars() {
register_sidebar(array(
'id' => 'sidebar1',
'name' => __( 'Sidebar 1', 'sepalandseedtheme' ),
'description' => __( 'The first (primary) sidebar.', 'sepalandseedtheme' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
/*
to add more sidebars or widgetized areas, just copy
and edit the above sidebar code. In order to call
your new sidebar just use the following code:
Just change the name to whatever your new
sidebar's id is, for example:
register_sidebar(array(
'id' => 'sidebar2',
'name' => __( 'Sidebar 2', 'sepalandseedtheme' ),
'description' => __( 'The second (secondary) sidebar.', 'sepalandseedtheme' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
To call the sidebar in your template, you can just copy
the sidebar.php file and rename it to your sidebar's name.
So using the above example, it would be:
sidebar-sidebar2.php
*/
} // don't remove this bracket!
/************* COMMENT LAYOUT *********************/
// Comment Layout
function sepal_and_seed_comments( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment; ?>
<div id="comment-<?php comment_ID(); ?>" <?php comment_class('cf'); ?>>
<article class="cf">
<header class="comment-author vcard">
<?php
/*
this is the new responsive optimized comment image. It used the new HTML5 data-attribute to display comment gravatars on larger screens only. What this means is that on larger posts, mobile sites don't have a ton of requests for comment images. This makes load time incredibly fast! If you'd like to change it back, just replace it with the regular wordpress gravatar call:
echo get_avatar($comment,$size='32',$default='<path_to_url>' );
*/
?>
<?php printf(__( '<cite class="fn">%1$s</cite> %2$s', 'sepalandseedtheme' ), get_comment_author_link(), edit_comment_link(__( '(Edit)', 'sepalandseedtheme' ),' ','') ) ?>
<time datetime="<?php echo comment_time('Y-m-j'); ?>"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php comment_time(__( 'F jS, Y', 'sepalandseedtheme' )); ?> </a></time>
</header>
<?php if ($comment->comment_approved == '0') : ?>
<div class="alert alert-info">
<p><?php _e( 'Your comment is awaiting moderation.', 'sepalandseedtheme' ) ?></p>
</div>
<?php endif; ?>
<section class="comment_content cf">
<?php comment_text() ?>
</section>
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</article>
<?php // </li> is added by WordPress automatically ?>
<?php
} // don't remove this bracket!
// LOAD TGM
require_once( 'library/class-tgm-plugin-activation.php' );
add_action( 'tgmpa_register', 'tww_register_required_plugins' );
function tww_register_required_plugins() {
/*
* Array of plugin arrays. Required keys are name and slug.
* If the source is NOT from the .org repo, then source is also required.
*/
$plugins = array(
// This is an example of how to include a plugin bundled with a theme.
// array(
// 'name' => 'TGM Example Plugin', // The plugin name.
// 'slug' => 'tgm-example-plugin', // The plugin slug (typically the folder name).
// 'source' => get_template_directory() . '/lib/plugins/tgm-example-plugin.zip', // The plugin source.
// 'required' => true, // If false, the plugin is only 'recommended' instead of required.
// 'version' => '', // E.g. 1.0.0. If set, the active plugin must be this version or higher. If the plugin version is higher than the plugin version installed, the user will be notified to update the plugin.
// 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
// 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
// 'external_url' => '', // If set, overrides default API URL and points to an external URL.
// 'is_callable' => '', // If set, this callable will be be checked for availability to determine if a plugin is active.
// ),
// This is an example of how to include a plugin from an arbitrary external source in your theme.
// array(
// 'name' => 'TGM New Media Plugin', // The plugin name.
// 'slug' => 'tgm-new-media-plugin', // The plugin slug (typically the folder name).
// 'source' => 'https://s3.amazonaws.com/tgm/tgm-new-media-plugin.zip', // The plugin source.
// 'required' => true, // If false, the plugin is only 'recommended' instead of required.
// 'external_url' => 'https://github.com/thomasgriffin/New-Media-Image-Uploader', // If set, overrides default API URL and points to an external URL.
// ),
// This is an example of how to include a plugin from a GitHub repository in your theme.
// This presumes that the plugin code is based in the root of the GitHub repository
// and not in a subdirectory ('/src') of the repository.
// array(
// 'name' => 'Adminbar Link Comments to Pending',
// 'slug' => 'adminbar-link-comments-to-pending',
// 'source' => 'https://github.com/jrfnl/WP-adminbar-comments-to-pending/archive/master.zip',
// ),
// This is an example of how to include a plugin from the WordPress Plugin Repository.
array(
'name' => '(GA) Google Analytics',
'slug' => 'ga-google-analytics',
'required' => true,
),
// This is an example of the use of 'is_callable' functionality. A user could - for instance -
// have WPSEO installed *or* WPSEO Premium. The slug would in that last case be different, i.e.
// 'wordpress-seo-premium'.
// By setting 'is_callable' to either a function from that plugin or a class method
// `array( 'class', 'method' )` similar to how you hook in to actions and filters, TGMPA can still
// recognize the plugin as being installed.
array(
'name' => 'WordPress SEO by Yoast',
'slug' => 'wordpress-seo',
'is_callable' => 'wpseo_init',
),
);
/*
* Array of configuration settings. Amend each line as needed.
*
* TGMPA will start providing localized text strings soon. If you already have translations of our standard
* strings available, please help us make TGMPA even better by giving us access to these translations or by
* sending in a pull-request with .po file(s) with the translations.
*
* Only uncomment the strings in the config array if you want to customize the strings.
*/
$config = array(
'id' => 'tww', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'dismissable' => false, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
/*
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'tww' ),
'menu_title' => __( 'Install Plugins', 'tww' ),
/* translators: %s: plugin name. * /
'installing' => __( 'Installing Plugin: %s', 'tww' ),
/* translators: %s: plugin name. * /
'updating' => __( 'Updating Plugin: %s', 'tww' ),
'oops' => __( 'Something went wrong with the plugin API.', 'tww' ),
'notice_can_install_required' => _n_noop(
/* translators: 1: plugin name(s). * /
'This theme requires the following plugin: %1$s.',
'This theme requires the following plugins: %1$s.',
'tww'
),
'notice_can_install_recommended' => _n_noop(
/* translators: 1: plugin name(s). * /
'This theme recommends the following plugin: %1$s.',
'This theme recommends the following plugins: %1$s.',
'tww'
),
'notice_ask_to_update' => _n_noop(
/* translators: 1: plugin name(s). * /
'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.',
'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.',
'tww'
),
'notice_ask_to_update_maybe' => _n_noop(
/* translators: 1: plugin name(s). * /
'There is an update available for: %1$s.',
'There are updates available for the following plugins: %1$s.',
'tww'
),
'notice_can_activate_required' => _n_noop(
/* translators: 1: plugin name(s). * /
'The following required plugin is currently inactive: %1$s.',
'The following required plugins are currently inactive: %1$s.',
'tww'
),
'notice_can_activate_recommended' => _n_noop(
/* translators: 1: plugin name(s). * /
'The following recommended plugin is currently inactive: %1$s.',
'The following recommended plugins are currently inactive: %1$s.',
'tww'
),
'install_link' => _n_noop(
'Begin installing plugin',
'Begin installing plugins',
'tww'
),
'update_link' => _n_noop(
'Begin updating plugin',
'Begin updating plugins',
'tww'
),
'activate_link' => _n_noop(
'Begin activating plugin',
'Begin activating plugins',
'tww'
),
'return' => __( 'Return to Required Plugins Installer', 'tww' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'tww' ),
'activated_successfully' => __( 'The following plugin was activated successfully:', 'tww' ),
/* translators: 1: plugin name. * /
'plugin_already_active' => __( 'No action taken. Plugin %1$s was already active.', 'tww' ),
/* translators: 1: plugin name. * /
'plugin_needs_higher_version' => __( 'Plugin not activated. A higher version of %s is needed for this theme. Please update the plugin.', 'tww' ),
/* translators: 1: dashboard link. * /
'complete' => __( 'All plugins installed and activated successfully. %1$s', 'tww' ),
'dismiss' => __( 'Dismiss this notice', 'tww' ),
'notice_cannot_install_activate' => __( 'There are one or more required or recommended plugins to install, update or activate.', 'tww' ),
'contact_admin' => __( 'Please contact the administrator of this site for help.', 'tww' ),
'nag_type' => '', // Determines admin notice type - can only be one of the typical WP notice classes, such as 'updated', 'update-nag', 'notice-warning', 'notice-info' or 'error'. Some of which may not work as expected in older WP versions.
),
*/
);
tgmpa( $plugins, $config );
}
/*
This is a modification of a function found in the
twentythirteen theme where we can declare some
external fonts. If you're using Google Fonts, you
can replace these fonts, change it in your scss files
and be up and running in seconds.
*/
function sepal_and_seed_fonts() {
wp_enqueue_style('googleFonts', '//fonts.googleapis.com/css?family=Montserrat:700|Open+Sans');
}
add_action('wp_enqueue_scripts', 'sepal_and_seed_fonts');
// Add manual excerpt back to wp-admin default view
add_filter('default_hidden_meta_boxes', 'be_hidden_meta_boxes', 10, 2);
function be_hidden_meta_boxes($hidden, $screen) {
if ( 'post' == $screen->base || 'page' == $screen->base ) {
// removed 'postcustom',
$hidden = array(
'slugdiv',
'trackbacksdiv',
'postexcerpt',
'commentstatusdiv',
'commentsdiv',
'authordiv',
'revisionsdiv'
);
}
return $hidden;
}
// LOAD Custom Recent Posts Widget
require_once( 'library/class-custom-recent-posts-widget.php' );
add_action( 'widgets_init', create_function( '', 'register_widget( "Custom_Widget_Recent_Posts" );' ) );
/************* Remove comment reply.js *************/
function clean_header(){
wp_deregister_script( 'comment-reply' );
}
add_action('init','clean_header');
/************* Remove jQuery *************/
function wpdocs_dequeue_script() {
if ( !is_admin() ) wp_deregister_script('jquery');
}
add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );
/* DON'T DELETE THIS CLOSING TAG */ ?>