Created
March 31, 2016 16:56
-
-
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.
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: 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; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wpmem_block() was deprecated in plugin version 3.1 and removed in 3.2. Use wpmem_is_blocked() instead.