forked from argoproject/Argo
-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
functions.php
486 lines (423 loc) · 13 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
<?php
/**
* Largo functions and definitions
*
* When using a child theme (see https://codex.wordpress.org/Theme_Development and
* https://codex.wordpress.org/Child_Themes), you can override certain functions
* (those wrapped in a function_exists() call) by defining them first in your child theme's
* functions.php file. The child theme's functions.php file is included before the parent
* theme's file, so the child theme functions would be used.
*
* Functions that are not pluggable (not wrapped in function_exists()) are instead attached
* to a filter or action hook. The hook can be removed by using remove_action() or
* remove_filter() and you can attach your own function to the hook.
*
* We can remove the parent theme's hook only after it is attached, which means we need to
* wait until setting up the child theme:
*
* <code>
* add_action( 'after_setup_theme', 'my_child_theme_setup' );
* function my_child_theme_setup() {
* // We are providing our own filter for excerpt_length (or using the unfiltered value)
* remove_filter( 'excerpt_length', 'eleven_excerpt_length' );
* ...
* }
* </code>
*
* For more information on hooks, actions, and filters, see https://codex.wordpress.org/Plugin_API.
*
* @package Largo
*/
/**
* By default we'll assume the site is not hosted by WPB.
*
* There should be no reason to set this.
*/
if ( ! defined( 'WPB_HOSTED' ) )
define( 'WPB_HOSTED', FALSE );
/**
* LARGO_DEBUG defines whether or not to use minified assets
*
* Largo by default uses minified CSS and JavaScript files.
* set LARGO_DEBUG to TRUE to use unminified JavaScript files
* and unminified CSS files with sourcemaps to our LESS files.
*
* @since 0.5
*/
if ( ! defined( 'LARGO_DEBUG' ) )
define( 'LARGO_DEBUG', FALSE );
/**
* Image size constants, almost 100% that you won't need to change these
*/
if ( ! defined( 'FULL_WIDTH' ) ) {
define( 'FULL_WIDTH', 1170 );
}
if ( ! defined( 'LARGE_WIDTH' ) ) {
define( 'LARGE_WIDTH', 771 );
}
if ( ! defined( 'MEDIUM_WIDTH' ) ) {
define( 'MEDIUM_WIDTH', 336 );
}
if ( ! defined( 'FULL_HEIGHT' ) ) {
define( 'FULL_HEIGHT', 9999 );
}
if ( ! defined( 'LARGE_HEIGHT' ) ) {
define( 'LARGE_HEIGHT', 9999 );
}
if ( ! defined( 'MEDIUM_HEIGHT' ) ) {
define( 'MEDIUM_HEIGHT', 9999 );
}
if ( ! isset( $content_width ) )
/**
* Set the content width based on the theme's design and stylesheet.
*
* @ignore
*/
$content_width = 771;
if ( ! isset( $largo ) )
/*
* Set the global $largo var
*
* @ignore
*/
$largo = array();
/*
* load the options framework (used for our theme options pages)
*
* @ignore
*/
if ( ! function_exists( 'optionsframework_init' ) ) {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/lib/options-framework/' );
if ( 0 == validate_file( '/lib/options-framework/options-framework.php' ) ) {
require_once get_template_directory() . '/lib/options-framework/options-framework.php';
}
}
/**
* A class to represent the one true Largo theme instance
*/
class Largo {
private static $instance;
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new Largo;
self::$instance->load();
}
return self::$instance;
}
/**
* Load the theme
*/
private function load() {
$this->require_files();
$this->register_nav_menus();
$this->register_media_sizes();
$this->template_constants();
$this->customizer = Largo_Customizer::get_instance();
}
/**
* Load required files
*/
private function require_files() {
// @todo: is there a reason this is not sorted?
$includes = array(
'/largo-apis.php',
'/inc/ajax-functions.php',
'/inc/helpers.php',
'/inc/dashboard.php',
'/inc/custom-feeds.php',
'/inc/users.php',
'/inc/term-meta.php',
'/inc/sidebars.php',
'/inc/customizer/customizer.php',
'/inc/widgets.php',
'/inc/nav-menus.php',
'/inc/taxonomies.php',
'/inc/term-icons.php',
'/inc/term-sidebars.php',
'/inc/images.php',
'/inc/editor.php',
'/inc/post-metaboxes.php',
'/inc/open-graph.php',
'/inc/verify.php',
'/inc/post-tags.php',
'/inc/byline_class.php',
'/inc/header-footer.php',
'/inc/related-content.php',
'/inc/featured-content.php',
'/inc/enqueue.php',
'/inc/post-social.php',
'/inc/post-templates.php',
'/inc/home-templates.php',
'/inc/update.php',
'/inc/avatars.php',
'/inc/featured-media.php',
'/inc/deprecated.php',
'/inc/pagination.php',
'/inc/conditionals.php',
'/inc/gutenberg-block-edits.php',
);
if ( $this->is_less_enabled() ) {
$includes[] = '/inc/custom-less-variables.php';
}
// If the plugin is already active, don't cause fatals
if ( ! class_exists( 'Navis_Media_Credit' ) ) {
$includes[] = '/lib/navis-media-credit/navis-media-credit.php';
}
if ( ! class_exists( 'Navis_Slideshows' ) ) {
$includes[] = '/lib/navis-slideshows/navis-slideshows.php';
}
if ( ! function_exists( 'clean_contact_func' ) ) {
$includes[] = '/lib/clean-contact/clean_contact.php';
}
foreach ( $includes as $include ) {
if ( 0 === validate_file( $include ) ) {
require_once( get_template_directory() . $include );
}
}
}
/**
* Register the nav menus for the theme
*/
private function register_nav_menus() {
$menus = array(
'global-nav' => __( 'Global Navigation', 'largo' ),
'main-nav' => __( 'Main Navigation', 'largo' ),
'dont-miss' => __( 'Don\'t Miss', 'largo' ),
'footer' => __( 'Footer Navigation', 'largo' ),
'footer-bottom' => __( 'Footer Bottom', 'largo' )
);
register_nav_menus( $menus );
// Avoid database writes on the frontend
if ( ! is_admin() ) {
return;
}
//Try to automatically link menus to each of the locations.
foreach ( $menus as $location => $label ) {
// if a location isn't wired up...
if ( ! has_nav_menu( $location ) ) {
// get or create the nav menu
$nav_menu = wp_get_nav_menu_object( $label );
if ( ! $nav_menu ) {
$new_menu_id = wp_create_nav_menu( $label );
$nav_menu = wp_get_nav_menu_object( $new_menu_id );
}
// wire it up to the location
$locations = get_theme_mod( 'nav_menu_locations' );
$locations[ $location ] = $nav_menu->term_id;
set_theme_mod( 'nav_menu_locations', $locations );
}
}
}
/**
* Register image and media sizes associated with the theme
*/
private function register_media_sizes() {
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 140, 140, true ); // thumbnail
add_image_size( '60x60', 60, 60, true ); // small thumbnail
add_image_size( '96x96', 96, 96, true ); // avatars
add_image_size( 'medium', MEDIUM_WIDTH, MEDIUM_HEIGHT ); // medium width scaling
add_image_size( 'large', LARGE_WIDTH, LARGE_HEIGHT ); // large width scaling
add_image_size( 'full', FULL_WIDTH, FULL_HEIGHT ); // full width scaling
add_image_size( 'third-full', FULL_WIDTH / 3, 500, true ); // large width scaling
add_image_size( 'two-third-full', FULL_WIDTH / 3 * 2, 500, true ); // large width scaling
add_image_size( 'rect_thumb', 800, 600, true ); // used for cat/tax archive pages
add_image_size( 'rect_thumb_half', 400, 300, true ); // smaller version of rect_thumb
add_filter( 'pre_option_thumbnail_size_w', function(){
return 140;
});
add_filter( 'pre_option_thumbnail_size_h', function(){
return 140;
});
add_filter( 'pre_option_thumbnail_crop', '__return_true' );
add_filter( 'pre_option_medium_size_w', function(){
return MEDIUM_WIDTH;
});
add_filter( 'pre_option_medium_size_h', function(){
return 9999;
});
add_filter( 'pre_option_large_size_w', function(){
return LARGE_WIDTH;
});
add_filter( 'pre_option_large_size_h', function(){
return 9999;
});
add_filter( 'pre_option_embed_autourls', '__return_true' );
add_filter( 'pre_option_embed_size_w', function(){
return LARGE_WIDTH;
});
add_filter( 'pre_option_embed_size_h', function(){
return 9999;
});
}
/**
* Template display constants, you can override these in your child theme's
* functions.php by doing something like:
* define( 'SHOW_GLOBAL_NAV', FALSE );
*/
private function template_constants() {
/* Navigation */
if ( ! defined( 'SHOW_GLOBAL_NAV' ) ) {
define( 'SHOW_GLOBAL_NAV', TRUE );
}
/*
* SHOW_STICKY_NAV is deprecated.
* @link https://github.com/INN/Largo/issues/1135
* @since 0.5.5
*/
if ( ! defined( 'SHOW_STICKY_NAV' ) ) {
define( 'SHOW_STICKY_NAV', FALSE );
}
if ( ! defined( 'SHOW_MAIN_NAV' ) ) {
define( 'SHOW_MAIN_NAV', TRUE );
}
if ( ! defined( 'SHOW_SECONDARY_NAV' ) ) {
if ( of_get_option( 'show_dont_miss_menu' ) ) {
define( 'SHOW_SECONDARY_NAV', TRUE );
} else {
define( 'SHOW_SECONDARY_NAV', FALSE );
}
}
/* Category */
if ( ! defined( 'SHOW_CATEGORY_RELATED_TOPICS' ) ) {
define( 'SHOW_CATEGORY_RELATED_TOPICS', TRUE );
}
}
/**
* Is the LESS feature enabled?
*/
public function is_less_enabled() {
return (bool) of_get_option( 'less_enabled' );
}
/**
* Is a given plugin active?
*
* @param string $plugin_slug
* @return bool
*/
public function is_plugin_active( $plugin_slug ) {
switch ( $plugin_slug ) {
case 'co-authors-plus':
return (bool) class_exists( 'coauthors_plus' );
default:
return false;
}
}
}
/**
* Load the theme
*
* @ignore
*/
function Largo() {
return Largo::get_instance();
}
add_action( 'after_setup_theme', 'Largo' );
/**
* Prints an admin warning if php is out of date.
*/
function largo_php_warning() {
$minver = "5.3.0";
$curver = phpversion();
if ( current_user_can('update_themes') && version_compare( $curver, $minver, "<" ) ) {
echo "<div class='update-nag'>";
printf(
// translators: %1$s and %2$s are PHP version numbers.
esc_html__( 'Largo requires <b>PHP %1$s</b>. Your server runs <b>$curver</b>. Please upgrade your version of php.', 'largo'),
$minver,
$curver
);
echo "</div>";
}
}
add_action( 'admin_notices', 'largo_php_warning' );
/*
* Load up all of the other goodies from the /inc directory
*/
$includes = array();
/*
* This functionality is probably not for everyone so we'll make it easy to turn it on or off
*/
if ( of_get_option( 'custom_landing_enabled' ) && of_get_option( 'series_enabled' ) ) {
$includes[] = '/inc/wp-taxonomy-landing/taxonomy-landing.php'; // adds taxonomy landing plugin
}
/*
* Perform load
*/
foreach ( $includes as $include ) {
if ( 0 === validate_file( $include ) ) {
require_once( get_template_directory() . $include );
}
}
if ( ! function_exists( 'largo_setup' ) ) {
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* To override largo_setup() in a child theme, add your own largo_setup() to your child theme's
* functions.php file.
*/
function largo_setup() {
$suffix = ( LARGO_DEBUG ) ? '' : '.min';
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style('/css/editor-style' . $suffix . '.css');
// Add default posts and comments RSS feed links to <head>.
add_theme_support( 'automatic-feed-links' );
// Add support for localization (this is a work in progress)
load_theme_textdomain('largo', get_template_directory() . '/lang');
//Add support for <title> tags
add_theme_support( 'title-tag' );
// Gutenberg alignment classes
add_theme_support( 'align-wide' );
// Gutenberg-derived responsive embedding
// https://github.com/INN/largo/issues/1688
add_theme_support( 'responsive-embeds' );
// Gutenberg support for editor styles; @link https://github.com/WordPress/gutenberg/pull/9008
add_theme_support( 'editor-styles' );
add_editor_style('/css/gutenberg' . $suffix . '.css');
}
}
add_action( 'after_setup_theme', 'largo_setup' );
if ( ! function_exists( 'of_set_option' ) ) {
/**
* Helper for setting specific theme options (optionsframework).
*
* Would be nice if optionsframework included this natively
* See https://github.com/devinsays/options-framework-plugin/issues/167
*/
function of_set_option( $option_name, $option_value ) {
$config = get_option( 'optionsframework' );
if ( ! isset( $config['id'] ) ) {
return false;
}
$options = get_option( $config['id'] );
if ( $options ) {
$options[$option_name] = $option_value;
return update_option( $config['id'], $options );
}
return false;
}
}
/**
* Gallery Default Settings
* Adds a '0' option for gallery columns
*/
add_action( 'wp_enqueue_media', 'gallery_zero_columns' );
function gallery_zero_columns() {
$columns_src = get_template_directory_uri() . '/lib/navis-slideshows/js/navis-columns.js';
wp_enqueue_script( 'navis-columns', $columns_src, array( 'jquery' ), '1.0', true );
}
/**
* Gallery Default Settings
* @param Array $settings
* @return Array $settings
*/
function theme_gallery_defaults( $settings ) {
// Sets default column setting to 0
$settings['galleryDefaults']['columns'] = 0;
return $settings;
}
add_filter( 'media_view_settings', 'theme_gallery_defaults' );