bueltge
3/31/2016 - 4:56 PM

WP Members Add-on, that block read access for the role Author after login.

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;
} );