This repository has been archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
template-content-only.php
104 lines (71 loc) · 2.75 KB
/
template-content-only.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
<?php
/**
* Template Name: WPCampus: Content Only
*/
global $post;
// Hide the admin bar.
add_filter( 'show_admin_bar', '__return_false' );
function wpcampus_content_only_assets() {
// Load the counter part to the iframe resizer.
wp_enqueue_script( 'wpc-iframe-resizer', trailingslashit( get_stylesheet_directory_uri() ) . 'assets/js/iframeResizer.contentWindow.min.js', array(), null );
}
add_action( 'wp_enqueue_scripts', 'wpcampus_content_only_assets', 20 );
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?> style="margin:0!important;padding:0!important;">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php wp_title( '-', true, 'left' ); ?></title>
<?php
wp_head();
wpcampus_add_document();
?>
</head>
<body <?php body_class(); ?>>
<?php
function wpcampus_print_login_message( $post_id, $key ) {
$message = get_post_meta( $post_id, $key, true );
if ( empty( $message ) ) {
return;
}
// Remove all but allowed tags.
$message = strip_tags( $message, '<a><ul><ol><li><em><strong><div><span><button><h2><h3><h4><h5><h6><br>' );
if ( empty( $message ) ) {
return;
}
echo wpautop( $message );
}
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
$require_login = get_post_meta( $post->ID, 'wpcampus_require_login', true );
$is_user_logged_in = is_user_logged_in();
if ( ! $is_user_logged_in && $require_login ) :
wpcampus_print_login_message( $post->ID, 'wpcampus_require_login_message_pre' );
?>
<h2>Login to WPCampus</h2>
<?php
wpcampus_print_login_message( $post->ID, 'wpcampus_require_login_message' );
wp_login_form();
wpcampus_print_login_message( $post->ID, 'wpcampus_require_login_message_post' );
else :
if ( $is_user_logged_in && $require_login ) :
$current_user = wp_get_current_user();
$current_user_edit_url = get_edit_user_link( $current_user->ID );
?>
<p class="wpcampus-login-status">
<a class="button wpcampus-login-status__button wpcampus-login-status__button--logout" href="<?php echo wp_logout_url( get_permalink() ); ?>" title="<?php printf( esc_attr__( 'Log out of your %s account', 'wpcampus' ), 'WPCampus' ); ?>"><?php _e( 'Logout', 'wpcampus' ); ?></a>
<span class="wpcampus-login-status__message"><?php printf( __( 'You are logged-in as %1$s%2$s%3$s.', 'wpcampus' ), '<strong>', $current_user->get( 'display_name' ), '</strong>' ); ?> <a href="<?php echo esc_url( $current_user_edit_url ); ?>" target="_blank">Edit your profile</a></span>
</p>
<?php
endif;
the_content();
endif;
endwhile;
endif;
wp_footer();
?>
</body>
</html>