forked from WPChill/decode-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
311 lines (255 loc) · 8.17 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
<?php
/**
* Decode functions and definitions
*
* @package Decode
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */
}
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' );
// 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',
'admin-preview-callback' => 'decode_admin_header_image',
);
$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' => 'ECF0F1',
);
$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(
'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 http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
/*
* Enable support for Post Formats.
* See http://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 );
}
endif; // decode_setup
add_action( 'after_setup_theme', 'decode_setup' );
/*
* Register styles and scripts.
*/
if ( ! is_admin() && ! function_exists( 'decode_scripts' ) ) {
function decode_scripts() {
wp_enqueue_style( 'decode-style', get_stylesheet_uri(), array(), '3.0.1' );
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' );
}
if ( get_theme_mod( 'show_sidebar', true ) == false ) {
wp_enqueue_script( 'decode-scripts', get_template_directory_uri() . '/scripts/decode.js', array(), '3.0.0', true );
}
if ( get_theme_mod( 'show_sidebar', true ) == true ) {
wp_enqueue_script( 'decode-sidebar', get_template_directory_uri() . '/scripts/decode-with-sidebar.js', array(), '3.0.0', true );
}
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) && get_theme_mod( 'enable_comments', true ) == true ) {
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 http://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.
/*
* 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 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' );
/*
* Add Google Profile to user contact methods.
*/
function decode_add_google_profile( $contactmethods ) {
// Add Google Profiles
$contactmethods['google_profile'] = 'Google Profile URL';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'decode_add_google_profile', 10, 1 );
/*
* 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( 'add_post_types_to_query' ) ) {
function 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', 'add_post_types_to_query' );
}