This repository has been archived by the owner on Jul 16, 2020. It is now read-only.
forked from thomasgriffin/theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
351 lines (275 loc) · 9.83 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
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
<?php
if ( ! defined( 'PP_THEME_VERSION' ) )
define( 'PP_THEME_VERSION', '1.2.2' );
if ( ! defined( 'PP_INCLUDES_DIR' ) )
define( 'PP_INCLUDES_DIR', trailingslashit( get_template_directory() ) . 'includes' ); /* Sets the path to the theme's includes directory. */
/**
* Includes
* @since 1.0
*/
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'masthead.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'scripts.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'page-mods.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'sharing.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'gforms.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'ajax-functions.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'navigation.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'template-tags.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'testimonials.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'affiliatewp.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'gallery.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'functions.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'comment.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'checkout.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'banners.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'custom-filters.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'blog.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'restrict-content-pro.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'notices.php' );
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'countdown.php' );
if ( class_exists( 'Easy_Digital_Downloads' ) ) {
require_once( trailingslashit( PP_INCLUDES_DIR ) . 'edd.php' );
}
/**
* Set up the content width value based on the theme's design.
*
* @since 1.0
*/
if ( ! isset( $content_width ) ) {
$content_width = 592;
}
if ( ! function_exists( 'pp_setup' ) ) :
/**
* Setup.
*
* Set up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support post thumbnails.
*
* @since 1.0
*/
function pp_setup() {
load_theme_textdomain( 'pp', get_template_directory() . '/languages' );
// Add RSS feed links to <head> for posts and comments.
add_theme_support( 'automatic-feed-links' );
// add post format support
add_theme_support( 'post-formats', array( 'video' ) );
add_post_type_support( 'page', 'excerpt' );
// Enable support for Post Thumbnails, and declare two sizes.
add_theme_support( 'post-thumbnails' );
// set_post_thumbnail_size( 672, 372, true );
add_image_size( 'pp-full-width', 1038, 576, true );
add_image_size( 'pp-grid-thumbnail', 480, 240, true );
add_image_size( 'pp-large', 592, 296, true );
register_nav_menus( array(
'primary' => __( 'Primary menu', 'pp' ),
'footer' => __( 'Footer menu', 'pp' ),
'useful_links' => __( 'Useful links', 'pp' ),
) );
/*
* 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'
) );
// This theme uses its own gallery styles.
add_filter( 'use_default_gallery_style', '__return_false' );
}
endif; // pp_setup
add_action( 'after_setup_theme', 'pp_setup' );
/**
* Filter menu and add 'has-sub-menu' class to parent
*
* @since 1.0
*/
function pp_add_has_sub_menu_parent_class( $items ) {
$parents = array();
foreach ( $items as $item ) {
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
}
foreach ( $items as $item ) {
if ( in_array( $item->ID, $parents ) ) {
$item->classes[] = 'has-sub-menu';
}
}
return $items;
}
add_filter( 'wp_nav_menu_objects', 'pp_add_has_sub_menu_parent_class' );
/**
* Remove unwanted class names from homepage
*/
function pp_remove_body_classes( $wp_classes, $extra_classes ) {
$blacklist = array( 'blog' );
$wp_classes = array_diff( $wp_classes, $blacklist );
// Add the extra classes back untouched
return array_merge( $wp_classes, (array) $extra_classes );
}
add_filter( 'body_class', 'pp_remove_body_classes', 10, 2 );
/**
* Adds custom classes to the array of body classes.
*
* @since 1.0
*/
function pp_body_classes( $classes ) {
global $post;
// Adds a class of 'has-featured-image' if the current post has a featured image
if ( isset( $post->ID ) && get_the_post_thumbnail( $post->ID ) )
$classes[] = 'has-featured-image';
// Adds a class of group-blog to blogs with more than 1 published author
if ( is_multi_author() )
$classes[] = 'group-blog';
// Adds a class of 'blog' if the blog template is being used. The homepage when used as a blog also has this class already
if ( is_page_template( 'page-templates/blog.php' ) )
$classes[] = 'blog';
if ( is_page_template( 'page-templates/testimonials.php' ) )
$classes[] = 'testimonials';
if ( is_post_type_archive( 'download' ) )
$classes[] = 'products';
if ( is_page_template( 'page-templates/assets-and-banners.php' ) )
$classes[] = 'assets-and-banners';
if ( is_page_template( 'page-templates/brand-assets.php' ) )
$classes[] = 'brand-assets';
if ( is_page_template( 'page-templates/full-width.php' ) )
$classes[] = 'full-width';
if ( is_page_template( 'page-templates/pricing.php' ) )
$classes[] = 'pricing';
if ( is_page_template( 'page-templates/join-the-site.php' ) )
$classes[] = 'join';
if ( is_page( 'register' ) )
$classes[] = 'register';
if ( is_page_template( 'page-templates/no-sidebar.php' ) )
$classes[] = 'no-sidebar';
if ( is_page_template( 'page-templates/support.php' ) )
$classes[] = 'support';
if ( is_page( 'about' ) )
$classes[] = 'about';
if ( is_user_logged_in() && isset( $post->post_content ) && has_shortcode( $post->post_content, 'purchase_history' ) )
$classes[] = 'purchase-history';
if ( is_page_template( 'page-templates/changelog.php' ) )
$classes[] = 'changelog';
if ( wp_unslash( site_url('/') ) == wp_get_referer() )
$classes[] = 'from-home';
if ( function_exists('edd_get_cart_contents') && edd_get_cart_contents() ) {
$classes[] = 'edd-items-in-cart';
}
if ( function_exists( 'edd_is_success_page' ) && edd_is_success_page() )
$classes[] = 'purchase-confirmation';
if ( is_page_template( 'page-templates/account.php' ) ) {
$classes[] = 'account';
if ( ! is_user_logged_in() ) {
$classes[] = 'account-logged-out';
}
else {
$classes[] = 'account-logged-in';
}
}
if ( is_page_template( 'page-templates/affiliates.php' ) )
$classes[] = 'affiliates';
return $classes;
}
add_filter( 'body_class', 'pp_body_classes' );
/**
* Register sidebars
*
* @since 1.0
*
* @return void
*/
function pp_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Sidebar', 'pp' ),
'id' => 'sidebar-1',
'description' => __( 'Main sidebar', 'pp' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'About', 'pp' ),
'id' => 'sidebar-about',
'description' => __( 'About sidebar', 'pp' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'pp_widgets_init' );
/**
* Create a nicely formatted and more specific title element text for output
* in head of document, based on current view.
*
* @since AffiliateWP 1.0
*
* @param string $title Default title text for current view.
* @param string $sep Optional separator.
* @return string The filtered title.
*/
function pp_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() ) {
return $title;
}
// Add the site name.
$title .= get_bloginfo( 'name' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'pp' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'pp_wp_title', 10, 2 );
function pp_edd_optimizely_revenue_tracking() {
if( ! function_exists( 'edd_get_purchase_session' ) ) {
return;
}
$session = edd_get_purchase_session();
if( ! $session ) {
return;
}
$payment_id = edd_get_purchase_id_by_key( $session['purchase_key'] );
?>
<script>
var price = <?php echo edd_get_payment_amount( $payment_id ); ?>
window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', 'purchase_complete', {'revenue': price * 100}]);
</script>
<?php
}
add_action( 'wp_head', 'pp_edd_optimizely_revenue_tracking');
/**
* Redirect to correct tab when profile is updated
*/
function pp_rcp_profile_updated( $user_id, $userdata ) {
wp_safe_redirect( add_query_arg( 'updated', 'true', sanitize_text_field( $_POST['rcp_redirect'] ) . '#tabs=3' ) );
exit;
}
add_action( 'rcp_user_profile_updated', 'pp_rcp_profile_updated', 10, 2 );
/**
* Remove the license keys column
*/
remove_action( 'edd_purchase_history_row_end', 'edd_sl_site_management_links', 10 );
remove_action( 'edd_purchase_history_header_after', 'edd_sl_add_key_column' );
/**
* Get ID of RCP based on title
*
*/
function pp_get_rcp_download_id() {
$download = get_page_by_title( 'Restrict Content Pro', OBJECT, 'download' );
$download_id = $download->ID;
if ( $download_id ) {
return $download_id;
}
return false;
}