-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfunctions.php
264 lines (217 loc) · 8.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
<?php
require_once 'inc/BootstrapNavMenuWalker.php';
require_once 'inc/Comments.php';
// Bootstrap Menu Walker
add_action('after_setup_theme', 'gitsta_bootstrap_setup');
// TGM Plugin Activation <http://tgmpluginactivation.com/>
// Thanks to @EmilUzelac
require_once 'inc/class-tgm-plugin-activation.php';
add_action('tgmpa_register', function() {
$plugins = array(
array(
'name' => 'WP-Markdown',
'slug' => 'wp-markdown',
'required' => false,
),
array(
'name' => 'Gust',
'slug' => 'gust',
'required' => false
)
);
tgmpa($plugins);
});
$goofy = array(1);
/*
|----------------------------------------------------------
| Gitsta Theme Setup
|----------------------------------------------------------
*/
add_action('after_setup_theme', function() {
// Content width - required by WordPress
global $content_width;
if( ! isset($content_width)) {
$content_width = 945;
}
// Theme support
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
add_theme_support('title-tag');
// Title hook
add_action('wp_title', function($title) {
return get_bloginfo('name') . $title;
});
// Scripts and styles used by the theme
add_action('wp_enqueue_scripts', function() {
// Scripts and styles
wp_enqueue_style('gitsta-style', get_stylesheet_uri());
wp_enqueue_style('bootstrap', get_template_directory_uri() . '/vendor/bootstrap/css/bootstrap.css');
wp_enqueue_style('font-awesome', get_template_directory_uri() . '/vendor/font-awesome/css/font-awesome.css');
wp_enqueue_style('octicons', get_template_directory_uri() . '/vendor/octicons/css/octicons.css');
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/vendor/bootstrap/js/bootstrap.js', array('jquery'));
wp_enqueue_script('marked', get_template_directory_uri() . '/vendor/marked.js');
wp_enqueue_script('gitsta-main-js', get_template_directory_uri() . '/js/main.js');
wp_localize_script('gitsta-main-js', 'theme', array('template_directory_uri' => get_template_directory_uri()));
});
/*
|----------------------------------------------------------
| Sidebar
|----------------------------------------------------------
|
| Sidebar is hidden on mobile devices
|
*/
if(function_exists('register_sidebar')) {
add_action('widgets_init', function() {
register_sidebar(array(
'before_widget' => '<div id="%1$s" class="widget hidden-xs">',
'after_widget' => '</div>'
));
});
}
/*
|----------------------------------------------------------
| Filters
|----------------------------------------------------------
*/
// CSS Style for reply link
add_filter('comment_reply_link', function($link) {
$link = str_replace("class='comment-reply-link'", "class='comment-reply-link btn btn-default btn-xs' data-scroll='true'", $link);
return $link;
});
// CSS Style for edit comment link
add_filter('edit_comment_link', function($link) {
$link = str_replace('class="comment-edit-link"', "class='comment-edit-link btn btn-default btn-xs'", $link);
return $link;
});
// CSS Style for edit post link
add_filter('edit_post_link', function($link) {
$link = str_replace('class="post-edit-link"', "class='post-edit-link btn btn-info btn-xs'", $link);
return $link;
});
// Add some css classes to images
add_filter('the_content', function($content) {
$pattern = "/<img(.*?)class=\"(?!wp-smiley)(.*?)\"(.*?)>/i";
$replacement = '<img$1class="$2 img-thumbnail img-responsive"$3>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
});
// Add bootstrap css classes to tables
add_filter('the_content', function($content) {
$pattern = "/<table(.*?)>/i";
$replacement = '<table $1 class="table table-bordered table-striped">';
$content = preg_replace($pattern, $replacement, $content);
return $content;
});
// Adds some css classes to avatars
add_filter('get_avatar', function($avatar) {
$avatar = str_replace("class='avatar",
"class='avatar media-object img-rounded",
$avatar);
return $avatar;
});
// Add css class to tags
add_filter('the_tags', function($tag) {
$tag = str_replace('rel="tag">',
'rel="tag" class="label label-primary">',
$tag);
return $tag;
});
// Code tags
add_filter('the_content', function($content) {
$pattern = "/<pre(.*?)>/i";
$replacement = '<div class="code-box"><div class="code-title"><i class="fa fa-code"></i> <div class="pull-right"><a href="#" class="btn btn-default btn-xs toggle-code" data-toggle="tooltip" title="' . __('Toggle code', 'gitsta') . '"><i class="fa fa-toggle-up"></i></a></div></div><pre $1>';
$content = preg_replace($pattern, $replacement, $content);
$pattern = "/<\/pre>/";
$replacement = '</pre></div>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
});
// Read more Hack
add_filter('the_content_more_link', function($link) {
$link = preg_replace( '|#more-[0-9]+|', '', $link );
return $link;
});
/*
|----------------------------------------------------------
| Theme options
|----------------------------------------------------------
*/
// To reduce redundancy
function get_gitsta_theme_option($option) {
// Default theme options (somehow a senseless comment)
$default_theme_options = array(
'favicon_url' => '',
'comment_markdown_support' => 1,
'frontpage_blog_descr' => 0,
'error_404_title' => 'Error 404',
'error_404_content' => '<img src="' . get_template_directory_uri() . '/vendor/deadlink.png" class="img-responsive" style="margin: 0 auto; padding-top: 30px; padding-bottom: 30px;">
<p class="text-muted">
Whoops, you found a dead link.
</p>',
);
$gitsta_theme_options = get_option('gitsta_theme_options', $default_theme_options);
if(isset($gitsta_theme_options[$option])) {
return $gitsta_theme_options[$option];
}
return false;
}
add_action('admin_init', function() {
register_setting('gitsta_options', 'gitsta_theme_options', function($input) {
return $input;
});
});
add_action('admin_menu', function() {
add_theme_page('Gitsta', 'Gitsta', 'edit_theme_options', 'gitsta-option', function() {
include 'inc/Partials/ThemeOptions.php';
});
});
/*
|----------------------------------------------------------
| Custom wp_link_pages function
|----------------------------------------------------------
*/
function gitsta_wp_link_pages($args = '') {
$defaults = array(
'before' => '',
'after' => '',
'prev_and_next' => true,
'nextpagelink' => '»',
'prevpagelink' => '«',
'echo' => true
);
$r = wp_parse_args($args, $defaults);
extract($r, EXTR_SKIP);
global $page, $numpages, $multipage, $more;
$output = '';
if($multipage) {
$output .= $before . '<ul class="pagination">';
// Attach prev link
$i = ($page - 1);
if(($i > 0) && $prev_and_next) {
$output .= '<li>' . _wp_link_page($i) . $prevpagelink . '</a></li>';
}
// Attach page numbers
for($i = 1; $i <= $numpages; $i++) {
$link = '';
if($i == $page) {
$link .= '<li class="active"><a href="#">' . $i . '</li>';
} else {
$link .= '<li>' . _wp_link_page($i) . $i . '</a></li>';
}
$link = apply_filters('wp_link_pages_link', $link, $i);
$output .= $link;
}
// Attach next link
$i = ($page + 1);
if(($i <= $numpages) && $prev_and_next) {
$output .= '<li>' . _wp_link_page($i) . $nextpagelink . '</a></li>';
}
$output .= '</ul>' . $after;
}
$output = apply_filters('wp_link_pages', $output, $args);
if($echo) {
echo $output;
}
}
});