Skip to content

Instantly share code, notes, and snippets.

@bueltge
Created March 31, 2016 16:56
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 bueltge/9fb34ee51b76109d1d31cf77d8d87eb3 to your computer and use it in GitHub Desktop.
Save bueltge/9fb34ee51b76109d1d31cf77d8d87eb3 to your computer and use it in GitHub Desktop.
WP Members Add-on, that block read access for the role Author after login.
<?php
/**
* Plugin Name: WP Members Add-on, Change Read Access for role author
*/
! defined( 'ABSPATH' ) && exit;
register_activation_hook( __FILE__, function() {
if ( ! function_exists( 'wpmem_block' ) ) {
deactivate_plugins( __FILE__ );
wp_die(
esc_attr__( 'Sorry, This plugin requires the WP Members plugin' )
);
}
} );
/**
* @param $content
*
* @return string|void
*/
add_filter( 'wpmem_securify', function( $content ) {
if ( ! is_user_logged_in() ) {
return $content;
}
if ( current_user_can( 'administrator' ) ) {
return $content;
}
if ( current_user_can( 'author' ) && wpmem_block() ) {
// Get dialogs set in the DB.
$message = get_option( 'wpmembers_dialogs' );
// Fallback fro restricted message in the array.
if ( ! isset( $message[0] ) || empty( $message[0] ) ) {
esc_attr__( 'Sorry, you do not have access to this post.' );
}
// Return custom excerpt from WP Members + restricted message.
return wpmem_do_excerpt( $content ) . '</p><p>' . stripslashes( $message[0] );
}
return $content;
} );
@butlerblog
Copy link

wpmem_block() was deprecated in plugin version 3.1 and removed in 3.2. Use wpmem_is_blocked() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment