Created
June 2, 2020 20:45
-
-
Save BinaryMoon/fe2c163e3c5ddd196cce18ba02e214bf to your computer and use it in GitHub Desktop.
Disable 'more posts' list in footer of Lens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Lens disable more posts on . | |
* Plugin URI: https://prothemedesign.com | |
* Description: Disable Lens 'more posts' functionality for logged out users. | |
* Author: Ben Gillbanks | |
* Version: 1.0 | |
* Author URI: https://prothemedesign.com | |
* | |
* @package ptd | |
*/ | |
/** | |
* If a user is logged out then hide the more posts content. | |
*/ | |
function lens_disable_more_posts_logged_out( $amount ) { | |
if ( is_user_logged_in() ) { | |
return $amount; | |
} | |
return 'disable'; | |
} | |
add_filter( 'lens_more_posts_quantity', 'lens_disable_more_posts_logged_out' ); | |
/** | |
* Disable footer 'more posts' if the query is set correctly. | |
*/ | |
function lens_more_posts_pre_get_posts( $query ) { | |
if ( 'disable' === $query->query[ 'posts_per_page' ] ) { | |
// Set the category to an unlikely number. Not foolproof but should be fine. | |
$query->set( 'cat', 9999999999999 ); | |
} | |
} | |
add_action( 'pre_get_posts', 'lens_more_posts_pre_get_posts' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment