forked from strangerstudios/memberlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
311 lines (272 loc) · 11.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
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
<?php
/**
* Memberlite functions and definitions
*
* @package Memberlite
*/
define('MEMBERLITE_VERSION', '3.0.1');
//get default values for options/etc
require_once get_template_directory() . '/inc/defaults.php';
//enqueue additional stylesheets and javascript
function memberlite_init_styles()
{
global $memberlite_defaults;
//need jquery
wp_enqueue_script('jquery');
//framework stuff
wp_enqueue_style('memberlite_grid', get_template_directory_uri() . "/css/grid.css", array(), MEMBERLITE_VERSION);
wp_enqueue_style('memberlite_style', get_stylesheet_uri(), array(), MEMBERLITE_VERSION);
wp_enqueue_style('memberlite_print_style', get_template_directory_uri() . "/css/print.css", array(), MEMBERLITE_VERSION, "print");
wp_enqueue_script('memberlite-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), MEMBERLITE_VERSION, true);
wp_enqueue_script('memberlite-script', get_template_directory_uri() . '/js/memberlite.js', array( 'jquery' ), MEMBERLITE_VERSION, true);
wp_enqueue_script('memberlite-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array( 'jquery' ), MEMBERLITE_VERSION, true);
wp_enqueue_style('memberlite_fontawesome', get_template_directory_uri() . "/font-awesome/css/font-awesome.min.css", array(), "4.6.1");
//load dark.css for dark/inverted backgrounds
$memberlite_darkcss = get_theme_mod('memberlite_darkcss',$memberlite_defaults['memberlite_darkcss'],false);
if( !empty($memberlite_darkcss) )
{
wp_enqueue_style('memberlite_darkcss', get_template_directory_uri() . "/css/dark.css", array(), MEMBERLITE_VERSION);
}
//comments JS on single pages only
if ( is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
}
add_action('wp_enqueue_scripts', 'memberlite_init_styles');
/* Load fonts via Google API */
function memberlite_load_fonts()
{
global $memberlite_defaults;
wp_register_style('googleFonts', '//fonts.googleapis.com/css?family=' . str_replace('_',':400,700|',str_replace('-','+',get_theme_mod('memberlite_webfonts',$memberlite_defaults['memberlite_webfonts']))) . ':400,700');
wp_enqueue_style('googleFonts');
}
add_action('wp_print_styles', 'memberlite_load_fonts');
/* Set the content width based on the theme's design and stylesheet. */
if(!isset($content_width)) {
$content_width = 748; /* pixels */
}
/* Adjust the content width based on the template. */
function memberlite_adjust_content_width() {
global $content_width;
if ( is_page_template( 'templates/full-width.php' ) || is_page_template( 'templates/fluid-width.php' ) )
$content_width = 1170; /* pixels */
}
add_action( 'template_redirect', 'memberlite_adjust_content_width' );
if(!function_exists('memberlite_setup')) :
/* Sets up theme defaults and registers support for various WordPress features. */
function memberlite_setup() {
/*
* Make theme available for translation.
* If you're building a theme based on Memberlite, use a find and replace
* to change 'memberlite' to the name of your theme in all the template files
*/
load_theme_textdomain('memberlite');
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
// Add document title tag to HTML
add_theme_support('title-tag');
// Add logo upload support via Customizer
add_theme_support( 'custom-logo', array(
'height' => 100,
'width' => 360,
'flex-width' => true,
'header-text' => array( 'site-title', 'site-description' ),
) );
// Enable support for Post Thumbnails on posts and pages.
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 150, 150, true );
add_image_size('mini', 80, 80, true, array('center','center'));
add_image_size('banner', 793, 200, true, array('center','center'));
add_image_size('fullwidth', 1170, 1200, false, array('center','center'));
add_image_size('masthead', 1600, 300, true, array('center','center'));
// This theme uses wp_nav_menu() in four locations.
register_nav_menus( array(
'primary' => __('Primary Menu', 'memberlite'),
'member' => __('Member Menu', 'memberlite'),
'meta' => __('Meta Menu', 'memberlite'),
'footer' => __('Footer Menu', 'memberlite'),
));
// Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support('html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
));
// Enables support for Post Formats.
add_theme_support('post-formats', array(
'audio', 'image', 'link', 'quote', 'status', 'video',
));
// Setup the WordPress core custom background feature.
add_theme_support('custom-background', apply_filters('memberlite_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
)));
// Styles the visual editor to resemble the theme style
add_editor_style( array( 'css/editor-style.css') );
// Enable the use of shortcodes in text widgets.
add_filter( 'widget_text', 'do_shortcode' );
// Indicate widget sidebars can use selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif; // memberlite_setup
add_action('after_setup_theme', 'memberlite_setup');
/* Register widget areas */
function memberlite_widgets_init() {
global $memberlite_defaults;
register_sidebar( array(
'name' => __('Posts and Archives', 'memberlite'),
'id' => 'sidebar-2',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar( array(
'name' => __('Pages', 'memberlite'),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar( array(
'name' => __('Header Right', 'memberlite'),
'id' => 'sidebar-3',
'description' => '',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
));
$footer_widgets_count = get_theme_mod('memberlite_footerwidgets',$memberlite_defaults['memberlite_footerwidgets']);
if($footer_widgets_count == '2')
$footer_widgets_col_class = 'medium-6';
elseif($footer_widgets_count == '3')
$footer_widgets_col_class = 'medium-4';
elseif($footer_widgets_count == '6')
$footer_widgets_col_class = 'large-3';
else
$footer_widgets_col_class = 'medium-3';
register_sidebar( array(
'name' => __('Footer Widgets', 'memberlite'),
'id' => 'sidebar-4',
'description' => 'You can set the number of widget columns in Appearance > Customize. Default: 4 columns.',
'before_widget' => '<aside id="%1$s" class="widget ' . $footer_widgets_col_class . ' columns %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
register_sidebar( array(
'name' => __('Mobile Menu Widgets', 'memberlite'),
'id' => 'sidebar-5',
'description' => 'The slide-out mobile menu area.',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
));
}
add_action('widgets_init', 'memberlite_widgets_init');
/* Adds a Log Out link in member menu */
function memberlite_menus( $items, $args ) {
//is this the member menu location or a replaced menu using pmpro-nav-menus plugin
if ($args->theme_location == 'member' || ( strpos($args->theme_location, '-member') !== false ) ) {
if (is_user_logged_in() && defined('PMPRO_VERSION') && pmpro_hasMembershipLevel())
{
//user is logged in and has a membership level
$items .= '<li><a href="'. wp_logout_url() .'">' . __('Log Out','memberlite') . '</a></li>';
}
elseif (is_user_logged_in() )
{
//user is logged in and does not have a membership level
$items = '<li><a href="'. wp_logout_url() .'">' . __('Log Out','memberlite') . '</a></li>';
}
else
{
//not logged in
$items = '<li><a href="'. wp_login_url() .'">' . __('Log In','memberlite') . '</a></li>';
$items .= '<li><a href="'. wp_registration_url() .'">' . __('Register','memberlite') . '</a></li>';
}
}
//is this the primary menu location or a replaced menu using pmpro-nav-menus plugin
if ($args->theme_location == 'primary' || ( strpos($args->theme_location, '-primary') !== false ) ) {
$nav_menu_search = get_theme_mod( 'nav_menu_search', false );
if(!empty($nav_menu_search))
$items .= get_search_form(false);
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'memberlite_menus', 10, 2 );
function memberlite_member_menu_cb( $args )
{
extract( $args );
if(empty($link_before))
$link_before = '<li class="menu_item">';
if(empty($link_after))
$link_after = '</li>';
if (is_user_logged_in())
$link = $link_before . '<a href="'. wp_logout_url() .'">' . $before . __('Log Out','memberlite') . $after . '</a>';
else
{
$link = $link_before . '<a href="'. wp_login_url() .'">' . $before . __('Log In','memberlite') . $after . '</a>';
$link .= $link_before . '<a href="'. wp_registration_url() .'">' . $before . __('Register','memberlite') . $after . '</a>' . $link_after;
}
$output = sprintf( $items_wrap, $menu_id, $menu_class, $link );
if(!empty($container))
{
$output = "<$container class='$container_class' id='$container_id'>$output</$container>";
}
if($echo)
{
echo $output;
}
return $output;
}
function memberlite_wp_nav_menu( $menu ) {
return do_shortcode( $menu );
}
add_filter('wp_nav_menu', 'memberlite_wp_nav_menu');
/* Exclude pings and trackbacks from the number of comments on a post. */
function memberlite_comment_count( $count ) {
global $id;
$comment_count = 0;
$comments = get_approved_comments( $id );
foreach ( $comments as $comment ) {
if ( $comment->comment_type === '' ) {
$comment_count++;
}
}
return $comment_count;
}
add_filter( 'get_comments_number', 'memberlite_comment_count', 0 );
/* Check for updates */
if(is_admin()) {
require_once get_template_directory() . '/inc/updates.php';
memberlite_checkForUpdates();
}
/* Custom admin theme pages. */
if(is_admin())
require_once get_template_directory() . '/inc/admin.php';
/* Implement the Custom Header feature. */
require_once get_template_directory() . '/inc/custom-header.php';
/* Custom sidebars pages. */
require_once get_template_directory() . '/inc/custom-sidebars.php';
/* Customizer additions. */
require_once get_template_directory() . '/inc/customizer.php';
/* Custom functions that act independently of the theme templates. */
require_once get_template_directory() . '/inc/extras.php';
/* Load Jetpack compatibility file. */
require_once get_template_directory() . '/inc/jetpack.php';
/* Custom template tags. */
require_once get_template_directory() . '/inc/template-tags.php';
/* Custom meta boxes. */
if(is_admin())
require_once get_template_directory() . '/inc/metaboxes.php';
/* Custom widgets that act independently of the theme templates. */
require_once get_template_directory() . '/inc/widgets.php';
/* Integration for Paid Memberships Pro. */
if(defined('PMPRO_VERSION'))
require_once get_template_directory() . '/inc/integrations/paid-memberships-pro.php';
/* Integration for WooCommerce. */
if(function_exists('is_woocommerce'))
require_once get_template_directory() . '/inc/integrations/woocommerce.php';