-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
254 lines (209 loc) · 9.74 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
<?php
// Define global theme variables
define( 'RADIUZZ_CASSIOPEIA_THEMEROOT', get_stylesheet_directory_uri() );
define( 'RADIUZZ_CASSIOPEIA_IMAGES', RADIUZZ_CASSIOPEIA_THEMEROOT . '/images' );
$posts_per_page = get_option('posts_per_page');
global $posts_per_page;
// Set max content width
if (!isset($content_width)) {
$content_width = 1170;
}
add_action( 'after_setup_theme', 'radiuzz_cassiopeia_setup' );
function radiuzz_cassiopeia_setup() {
// Add theme support
add_theme_support("menus");
add_theme_support("post-thumbnails");
add_theme_support("automatic-feed-links");
add_theme_support("title-tag");
/* ------------------------------------------------------------------------ */
/* Theme Menus */
/* ------------------------------------------------------------------------ */
register_nav_menus(
array(
"main-menu" => "Main Menu",
)
);
add_filter('nav_menu_css_class' , 'radiuzz_cassiopeia_nav_class' , 10 , 2);
function radiuzz_cassiopeia_nav_class($classes, $item){
if( in_array('current-menu-item', $classes) ){
$classes[] = 'active ';
}
return $classes;
}
}
/* ------------------------------------------------------------------------ */
/* Theme Stylesheets */
/* ------------------------------------------------------------------------ */
function radiuzz_cassiopeia_enqueue_css() {
// Register
wp_register_style("wp-style", get_stylesheet_uri(), false, "1.0");
wp_register_style("bootstrap", get_template_directory_uri()."/assets/css/bootstrap.css", false, "1.0");
wp_register_style("font-awesome", get_template_directory_uri()."/assets/css/font-awesome.css", false, "1.0");
wp_register_style("main", get_template_directory_uri()."/assets/css/main.css", false, "1.0");
// Enqueue
wp_enqueue_style("wp-style");
wp_enqueue_style("bootstrap");
wp_enqueue_style("font-awesome");
wp_enqueue_style("main");
}
add_action("wp_enqueue_scripts", "radiuzz_cassiopeia_enqueue_css");
// Include custom css
include( get_template_directory() . "/assets/css/custom.php");
/* ------------------------------------------------------------------------ */
/* Google Fonts */
/* ------------------------------------------------------------------------ */
/*
Register Fonts
*/
function radiuzz_cassiopeia_google_fonts() {
$font_url = '';
/*
Translators: If there are characters in your language that are not supported
by chosen font(s), translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Google font: on or off', "cassiopeia" ) ) {
$font_url = add_query_arg( 'family', urlencode( 'Lora|Rokkitt:400,400italic,700italic,700&subset=latin,latin-ext' ), "//fonts.googleapis.com/css" );
}
return $font_url;
}
/*
Enqueue scripts and styles.
*/
function radiuzz_cassiopeia_scripts() {
wp_enqueue_style( 'cassiopeia-fonts', radiuzz_cassiopeia_google_fonts(), array(), '1.0.0' );
}
add_action( 'wp_enqueue_scripts', 'radiuzz_cassiopeia_scripts' );
/* ------------------------------------------------------------------------ */
/* Loading Theme Scripts */
/* ------------------------------------------------------------------------ */
function radiuzz_cassiopeia_enqueue_js() {
if(!is_admin()) {
// Register
wp_register_script("bootstrap", get_template_directory_uri()."/assets/js/bootstrap.js", array("jquery"), "1.0", TRUE);
wp_register_script("isotope", get_template_directory_uri()."/assets/js/isotope.pkgd.js", array("jquery"), "1.0", TRUE);
wp_register_script("main", get_template_directory_uri()."/assets/js/main.js", array("jquery"), "1.0", TRUE);
// Enqueue
wp_enqueue_script("bootstrap");
wp_enqueue_script("isotope");
wp_enqueue_script("main");
if ( is_singular() ) wp_enqueue_script( "comment-reply" );
}
}
add_action("wp_enqueue_scripts", "radiuzz_cassiopeia_enqueue_js");
/* ------------------------------------------------------------------------ */
/* Widgets */
/* ------------------------------------------------------------------------ */
function radiuzz_cassiopeia_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Main Sidebar', "cassiopeia" ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Widgets in this area will be shown on all posts and pages.', "cassiopeia" ),
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}
add_action( 'widgets_init', 'radiuzz_cassiopeia_widgets_init' );
function radiuzz_cassiopeia_social_sharing_buttons($cassiopeia_share_buttons) {
// Show this on post and page only. Add filter is_home() for home page
if(is_single()){
// Get current page URL
$shortURL = get_permalink();
// Get current page title
$shortTitle = get_the_title();
// Construct sharing URL without using any script
$facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$shortURL;
$twitterURL = 'https://twitter.com/intent/tweet?text='.$shortTitle.'&url='.$shortURL.'&via=Crunchify';
$googleURL = 'https://plus.google.com/share?url='.$shortURL;
// Add sharing button at the end of page/page content
$cassiopeia_share_buttons .= '<div class="share-side">';
$cassiopeia_share_buttons .= '<h5>Share Via:</h5>';
$cassiopeia_share_buttons .= '<ul>';
$cassiopeia_share_buttons .= '<li><a class="" href="'.$facebookURL.'" target="_blank"><i class="fa fa-facebook"></i></a></li>';
$cassiopeia_share_buttons .= '<li><a class="" href="'. $twitterURL .'" target="_blank"><i class="fa fa-twitter"></i></a></li>';
$cassiopeia_share_buttons .= '<li><a class="" href="'.$googleURL.'" target="_blank"><i class="fa fa-google-plus"></i></a></li>';
$cassiopeia_share_buttons .= '</ul>';
$cassiopeia_share_buttons .= '</div>';
return $cassiopeia_share_buttons;
}
else{
return $cassiopeia_share_buttons;
}
};
add_filter( 'the_content', 'radiuzz_cassiopeia_social_sharing_buttons');
/* ------------------------------------------------------------------------ */
/* TGMPA plugin activation */
/* ------------------------------------------------------------------------ */
require_once( get_template_directory() . '/includes/plugin-activation.php');
add_action( 'tgmpa_register', 'radiuzz_cassiopeia_theme_plugins' );
function radiuzz_cassiopeia_theme_plugins() {
$plugins = array(
array(
'name' => esc_html__('Cassiopeia core',"cassiopeia"), // The plugin name
'slug' => "cassiopeia", // The plugin slug (typically the folder name)
'source' => 'http://cassiopeia.radiuzz.com/plugins/cassiopeia.zip', // The plugin source
'required' => true, // If false, the plugin is only 'recommended' instead of required
'version' => '1.0', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
'external_url' => '', // If set, overrides default API URL and points to an external URL
),
array(
'name' => esc_html__('Contact form 7',"cassiopeia"),
'slug' => 'contact-form-7',
'required' => true,
),
array(
'name' => esc_html__('Advanced custom fields',"cassiopeia"),
'slug' => 'advanced-custom-fields',
'required' => true,
'force_activation' => false,
)
);
$config = array(
'id' => "cassiopeia", // Unique ID for hashing notices for multiple instances of cassiopeia.
'domain' => "cassiopeia", // Text domain - likely want to be the same as your theme.
'default_path' => '', // Default absolute path to pre-packaged plugins.
'menu' => 'cassiopeia-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
);
tgmpa( $plugins, $config );
}
function radiuzz_cassiopeia_pagination($pages = '', $class = '', $range = 4) {
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if($class == '') {
$pagination_class = 'pagination';
} else {
$pagination_class = $class;
}
if(1 != $pages)
{
echo "<ul class=\"" . esc_attr($pagination_class) . "\">";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« ".esc_html__("First" , "cassiopeia")."</a>";
if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."'>‹ ".esc_html__("Previous","cassiopeia")."</a></li>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<li class=\"active\"><a>".$i."</a></li>":"<li><a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a></li>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">".esc_html__("<i class='fa fa-long-arrow-right'></i>", "cassiopeia")." ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a href='".get_pagenum_link($pages)."'>".esc_html__("<i class='fa fa-long-arrow-left'></i>" , "cassiopeia")." »</a></li>";
echo "</ul>\n";
}
}