-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
214 lines (182 loc) · 6.91 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
<?php
require_once('wp-bootstrap-navwalker.php'); // for menu
require_once('question-functions.php'); // question post type + hint/answer
require_once('customizer.php'); // theme customization
require_once('default_theme_vals.php');
add_filter( 'img_caption_shortcode', 'dap_responsive_img_caption_filter', 10, 3 );
function dap_responsive_img_caption_filter( $val, $attr, $content = null ) {
extract(shortcode_atts( array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
),
$attr));
if ( 1 > (int) $width || empty($caption) )
return $val;
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="max-width: 100% !important; height: auto; width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
// turn off related posts in jetpack for everything other than blog posts
function no_related_posts( $options ) {
if ( !is_singular( 'post' ) ) {
$options['enabled'] = false;
}
return $options;
}
add_filter( 'jetpack_relatedposts_filter_options', 'no_related_posts' );
add_action( 'widgets_init', 'configure_sidebars' );
function configure_sidebars(){
register_sidebar( array(
'name' => 'Dynamic Sidebar',
'id' => 'widgety',
'description' => 'Widgets in this area will be shown on post lists',
'before_widget' => '<div id="%1$s" class="widget %2$s unstyled">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Dynamic Top',
'id' => 'widgety-top',
'description' => 'Widgets in this area will be shown on post lists',
'before_widget' => '<div id="%1$s" class="widget %2$s unstyled">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Header',
'id' => 'header',
'description' => 'This widget goes in the header',
'before_widget' => '<div id="%1$s" class="widget %2$s unstyled">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Footer',
'id' => 'footer',
'description' => 'This widget goes in the footer',
'before_widget' => '<div id="%1$s" class="widget %2$s unstyled">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
) );
}
//Exclude pages from WordPress Search
if (!is_admin()) {
function wpb_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','wpb_search_filter');
}
function custom_theme_setup() {
add_theme_support( 'html5', array( 'comment-list' ) );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );
// Get permalink for question feeder
// either home or separate question feeder page
function question_feeder_permalink(){
$args = array(
'post_type' => 'page',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'question-feeder.php',
)
)
);
$query = new WP_Query( $args );
/* This should only happen ONCE. Only one question feeder per website. */
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$link = get_the_permalink();
}
wp_reset_query();
}
/* ...unless we don't create one. In this case, just get home url (default) */
else{
$link = get_home_url();
}
return $link;
}
defined('FEEDER_LINK') or define('FEEDER_LINK', question_feeder_permalink());
function wp_42573_fix_template_caching( WP_Screen $current_screen ) {
// Only flush the file cache with each request to post list table, edit post screen, or theme editor.
if ( ! in_array( $current_screen->base, array( 'post', 'edit', 'theme-editor' ), true ) ) {
return;
}
$theme = wp_get_theme();
if ( ! $theme ) {
return;
}
$cache_hash = md5( $theme->get_theme_root() . '/' . $theme->get_stylesheet() );
$label = sanitize_key( 'files_' . $cache_hash . '-' . $theme->get( 'Version' ) );
$transient_key = substr( $label, 0, 29 ) . md5( $label );
delete_transient( $transient_key );
}
add_action( 'current_screen', 'wp_42573_fix_template_caching' );
add_theme_support( 'post-thumbnails' );
// Replaces the excerpt "Read More" text by a link
function new_excerpt_more($more) {
return '...<p><a class="moretopic" href="'. get_permalink() . '"> (Continue)</a></p>';
}
add_filter('excerpt_more', 'new_excerpt_more');
/* Theme setup */
function get_num_questions($terms){
$count = 0;
foreach ($terms as $term){
$count = $count + ($term->count);
}
return $count;
}
/* Images */
$args = array(
'flex-width' => true,
'flex-height' => true,
'width' => 0,
'height' => 0,
'default-image' => get_template_directory_uri() . '/assets/images/gfdatabase.png',
'uploads' => true,
);
add_theme_support( 'custom-header', $args );
add_action( 'after_setup_theme', 'wpt_setup' );
if ( ! function_exists( 'wpt_setup' ) ){
function wpt_setup() {
register_nav_menu( 'primary', __( 'Primary navigation') );
}
}
function wpt_register_js() {
wp_register_script('jquery.bootstrap.min', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script('jquery.bootstrap.min');
wp_register_script('scroll-top', TEMPLATE_DIR . '/assets/js/scroll-top.js', array('jquery'));
wp_enqueue_script('scroll-top');
// Only include MathJax and the question javascript when the post type is a question
if (get_post_type() === 'question' || get_post_meta( get_the_ID(), '_wp_page_template', true ) === 'question-feeder.php'){
wp_register_script('mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML');
wp_enqueue_script('mathjax');
wp_register_script('question', TEMPLATE_DIR . '/assets/js/question.js', array('jquery'));
wp_enqueue_script('question');
}
}
add_action( 'wp_enqueue_scripts', 'wpt_register_js' );
function wpt_register_css() {
wp_register_style( 'bootstrap.min', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );
wp_enqueue_style( 'bootstrap.min' );
wp_register_style('font-awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
wp_enqueue_style('font-awesome');
wp_register_style('normalize', TEMPLATE_DIR . '/assets/css/normalize.css');
wp_enqueue_style('normalize');
wp_enqueue_style( 'parent-style', TEMPLATE_DIR . '/style.css');
if (TEMPLATE_DIR !== STYLESHEET_DIR){
wp_enqueue_style( 'child-style', STYLESHEET_DIR . '/style.css', array( 'parent-style' ) );
}
}
add_action( 'wp_enqueue_scripts', 'wpt_register_css' );