add_filter( "wp", "loggedin_members_only_init", 50 );
function loggedin_members_only_init() {
if( is_singular( 'advert' ) && get_current_user_id() < 1 ) {
remove_action( 'adverts_tpl_single_bottom', 'adverts_single_contact_information' );
remove_action( 'adverts_tpl_single_bottom', 'adext_contact_form' );
remove_action( 'adverts_tpl_single_bottom', 'adext_bp_send_private_message_button', 50 );
add_action( 'adverts_tpl_single_bottom', "loggedin_members_only", 5 );
}
}
function loggedin_members_only( $post_id ) {
$flash = array( "error" => array(), "info" => array(), "warn" => array() );
$flash["warn"][] = array(
"message" => sprintf( "Only logged-in user can contact sellers. <a href=\"%s\">Login</a> or <a href=\"%s\">Register</a>", wp_login_url( get_permalink( get_the_ID() ) ), wp_registration_url() ),
"icon" => "adverts-icon-block"
);
adverts_flash( $flash );
}