um_custom_restriction
Hook type
Filter
Description
Restrict a page/post for logged in users by custom logic.
Parameters
$custom_restriction
(bool) Custom Restriction
$restriction
(array) Restriction settings
Usage
add_filter( 'um_custom_restriction', 'function_name', 10, 2 );
Examples
Example - Basic usage
<?php add_filter( 'um_custom_restriction', 'my_custom_restriction', 10, 2 ); function my_custom_restriction( $custom_restriction, $restriction ) { // your code here return $custom_restriction; } ?>
Example - Restrict a page/post by user meta
<?php add_filter( 'um_custom_restriction', 'my_custom_restriction', 10, 2 ); function my_custom_restriction( $custom_restriction, $restriction ) { /* Set needed meta key and value here */ $meta_key = 'um_ut_interests'; $meta_value = 21; $value = get_user_meta( get_current_user_id(), $meta_key, true ); if ( is_array( $value ) && !in_array( $meta_value, $value ) ) { $custom_restriction = false; } elseif ( !is_array( $value ) && $value != $meta_value ) { $custom_restriction = false; } return $custom_restriction; } ?>
Change Log
Since: 2.0
Source
um_custom_restriction
is located in includes/core/class-access.php::line 112