Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Last active March 2, 2017 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/502f748635d67a7ab74d3c3f743102f6 to your computer and use it in GitHub Desktop.
Save pbrocks/502f748635d67a7ab74d3c3f743102f6 to your computer and use it in GitHub Desktop.
PMPro Diagnostic
add_action( 'wp_head', 'pbrx_temp_css' );
function pbrx_temp_css() {
?>
<style>
.head-diagnostic {
text-align: center;
}
.positive {
color: green;
}
.negative {
color: salmon;
}
</style>
<?php
}
add_action( 'wp_head', 'pbrx_check_user', 20 );
function pbrx_check_user( $user ) {
global $current_user, $post;
$current_user->membership_level = pmpro_getMembershipLevelForUser( $current_user->ID );
$name = $current_user->display_name;
$cutoff = strtotime( '-30 Days', current_time( 'timestamp' ) );
$published = strtotime( $post->post_date );
if ( is_user_logged_in() ) {
echo '<h3 class="head-diagnostic positive">Welcome, ' . $current_user->membership_level->name . ' user, ' . $name . ' !<br> cutoff = ' . date( 'Y-m-d', $cutoff ) . '<br> published = ' . date( 'Y-m-d', $published ) .'</h3>';
} else {
echo '<h3 class="head-diagnostic negative">Welcome, visitor!</h3>';
return;
}
if ( $cutoff > $published ) {
echo '<h3 class="head-diagnostic negative">Flag this post</h3>';
return true;
} else {
echo '<h3 class="head-diagnostic positive">Show this post</h3>';
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment