| 1 |
<?php |
| 2 |
|
| 3 |
$redirect_url = wppb_toolbox_get_settings( 'fields', 'redirect-if-empty-required-url' ); |
| 4 |
|
| 5 |
if ( !empty( $redirect_url ) ) |
| 6 |
add_action( 'template_redirect', 'wppb_toolbox_redirect_if_empty_required' ); |
| 7 |
|
| 8 |
function wppb_toolbox_redirect_if_empty_required() { |
| 9 |
if ( current_user_can( 'manage_options' ) ) |
| 10 |
return; |
| 11 |
|
| 12 |
$user_id = get_current_user_id(); |
| 13 |
$current_url = wppb_curpageurl(); |
| 14 |
$redirect_url = get_permalink( wppb_toolbox_get_settings( 'fields', 'redirect-if-empty-required-url' ) ); |
| 15 |
|
| 16 |
if ( !empty( $user_id ) && ( $current_url != $redirect_url ) && apply_filters( 'wppb_toolbox_redirect_if_empty_required', true, $user_id, $current_url, $redirect_url ) ) { |
| 17 |
|
| 18 |
$fields = get_option( 'wppb_manage_fields', array() ); |
| 19 |
$without_meta_name = array( 'user_url' => 'Default - Website', 'display_name' => 'Default - Display name publicly as' ); |
| 20 |
|
| 21 |
foreach ( $fields as $field ){ |
| 22 |
|
| 23 |
if ( $field['required'] == 'Yes' && !empty( $field['meta-name'] ) ){ |
| 24 |
|
| 25 |
if( $field['meta-name'] == 'map' ) |
| 26 |
$value = wppb_get_user_map_markers( $user_id, $field['meta-name'] ); |
| 27 |
else |
| 28 |
$value = get_user_meta( $user_id, $field['meta-name'], true ); |
| 29 |
|
| 30 |
if ( empty( $value ) ){ |
| 31 |
wp_redirect( $redirect_url ); |
| 32 |
exit(); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
if( $field['required'] == 'Yes' && ( $field['field'] == 'Default - Website' || $field['field'] == 'Default - Display name publicly as' ) ){ |
| 37 |
$user = get_userdata( $user_id ); |
| 38 |
|
| 39 |
$key = array_search( $field['field'], $without_meta_name ); |
| 40 |
$value = $user->$key; |
| 41 |
|
| 42 |
if ( empty( $value ) ){ |
| 43 |
wp_redirect( $redirect_url ); |
| 44 |
exit(); |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|