-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·146 lines (122 loc) · 3.97 KB
/
functions.php
File metadata and controls
executable file
·146 lines (122 loc) · 3.97 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
<?php
function scripts_and_styles_method() {
$templateuri = get_template_directory_uri() . '/js/';
// library.js is to bundle plugins. my.js is your scripts. enqueue more files as needed
$jslib = $templateuri."library.js";
wp_enqueue_script( 'jslib', $jslib,'','',true);
$myscripts = $templateuri."main.min.js";
wp_enqueue_script( 'myscripts', $myscripts,'','',true);
wp_localize_script( 'myscripts', 'WP', array(
'blogName' => get_bloginfo('name')
));
// enqueue stylesheet here. file does not exist until stylus file is processed
wp_enqueue_style( 'site', get_stylesheet_directory_uri() . '/css/site.min.css' );
// dashicons for admin
if(is_admin()){
wp_enqueue_style( 'dashicons' );
}
}
add_action('wp_enqueue_scripts', 'scripts_and_styles_method');
if( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' );
}
if( function_exists( 'add_image_size' ) ) {
add_image_size( 'admin-thumb', 150, 150, false );
add_image_size( 'opengraph', 1200, 630, true );
add_image_size( 'name', 199, 299, true );
}
// Register Nav Menus
register_nav_menus( array(
'menu_pages' => 'Pages',
) );
add_filter( 'wp_nav_menu_items', 'prefix_remove_menu_item_whitespace' );
function prefix_remove_menu_item_whitespace( $items ) {
return preg_replace( '/>(\s|\n|\r)+</', '><', $items );
}
function wpa_category_nav_class( $classes, $item ){
if( 'category' == $item->object ){
$classes[] = 'menu-category-' . $item->object_id;
}
return $classes;
}
add_filter( 'nav_menu_css_class', 'wpa_category_nav_class', 10, 2 );
//get_template_part( 'lib/gallery' );
//get_template_part( 'lib/post-types' );
//get_template_part( 'lib/meta-boxes' );
//get_template_part( 'lib/theme-options' );
get_template_part( 'lib/custom-nav' );
add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
function cmb_initialize_cmb_meta_boxes() {
// Add CMB2 plugin
if( ! class_exists( 'cmb2_bootstrap_202' ) )
require_once 'lib/CMB2/init.php';
}
// Disable that freaking admin bar
add_filter('show_admin_bar', '__return_false');
// Turn off version in meta
function no_generator() { return ''; }
add_filter( 'the_generator', 'no_generator' );
// Show thumbnails in admin lists
add_filter('manage_posts_columns', 'new_add_post_thumbnail_column');
function new_add_post_thumbnail_column($cols){
$cols['new_post_thumb'] = __('Thumbnail');
return $cols;
}
add_action('manage_posts_custom_column', 'new_display_post_thumbnail_column', 5, 2);
function new_display_post_thumbnail_column($col, $id){
switch($col){
case 'new_post_thumb':
if( function_exists('the_post_thumbnail') ) {
echo the_post_thumbnail( 'admin-thumb' );
}
else
echo 'Not supported in theme';
break;
}
}
// remove automatic <a> links from images in blog
function wpb_imagelink_setup() {
$image_set = get_option( 'image_default_link_type' );
if($image_set !== 'none') {
update_option('image_default_link_type', 'none');
}
}
add_action('admin_init', 'wpb_imagelink_setup', 10);
// custom login logo
/*
function custom_login_logo() {
echo '<style type="text/css">h1 a { background-image:url(' . get_bloginfo( 'template_directory' ) . '/images/login-logo.png) !important; background-size:300px auto !important; width:300px !important; }</style>';
}
add_action( 'login_head', 'custom_login_logo' );
*/
// UTILITY FUNCTIONS
// to replace file_get_contents
function url_get_contents($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
// get ID of page by slug
function get_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if($page) {
return $page->ID;
} else {
return null;
}
}
// is_single for custom post type
function is_single_type($type, $post) {
if (get_post_type($post->ID) === $type) {
return true;
} else {
return false;
}
}
?>