generated from asuengineering/pitchfork-child
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·54 lines (42 loc) · 1.63 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
<?php
/**
* Pitchfork child theme functions
*
* @package pitchfork-child
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require get_stylesheet_directory() . '/inc/enqueue-assets.php';
require get_stylesheet_directory() . '/inc/gravityforms.php';
// Shortcode to display current logged in user.
// Also updates the user's details from the ASU Search API while they are here.
function pitchfork_show_loggedin_user( $atts ) {
global $user_login;
$current_user = wp_get_current_user();
$userwelcome = '';
$userwelcome .= '<div class="user-profile"><img class="user_avatar" src="' . esc_url( get_avatar_url( $current_user->ID, ['size' => '150'] ) ) . '" />';
$userwelcome .= '<p><strong>' . $current_user->display_name . '</strong><br/>ASURite: ' . $current_user->user_login . '</p></div>';
if ( $user_login ) {
return $userwelcome;
} else {
return '<a class="btn btn-maroon mb-4" href="/wp-login.php">Register as a user</a>';
}
}
add_shortcode( 'show_loggedin_user', 'pitchfork_show_loggedin_user' );
// Redirect non-logged in users away from the request form page.
// Targets a page with the slug of "request".
add_action( 'template_redirect', 'pitchfork_redirect_away_from_request_form' );
function pitchfork_redirect_away_from_request_form() {
if ( is_page('request') && ! is_user_logged_in() ) {
wp_redirect( home_url(), 301 );
exit;
}
}
// Redirect users who just logged in back to the request form.
// Request form should be a page with the slug of "request"
add_filter('login_redirect', 'pitchfork_custom_login_redirect');
function pitchfork_custom_login_redirect() {
return '/request';
}