-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathfunctions.php
402 lines (383 loc) · 15.8 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
<?php
/**
* Decode functions and definitions
*
* @package Decode
*/
if ( ! function_exists( 'decode_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 for post thumbnails.
*/
function decode_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
*/
load_theme_textdomain( 'decode', get_template_directory() . '/languages' );
// Register all three menus.
$args = array(
'header-menu' => __( 'Header Menu', 'decode' ),
'sidebar-menu' => __( 'Sidebar Menu', 'decode' ),
'footer-menu' => __( 'Footer Menu', 'decode' )
);
$args = apply_filters( 'decode_register_nav_menus_args', $args );
register_nav_menus( $args );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* 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' );
/**
* Add theme support for Jetpack Site Logo.
*
* @link http://jetpack.me/support/site-logo/
*/
$args = array(
'header-text' => array(
'site-title',
'site-description',
),
'size' => 'full'
);
$args = apply_filters( 'decode_site_logo_args', $args );
add_theme_support( 'site-logo', $args );
// Set up the WordPress core custom header feature.
$args = array(
'default-image' => '',
'flex-width' => true,
'height' => 300,
'flex-height' => true,
'header-text' => false,
'admin-head-callback' => 'decode_admin_header_style', // @todo: Remove this function when WordPress 4.3 is released
'admin-preview-callback' => 'decode_admin_header_image', // @todo: Remove this function when WordPress 4.3 is released
);
$args = apply_filters( 'decode_custom_header_args', $args );
add_theme_support( 'custom-header', $args );
// Set up the WordPress core custom background feature.
$args = array(
'default-color' => 'E9EBED',
);
$args = apply_filters( 'decode_custom_background_args', $args );
add_theme_support( 'custom-background', $args );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
$args = array(
'widgets',
'caption',
'comment-form',
'comment-list',
'gallery',
'search-form',
);
$args = apply_filters( 'decode_html5_args', $args );
add_theme_support( 'html5', $args );
/**
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
/**
* Enable support for Post Formats.
* @link https://codex.wordpress.org/Post_Formats
*/
$args = array(
'aside',
'image',
'video',
'quote',
'link',
);
$args = apply_filters( 'decode_post_formats_args', $args );
add_theme_support( 'post-formats', $args );
// Add Image Size
add_image_size( 'decode-pro-related-posts', 203, 150, true );
}
endif; // decode_setup
add_action( 'after_setup_theme', 'decode_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function decode_content_width() {
$GLOBALS['content_width'] = apply_filters( 'decode_content_width', 792 );
}
add_action( 'after_setup_theme', 'decode_content_width', 0 );
/*
* Register styles and scripts.
*/
if ( ! is_admin() && ! function_exists( 'decode_scripts' ) ) {
function decode_scripts() {
wp_enqueue_style( 'decode-icomoon', get_template_directory_uri().'/assets/icomoon.css', array(), '3.0.7' );
wp_enqueue_style( 'decode-style', get_stylesheet_uri(), array(), '3.0.7' );
if ( get_theme_mod( 'latin_extended_font', false ) == true ) {
wp_enqueue_style( 'decode-font-stylesheet', '//fonts.googleapis.com/css?family=Oxygen&subset=latin-ext' );
}
else {
wp_enqueue_style( 'decode-font-stylesheet', '//fonts.googleapis.com/css?family=Oxygen' );
}
wp_enqueue_script( 'decode-scripts', get_template_directory_uri() . '/scripts/decode.js', array(), '3.0.9', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'decode-keyboard-image-navigation', get_template_directory_uri() . '/scripts/keyboard-image-navigation.js', array( 'jquery' ), '2.7.5', true );
}
}
}
add_action( 'wp_enqueue_scripts', 'decode_scripts' );
/**
* Register widgetized area and update sidebar with default widgets.
*
* @link https://codex.wordpress.org/Function_Reference/register_sidebar
*/
if ( ! function_exists( 'decode_widgets_init' ) ) {
function decode_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'decode' ),
'id' => 'sidebar-1',
'description' => _x( 'Only displayed if sidebar remains enabled in the Customize menu.', 'sidebar description', 'decode' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
) );
}
}
add_action( 'widgets_init', 'decode_widgets_init' );
/*
* Add Custom CSS to page.
*/
if ( ! is_admin() && ! function_exists( 'decode_custom_css' ) ) {
function decode_custom_css() {
if ( get_theme_mod( 'custom_css', '' ) !== '' ) { ?>
<!-- Decode Custom CSS -->
<style type="text/css">
<?php echo get_theme_mod( 'custom_css', '' ); ?>
</style>
<?php }
}
}
add_action( 'wp_head', 'decode_custom_css', 11 ); // Priority of 11 will cause this to appear after the custom colors CSS.
/**
* TGM Plugin Activation
*/
require get_template_directory() . '/inc/tgm-plugin-activation/tgm-plugin-activation.php';
/*
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/*
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/*
* Customize custom controls.
*/
require get_template_directory() . '/inc/custom-controls.php';
/*
* Customize Menu additions.
*/
require get_template_directory() . '/inc/customizer.php';
/*
* Custom Header callbacks.
*/
require get_template_directory() . '/inc/custom-header.php';
/*
* Decode Theme Hook functions.
*/
require get_template_directory() . '/inc/decode-theme-hooks.php';
/*
* Theme Hook Alliance functions.
*/
require get_template_directory() . '/inc/tha-theme-hooks.php';
/*
* Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/*
* Setup editor styles.
*/
if ( ! function_exists( 'decode_add_editor_styles' ) ) {
function decode_add_editor_styles() {
add_editor_style( 'editor-style.css' );
}
}
add_action( 'init', 'decode_add_editor_styles' );
/*
* Add body classes for sidebar layout options.
*/
function decode_add_body_classes( $classes ) {
if ( get_theme_mod( 'show_sidebar', true ) == true ) {
// Add 'ghost-header-style' to the $classes array.
$classes[] = 'sidebar-style-' . get_theme_mod( 'constant_sidebar', 'closing' );
$classes[] = 'sidebar-style-' . get_theme_mod( 'sidebar_position', 'left' );
}
// Return the $classes array.
return $classes;
}
add_filter( 'body_class', 'decode_add_body_classes' );
/*
* Link post titles are turned into links to the link URL not the permalink for link blog-style behaviour.
*/
if ( ! function_exists( 'decode_print_post_title' ) ) {
function decode_print_post_title() {
global $post;
$thePostID = $post->ID;
$post_id = get_post( $thePostID );
$title = $post_id->post_title;
$perm = get_permalink( $post_id );
$post_keys = array(); $post_val = array();
$post_keys = get_post_custom_keys( $thePostID );
if ( ! empty( $post_keys ) ) {
foreach ( $post_keys as $pkey ) {
if ( $pkey == 'title_url' || $pkey == 'url_title' || $pkey == 'title_link' ) {
$post_val = get_post_custom_values( $pkey );
}
}
if ( empty( $post_val ) ) {
$link = $perm;
}
else {
$link = $post_val[0];
}
}
else {
$link = $perm;
}
echo '<a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a>';
}
}
/*
* Show all post types in main query
*/
if ( ! function_exists( 'decode_add_post_types_to_query' ) ) {
function decode_add_post_types_to_query( $query ) {
$typelist = 'post';
if ( get_theme_mod( 'add_custom_post_types', '' ) !== '' ) {
$typelist .= ', ' . get_theme_mod( 'add_custom_post_types', '' );
$typelist = explode( ', ', $typelist );
}
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', $typelist );
return $query;
}
}
if ( get_theme_mod( 'add_custom_post_types', '' ) !== '' ) {
add_action( 'pre_get_posts', 'decode_add_post_types_to_query' );
}
/**
* Header menu bottom
*/
if( !function_exists( 'header_menu_bottom' ) ) {
add_action( 'header_menu_bottom', 'header_menu_bottom' );
function header_menu_bottom() {
if ( get_theme_mod( 'show_header_menu', true ) == true && get_theme_mod( 'decode_pro_header_options_navigation_menu_position', 'after_logo' ) == 'after_logo' ) {
wp_nav_menu( array(
'theme_location' => 'header-menu',
'container' => false,
'menu_class' => 'menu horizontal-menu header-menu',
'menu_id' => 'header-menu',
'items_wrap' => '<nav id="%1$s" class="%2$s" role="navigation"><ul>%3$s</ul></nav><!-- #header-menu -->',
) );
}
}
}
// add custom class for archive pages
function decode_add_extra_articles_class( $classes ) {
global $post;
if ( is_archive() || is_home() ) {
$classes[] = 'archive-listings';
}
return $classes;
}
add_filter( 'post_class', 'decode_add_extra_articles_class' );
if( !function_exists('decode_register_required_plugins') ) {
/**
* Custom function to load TGMPA
*
* @since Decode 3.14.3
*/
function decode_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(
// Login Customizer
array(
'name' => 'Simple Social Share', // The plugin name.
'slug' => 'kiwi-social-share', // The plugin slug (typically the folder name).
'source' => '', // The plugin source.
'required' => false, // If false, the plugin is only 'recommended' instead of required.
'version' => '1.0.1', // E.g. 1.0.0. If set, the active plugin must be this version or higher.
'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.
),
array(
'name' => 'reCaptcha Security', // The plugin name.
'slug' => 'uber-nocaptcha-recaptcha', // The plugin slug (typically the folder name).
'source' => '', // The plugin source.
'required' => false, // If false, the plugin is only 'recommended' instead of required.
'version' => '1.0.4', // E.g. 1.0.0. If set, the active plugin must be this version or higher.
'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.
)
);
/**
* Array of configuration settings. Amend each line as needed.
* If you want the default strings to be available under your own theme domain,
* leave the strings uncommented.
* Some of the strings are added into a sprintf, so see the comments at the
* end of each line for what each argument will be.
*/
$config = array(
'default_path' => '', // Default absolute path to pre-packaged plugins.
'menu' => 'mt-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => true, // 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', 'decode'),
'menu_title' => __('Install Plugins', 'decode'),
'installing' => __('Installing Plugin: %s', 'decode'), // %s = plugin name.
'oops' => __('Something went wrong with the plugin API.', 'decode'),
'notice_can_install_required' => _n_noop('This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'decode'), // %1$s = plugin name(s).
'notice_can_install_recommended' => _n_noop('This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'decode'), // %1$s = plugin name(s).
'notice_cannot_install' => _n_noop('Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'decode'), // %1$s = plugin name(s).
'notice_can_activate_required' => _n_noop('The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'decode'), // %1$s = plugin name(s).
'notice_can_activate_recommended' => _n_noop('The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'decode'), // %1$s = plugin name(s).
'notice_cannot_activate' => _n_noop('Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'decode'), // %1$s = plugin name(s).
'notice_ask_to_update' => _n_noop('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.', 'decode'), // %1$s = plugin name(s).
'notice_cannot_update' => _n_noop('Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'decode'), // %1$s = plugin name(s).
'install_link' => _n_noop('Begin installing plugin', 'Begin installing plugins', 'decode'),
'activate_link' => _n_noop('Begin activating plugin', 'Begin activating plugins', 'decode'),
'return' => __('Return to Required Plugins Installer', 'decode'),
'plugin_activated' => __('Plugin activated successfully.', 'decode'),
'complete' => __('All plugins installed and activated successfully. %s', 'decode'), // %s = dashboard link.
'nag_type' => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
)
);
tgmpa($plugins, $config);
}
add_action( 'tgmpa_register', 'decode_register_required_plugins' );
}
#
# More Themes Functionality
#