Skip to content

Instantly share code, notes, and snippets.

@tnorthcutt
Last active December 27, 2017 15:38
Show Gist options
  • Select an option

  • Save tnorthcutt/63335776e60bc1f993d6768bae999551 to your computer and use it in GitHub Desktop.

Select an option

Save tnorthcutt/63335776e60bc1f993d6768bae999551 to your computer and use it in GitHub Desktop.
Don't show meal plans older than (sign up date + 1 week)
<?php
/**
* Don't show meal plans older than (sign up date + 1 week)
* @since 1.0.0
*
* @author Travis Northcutt
*
*/
function gfmp_show_allowed_meal_plans( $query ) {
// First, make sure we're on the front end and on the right archive view
if ( $query->is_main_query() && !is_admin() && is_post_type_archive( 'meal-plan' ) ) {
// Get the number of days a member has been a member
$days_as_member = mm_member_data( array( 'name' => 'daysAsMember' ) );
// We only want posts as old as a member, plus up to seven days
$days_ago = ( $days_as_member + 7 ) . ' days ago';
// Set our query parameters
$date_query = array(
array(
'after' => $days_ago
)
);
// Alter the query
$query->set( 'date_query', $date_query );
// If no posts returned, filter the message displayed
add_filter( 'genesis_noposts_text', 'gfmp_noplans_text' );
}
}
add_action( 'pre_get_posts', 'gfmp_show_allowed_meal_plans' );
/**
* Alter the message displayed if no meal plans found
*
* If user is logged in, apologize and direct to the contact form
*
* If not logged in, display login form + link to join
*
* @since 1.0.0
*
* @author Travis Northcutt
*
*/
function gfmp_noplans_text() {
if ( is_user_logged_in() ) {
return 'Sorry, we seem to have a slight problem. Please <a href="/contact">send us a quick message</a> and we\'ll help you out. Thanks!';
}
else {
$login_form = '<form action="/wp-login.php" method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" id="log" name="log" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" id="pwd" name="pwd" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Login" />
<input name="rememberme" type="checkbox" checked="checked" value="forever" />
Remember me
</td>
</tr>
<tr>
<td></td>
<td>
<a href="[your forgot password page here]">Forgot Password</a>
</td>
</tr>
</table>
</form>';
return 'Sorry, you seem to not be logged in. You can do that below. If you\'re not a member yet, check out our <a href="/membership-options">membership options.</a>' . $login_form;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment