forked from FutureMedia/HTML5-Blank-WordPress-Theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
387 lines (336 loc) · 14.5 KB
/
Copy pathfunctions.php
File metadata and controls
387 lines (336 loc) · 14.5 KB
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
<?php
/**
* Author: Todd Motto | @toddmotto and Mindshare Labs | @mindsharelabs
* URL: mindblank.com | @mindblank
* Custom functions, support, custom post types and more.
*/
/*------------------------------------*\
External Modules/Files
\*------------------------------------*/
include_once 'inc/content-functions.php';
/*------------------------------------*\
Theme Support
\*------------------------------------*/
if (!isset($content_width)) {
$content_width = 900;
}
if (function_exists('add_theme_support')) {
// Add Thumbnail Theme Support
add_theme_support('post-thumbnails');
// Enables post and comment RSS feed links to head
add_theme_support('automatic-feed-links');
// Enable mind support
add_theme_support('mind', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption'));
// Localisation Support
load_theme_textdomain('mindblank', get_template_directory() . '/languages');
}
/*------------------------------------*\
Functions
\*------------------------------------*/
// mind Blank navigation
function mindblank_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
// Load mind Blank scripts (header.php)
function mindblank_header_scripts()
{
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
wp_register_script('mindblankscripts-min', get_template_directory_uri() . '/js/scripts.js', array(), '1.0.0');
wp_enqueue_script('mindblankscripts-min');
wp_register_script('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), '1.0.0');
wp_enqueue_script('bootstrap');
}
}
// Load mind Blank conditional scripts
function mindblank_conditional_scripts()
{
// if (is_page('pagenamehere')) {
// // Conditional script(s)
// wp_register_script('scriptname', get_template_directory_uri() . '/js/scriptname.js', array('jquery'), '1.0.0');
// wp_enqueue_script('scriptname');
// }
}
// Load mind Blank styles
function mindblank_styles()
{
wp_register_style('mindblankcssmin', get_template_directory_uri() . '/style.css', array(), '1.0');
wp_enqueue_style('mindblankcssmin');
}
// Register mind Blank Navigation
function register_mind_menu()
{
register_nav_menus(array( // Using array to specify more menus if needed
'header-menu' => __('Header Menu', 'mindblank'), // Main Navigation
'sidebar-menu' => __('Sidebar Menu', 'mindblank'), // Sidebar Navigation
));
}
// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
$args['container'] = false;
return $args;
}
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
return is_array($var) ? array() : '';
}
// Remove invalid rel attribute values in the categorylist
function remove_category_rel_from_category_list($thelist)
{
return str_replace('rel="category tag"', 'rel="tag"', $thelist);
}
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
function add_slug_to_body_class($classes)
{
global $post;
if (is_home()) {
$key = array_search('blog', $classes);
if ($key > -1) {
unset($classes[$key]);
}
} elseif (is_page()) {
$classes[] = sanitize_html_class($post->post_name);
} elseif (is_singular()) {
$classes[] = sanitize_html_class($post->post_name);
}
return $classes;
}
// Remove the width and height attributes from inserted images
function remove_width_attribute($html)
{
$html = preg_replace('/(width|height)="\d*"\s/', "", $html);
return $html;
}
// If Dynamic Sidebar Exists
if (function_exists('register_sidebar')) {
// Define Sidebar Widget Area 1
register_sidebar(array(
'name' => __('Widget Area 1', 'mindblank'),
'description' => __('Description for this widget-area...', 'mindblank'),
'id' => 'widget-area-1',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
}
// Remove wp_head() injected Recent Comment styles
function my_remove_recent_comments_style()
{
global $wp_widget_factory;
if (isset($wp_widget_factory->widgets['WP_Widget_Recent_Comments'])) {
remove_action('wp_head', array(
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
'recent_comments_style'
));
}
}
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function mindwp_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}
// Create the Custom Excerpts callback
function mindwp_excerpt($length_callback = '', $more_callback = '')
{
global $post;
if (function_exists($length_callback)) {
add_filter('excerpt_length', $length_callback);
}
if (function_exists($more_callback)) {
add_filter('excerpt_more', $more_callback);
}
$output = get_the_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = '<p>' . $output . '</p>';
echo $output;
}
// Custom View Article link to Post
function mind_blank_view_article($more)
{
global $post;
return '... <a class="view-article" href="' . get_permalink($post->ID) . '">' . __('View Article', 'mindblank') . '</a>';
}
// Remove 'text/css' from our enqueued stylesheet
function mind_style_remove($tag)
{
return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag);
}
// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
function remove_thumbnail_dimensions($html)
{
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
}
// Custom Gravatar in Settings > Discussion
function mindblankgravatar($avatar_defaults)
{
$myavatar = get_template_directory_uri() . '/img/gravatar.jpg';
$avatar_defaults[$myavatar] = "Custom Gravatar";
return $avatar_defaults;
}
// Threaded Comments
function enable_threaded_comments()
{
if (!is_admin()) {
if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
wp_enqueue_script('comment-reply');
}
}
}
// Custom Comments Callback
function mindblankcomments($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ('div' == $args['style']) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<!-- heads up: starting < for the html tag (li or div) in the next line: -->
<<?php echo $tag ?><?php comment_class(empty($args['has_children']) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
<?php if ('div' != $args['style']) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ($args['avatar_size'] != 0) echo get_avatar($comment, $args['avatar_size']); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
<br/>
<?php endif; ?>
<div class="comment-meta commentmetadata"><a
href="<?php echo htmlspecialchars(get_comment_link($comment->comment_ID)) ?>">
<?php
printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'), ' ', '');
?>
</div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge($args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
<?php if ('div' != $args['style']) : ?>
</div>
<?php endif; ?>
<?php }
/*------------------------------------*\
Actions + Filters + ShortCodes
\*------------------------------------*/
// Add Actions
add_action('init', 'mindblank_header_scripts'); // Add Custom Scripts to wp_head
add_action('wp_print_scripts', 'mindblank_conditional_scripts'); // Add Conditional Page Scripts
add_action('get_header', 'enable_threaded_comments'); // Enable Threaded Comments
add_action('wp_enqueue_scripts', 'mindblank_styles'); // Add Theme Stylesheet
add_action('init', 'register_mind_menu'); // Add mind Blank Menu
add_action('init', 'create_post_type_mind'); // Add our mind Blank Custom Post Type
add_action('widgets_init', 'my_remove_recent_comments_style'); // Remove inline Recent Comment Styles from wp_head()
add_action('init', 'mindwp_pagination'); // Add our mind Pagination
// Remove Actions
remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file.
remove_action('wp_head', 'wp_generator'); // Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
// Add Filters
add_filter('avatar_defaults', 'mindblankgravatar'); // Custom Gravatar in Settings > Discussion
add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build)
add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar
add_filter('widget_text', 'shortcode_unautop'); // Remove <p> tags in Dynamic Sidebars (better!)
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding <div> from WP Navigation
// add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected classes (Commented out by default)
// add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected ID (Commented out by default)
// add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> Page ID's (Commented out by default)
add_filter('the_category', 'remove_category_rel_from_category_list'); // Remove invalid rel attribute
add_filter('the_excerpt', 'shortcode_unautop'); // Remove auto <p> tags in Excerpt (Manual Excerpts only)
add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only)
add_filter('excerpt_more', 'mind_blank_view_article'); // Add 'View Article' button instead of [...] for Excerpts
add_filter('style_loader_tag', 'mind_style_remove'); // Remove 'text/css' from enqueued stylesheet
add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails
add_filter('post_thumbnail_html', 'remove_width_attribute', 10); // Remove width and height dynamic attributes to post images
add_filter('image_send_to_editor', 'remove_width_attribute', 10); // Remove width and height dynamic attributes to post images
// Remove Filters
remove_filter('the_excerpt', 'wpautop'); // Remove <p> tags from Excerpt altogether
// Shortcodes
add_shortcode('mind_shortcode_demo', 'mind_shortcode_demo'); // You can place [mind_shortcode_demo] in Pages, Posts now.
add_shortcode('mind_shortcode_demo_2', 'mind_shortcode_demo_2'); // Place [mind_shortcode_demo_2] in Pages, Posts now.
// Shortcodes above would be nested like this -
// [mind_shortcode_demo] [mind_shortcode_demo_2] Here's the page title! [/mind_shortcode_demo_2] [/mind_shortcode_demo]
/*------------------------------------*\
Custom Post Types
\*------------------------------------*/
// Create 1 Custom Post type for a Demo, called mind-Blank
function create_post_type_mind()
{
register_taxonomy_for_object_type('category', 'mind-blank'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'mind-blank');
register_post_type('mind-blank', // Register Custom Post Type
array(
'labels' => array(
'name' => __('mind Blank Custom Post', 'mindblank'), // Rename these to suit
'singular_name' => __('mind Blank Custom Post', 'mindblank'),
'add_new' => __('Add New', 'mindblank'),
'add_new_item' => __('Add New mind Blank Custom Post', 'mindblank'),
'edit' => __('Edit', 'mindblank'),
'edit_item' => __('Edit mind Blank Custom Post', 'mindblank'),
'new_item' => __('New mind Blank Custom Post', 'mindblank'),
'view' => __('View mind Blank Custom Post', 'mindblank'),
'view_item' => __('View mind Blank Custom Post', 'mindblank'),
'search_items' => __('Search mind Blank Custom Post', 'mindblank'),
'not_found' => __('No mind Blank Custom Posts found', 'mindblank'),
'not_found_in_trash' => __('No mind Blank Custom Posts found in Trash', 'mindblank')
),
'public' => true,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
), // Go to Dashboard Custom mind Blank post for supports
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
}
/*------------------------------------*\
ShortCode Functions
\*------------------------------------*/