-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfunctions.php
400 lines (314 loc) · 13.5 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
<?php
/**
* Ignition functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
* @package Ignition
* @since 1.0
*
* The first file to look at is theme.config.json where you can quickly set up some theme settings
* like google fonts, icons for various areas and logo position
* you can also set the mobile menu by editing the mobile_menu_type option to open as app-menu or leave blank to open regular
* default_acf_header_block: add your post types here to force them to have a header block when a new post is made.
*
* Then you should set your CSS variables in variables.scss
*
* Once those are both edited, you can come here and add image sizes, widgets and anything else
* Remember it might not be necessary to enqueue js files here as any js file starting with an underscore will be added automatically to the front end js build
* That will work only if the file is inside the inc or parts folders.
* This ability also works for any scss file added with an underscore in those folders too.
* This also works for underscored php files.
* therefore all php files in the inc folder are already automatically included
*
* Besides adding image sizes, you may find you dont have to do much in here.
*/
/**
* Ignition only works in WordPress 5.5 or later. Here we check before allowing the theme to be used.
* There is nothing here for you to do.
*/
if ( version_compare( $GLOBALS['wp_version'], '5.5', '<' ) ) {
require get_template_directory() . '/inc/core/back-compat.php';
return;
}
/*--------------------------------------------------------------
# Check theme.config.json and make changes as needed.
--------------------------------------------------------------*/
/*--------------------------------------------------------------
# Setup
--------------------------------------------------------------*/
/**
* This sets up theme defaults and registers support for various WordPress features.
* Runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
* Here is where you can start changing settings.
* you can also add google fonts and a submenu arrow via the ign_config variable below
*/
function ignition_setup() {
/*
* Make theme available for translation.
* Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/ignition
* If you're building a theme based on Ignition, and you downloaded this from github, use a find and replace
* to change 'ignition' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'ignition' );
/*
* Enable support for Post Thumbnails on posts and pages.
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
add_post_type_support( 'page', 'excerpt' );
/**
* default image size for cards and thumbnails and header images
* Users should upload twice the size of an image size.
* So if the image size is 600 x 600, the user should upload a 1200 by 1200.
* Output the image size and WP will automatically include the full size for big display when needed.
*
* WP is also smart and if you set crop to true it will include the original only if it matches in ratio
* Header image size is included for large header images. Users dont have to upload twice that size unless your ok with large files.
*
* Recommend installing imsanity so users can't upload extremely huge images without them being compressed and resized.
*/
set_post_thumbnail_size( 300, 300, true );
add_image_size( 'header_image', 2000, 9999 );
add_filter( 'intermediate_image_sizes_advanced', 'remove_default_images' );
/*
* Add menus here
*/
register_nav_menus( array(
'top-menu' => __( 'Top Menu', 'ignition' ), //main menu at top.
) );
/*
* Enable support for Post Formats.
* Uncomment if you want to use this feauture
* See: https://codex.wordpress.org/Post_Formats
*/
// add_theme_support( 'post-formats', array(
// 'aside',
// 'image',
// 'video',
// 'quote',
// 'link',
// 'gallery',
// 'audio',
// ) );
// add_post_type_support( 'post', 'post-formats' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
//Adds Gutenberg Support
add_theme_support( 'align-wide' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Add theme support for Custom Logo.
add_theme_support( 'custom-logo', array(
'width' => 400,
'height' => 250,
'flex-width' => true,
'flex-height' => true
) );
// Add theme support for selective refresh for widgets in customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
add_theme_support( 'custom-header' );
/*
* tinymce styles
*/
add_editor_style( array(
get_template_directory_uri() . '/dist/frontEnd.css?' . wp_get_theme()->get( 'Version' ),
ign_google_fonts_url()
) );
$GLOBALS['content_width'] = 730;
}
add_action( 'after_setup_theme', 'ignition_setup' );
/*--------------------------------------------------------------
# ADMIN ACCESS AND ADMIN BAR VISIBILITY
--------------------------------------------------------------*/
/**
* Disable admin bar for everyone but administrators
* You can change this based on capabilities. By default manage_options is used to check for Administrators
*/
if ( ! function_exists( 'disable_admin_bar' ) ) {
function disable_admin_bar() {
if ( ! current_user_can( ign_get_config( 'admin_access_capability', 'manage_options' ) ) ) {
add_filter( 'show_admin_bar', '__return_false' );
}
}
}
add_action( 'after_setup_theme', 'disable_admin_bar' );
/**
* Redirect back to homepage and not allow access to WP Admin.
*/
if ( ! function_exists( 'redirect_admin' ) ) {
function redirect_admin() {
if ( ! current_user_can( ign_get_config( 'admin_access_capability', 'manage_options' ) ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
}
add_action( 'admin_init', 'redirect_admin' );
/*--------------------------------------------------------------
# Scripts and Styles
--------------------------------------------------------------*/
/**
* Enqueue all scripts and styles.
* Add your own scripts and styles below.
*/
function ignition_scripts() {
global $wp;
// Add google fonts
if ( ign_get_config( 'google_fonts' ) ) {
wp_enqueue_style( 'ignition-fonts', ign_google_fonts_url(), array(), wp_get_theme()->get( 'Version' ) );
}
// Theme stylesheet. Will get this stylesheet or a child themes stylesheet.
wp_enqueue_style( 'ignition-style', get_stylesheet_uri(), '', wp_get_theme()->get( 'Version' ) );
//Sass compiles styles. Will get child's theme version if found instead. Child theme should import with sass.
wp_enqueue_style( 'ignition-sass-styles', get_theme_file_uri( '/dist/frontEnd.css' ), '', wp_get_theme()->get( 'Version' ) );
wp_enqueue_script( 'iconify', 'https://code.iconify.design/1/1.0.6/iconify.min.js' );
//ie11 js polyfills
wp_enqueue_script( 'polyfill', 'https://polyfill.io/v3/polyfill.min.js?flags=gated&features=AbortController%2Cdefault%2CNodeList.prototype.forEach%2CEvent%2Csmoothscroll' );
//jQuery 3.0 replaces WP jquery
wp_deregister_script( 'jquery-core' );
wp_register_script( 'jquery-core', "https://code.jquery.com/jquery-3.5.1.min.js", array(), '3.5.1' );
wp_deregister_script( 'jquery-migrate' );
wp_register_script( 'jquery-migrate', "https://code.jquery.com/jquery-migrate-3.3.0.min.js", array( 'jquery-core' ), '3.3.0' );
//any javascript file in assets/js that ends with custom.js will be lumped into this file.
wp_enqueue_script( 'ignition-custom-js', get_template_directory_uri() . '/dist/frontEnd_bundle.js', array(
'jquery',
'polyfill'
),
wp_get_theme()->get( 'Version' ), true );
//AJAX ready for .custom.js files
wp_localize_script( 'ignition-custom-js', 'frontEndAjax', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax_nonce' ),
'url' => home_url(),
'currentUrl' => home_url( $wp->request )
) );
//Icons: add icons for use in custom js here
wp_localize_script( 'ignition-custom-js', 'icons', array(
'angleRight' => ign_get_svg( array( 'icon' => 'angle-right' ) ),
'sidebar' => ign_get_svg( array( 'icon' => 'sidebar' ) )
) );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
//add your styles and scripts here
}
add_action( 'wp_enqueue_scripts', 'ignition_scripts' );
/*
* Add Stylesheet for Gutenberg
*/
function ign_gutenberg_styles() {
//load regular versions if script debug is set to true in wp-config file.
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
// Load the theme styles within Gutenberg.
wp_enqueue_style( 'ign-gutenberg-style', get_theme_file_uri( '/dist/gutenberg-editor-style' . $suffix . '.css' ), false, wp_get_theme()->get( 'Version' ), 'all' );
wp_enqueue_script( 'ignition-custom-js', get_template_directory_uri() . '/dist/custom' . $suffix . '.js', array( 'jquery' ),
wp_get_theme()->get( 'Version' ), true );
}
//add_action( 'enqueue_block_editor_assets', 'ign_gutenberg_styles' ); //todo remove if already adding admin-css?
/**
* Add login stylehseet
*/
function login_styles() {
wp_enqueue_style( 'custom-admin', get_stylesheet_directory_uri() . '/dist/login.css', '', wp_get_theme()->get( 'Version' ) );
}
add_action( 'login_enqueue_scripts', 'login_styles' );
/**
* Add admin stylesheet
*/
function footer_styles() {
//load regular versions if script debug is set to true in wp-config file.
//$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_script( 'iconify', 'https://code.iconify.design/1/1.0.6/iconify.min.js' );
wp_enqueue_style( 'ignition-admin-styles', get_theme_file_uri( '/dist/backEnd.css' ), '', wp_get_theme()->get( 'Version' ) );
}
add_action( 'admin_footer', 'footer_styles', 99 );
/**
* Register widget areas.
* Change/Remove widget areas here. By default the widget areas are the sidebar and the footer which has 4 widget areas being output in columns.
* See template-parts/footer/footer-widgets.php
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
if ( ! function_exists( 'ign_widgets_init' ) ) {
function ign_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'ignition' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'ignition' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
//footer widgets and sections. up to 4
register_sidebar( array(
'name' => esc_html__( 'Footer', 'ignition' ),
'id' => 'sidebar-2',
'description' => esc_html__( 'Add footer widgets here.', 'pwm' ),
'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 2', 'ignition' ),
'id' => 'sidebar-3',
'description' => esc_html__( 'Add footer widgets here.', 'pwm' ),
'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 3', 'ignition' ),
'id' => 'sidebar-4',
'description' => esc_html__( 'Add footer widgets here.', 'pwm' ),
'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 4', 'ignition' ),
'id' => 'sidebar-5',
'description' => esc_html__( 'Add footer widgets here.', 'pwm' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
}
add_action( 'widgets_init', 'ign_widgets_init' );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function ignition_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
add_action( 'wp_head', 'ignition_pingback_header' );
/*--------------------------------------------------------------
# Adding More PHP Files Automatically
--------------------------------------------------------------*/
require_once get_parent_theme_file_path( '/inc/core/dev-helpers.php' );
//no need to include php files, just add them to the inc folder and start them with an underscore. Ignition takes care of the rest!
//Ignition will also search two directories deep for more underscored files within inc, blocks, and post-types folders.
// (ie: inc/acf-extras/_acf-extras.php )