Skip to content

Instantly share code, notes, and snippets.

@v-skochko
Created March 31, 2017 12:52
Show Gist options
  • Select an option

  • Save v-skochko/56296ae7302a9ed6a7987a48f3e0df88 to your computer and use it in GitHub Desktop.

Select an option

Save v-skochko/56296ae7302a9ed6a7987a48f3e0df88 to your computer and use it in GitHub Desktop.
<?php
$f_key = "course_cat_" . $cur_term->term_id;
the_field( 'password_protection', $f_key );
$passwd = isset( $_REQUEST['passwd'] ) ? $_REQUEST['passwd'] : null;
$admin_passwd = get_field( 'password_protection', $f_key );
$cookie = isset( $_SESSION['re_passwd'] ) ? $_SESSION['re_passwd'] : null;
if ( empty( $cookie ) ) {
if ( $passwd == $admin_passwd ) {
$_SESSION['re_passwd'] = $passwd;
echo '
<script>window.location.reload();</script>';
}
}
if ( empty( $cookie ) || $cookie !== $admin_passwd ) {
if ( ! empty( $passwd ) && ( $passwd !== $admin_passwd ) ) {
echo '<h3 class="passwd_wrong">' . __( 'Wrong password!' ) . '</h3>';
}
echo '
<form action="" method="post" class="re_passwd">
<input name="passwd" type="password" placeholder="' . __( 'Enter password' ) . '"/>
<input type="submit" value="' . __( 'Submit' ) . '">
</form>';
echo get_field( 'password_protection_desc' ) ?
'
<article class="re_desc">' . get_field( 'password_protection_desc' ) . '</article>'
: '';
} else {
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment