3276 | | return array( |
3277 | | 'activity-comment' => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ), |
3278 | | 'activity-comment-author' => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ), |
3279 | | 'activity-at-message' => __( 'Recipient was mentioned in an activity update.', 'buddypress' ), |
3280 | | 'groups-at-message' => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ), |
3281 | | 'core-user-registration' => __( 'Recipient has registered for an account.', 'buddypress' ), |
3282 | | 'core-user-registration-with-blog' => __( 'Recipient has registered for an account and site.', 'buddypress' ), |
3283 | | 'friends-request' => __( 'A member has sent a friend request to the recipient.', 'buddypress' ), |
3284 | | 'friends-request-accepted' => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ), |
3285 | | 'groups-details-updated' => __( "A group's details were updated.", 'buddypress' ), |
3286 | | 'groups-invitation' => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ), |
3287 | | 'groups-member-promoted' => __( "Recipient's status within a group has changed.", 'buddypress' ), |
3288 | | 'groups-membership-request' => __( 'A member has requested permission to join a group.', 'buddypress' ), |
3289 | | 'messages-unread' => __( 'Recipient has received a private message.', 'buddypress' ), |
3290 | | 'settings-verify-email-change' => __( 'Recipient has changed their email address.', 'buddypress' ), |
3291 | | 'groups-membership-request-accepted' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ), |
3292 | | 'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ), |
| 3277 | |
| 3278 | $activity_comment = array( |
| 3279 | 'description' => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ), |
| 3280 | 'unsubscribe' => array( |
| 3281 | 'meta_key' => 'notification_activity_new_reply', |
| 3282 | 'message' => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ), |
| 3283 | ) |
| 3285 | |
| 3286 | $activity_comment_author = array( |
| 3287 | 'description' => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ), |
| 3288 | 'unsubscribe' => array( |
| 3289 | 'meta_key' => 'notification_activity_new_reply', |
| 3290 | 'message' => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ), |
| 3291 | ) |
| 3292 | ); |
| 3293 | |
| 3294 | $activity_at_message = array( |
| 3295 | 'description' => __( 'Recipient was mentioned in an activity update.', 'buddypress' ), |
| 3296 | 'unsubscribe' => array( |
| 3297 | 'meta_key' => 'notification_activity_new_mention', |
| 3298 | 'message' => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ), |
| 3299 | ) |
| 3300 | ); |
| 3301 | |
| 3302 | $groups_at_message = array( |
| 3303 | 'description' => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ), |
| 3304 | 'unsubscribe' => array( |
| 3305 | 'meta_key' => 'notification_activity_new_mention', |
| 3306 | 'message' => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ), |
| 3307 | ) |
| 3308 | ); |
| 3309 | |
| 3310 | $core_user_registration = array( |
| 3311 | 'description' => __( 'Recipient has registered for an account.', 'buddypress' ), |
| 3312 | 'unsubscribe' => false |
| 3313 | ); |
| 3314 | |
| 3315 | $core_user_registration_with_blog = array( |
| 3316 | 'description' => __( 'Recipient has registered for an account and site.', 'buddypress' ), |
| 3317 | 'unsubscribe' => false |
| 3318 | ); |
| 3319 | |
| 3320 | $friends_request = array( |
| 3321 | 'description' => __( 'A member has sent a friend request to the recipient.', 'buddypress' ), |
| 3322 | 'unsubscribe' => array( |
| 3323 | 'meta_key' => 'notification_friends_friendship_request', |
| 3324 | 'message' => __( 'You will no longer receive emails when someone sends you a friend request.', 'buddypress' ), |
| 3325 | ) |
| 3326 | ); |
| 3327 | |
| 3328 | $friends_request_accepted = array( |
| 3329 | 'description' => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ), |
| 3330 | 'unsubscribe' => array( |
| 3331 | 'meta_key' => 'notification_friends_friendship_accepted', |
| 3332 | 'message' => __( 'You will no longer receive emails when someone accepts your friendship request.', 'buddypress' ), |
| 3333 | ) |
| 3334 | ); |
| 3335 | |
| 3336 | $groups_details_updated = array( |
| 3337 | 'description' => __( "A group's details were updated.", 'buddypress' ), |
| 3338 | 'unsubscribe' => array( |
| 3339 | 'meta_key' => 'notification_groups_group_updated', |
| 3340 | 'message' => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ), |
| 3341 | ) |
| 3342 | ); |
| 3343 | |
| 3344 | $groups_details_updated = array( |
| 3345 | 'description' => __( "A group's details were updated.", 'buddypress' ), |
| 3346 | 'unsubscribe' => array( |
| 3347 | 'meta_key' => 'notification_groups_group_updated', |
| 3348 | 'message' => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ), |
| 3349 | ) |
| 3350 | ); |
| 3351 | |
| 3352 | $groups_invitation = array( |
| 3353 | 'description' => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ), |
| 3354 | 'unsubscribe' => array( |
| 3355 | 'meta_key' => 'notification_groups_invite', |
| 3356 | 'message' => __( 'You will no longer receive emails when you are invited to join a group.', 'buddypress' ), |
| 3357 | ) |
| 3358 | ); |
| 3359 | |
| 3360 | $groups_member_promoted = array( |
| 3361 | 'description' => __( "Recipient's status within a group has changed.", 'buddypress' ), |
| 3362 | 'unsubscribe' => array( |
| 3363 | 'meta_key' => 'notification_groups_admin_promotion', |
| 3364 | 'message' => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ), |
| 3365 | ) |
| 3366 | ); |
| 3367 | |
| 3368 | $groups_member_promoted = array( |
| 3369 | 'description' => __( "Recipient's status within a group has changed.", 'buddypress' ), |
| 3370 | 'unsubscribe' => array( |
| 3371 | 'meta_key' => 'notification_groups_admin_promotion', |
| 3372 | 'message' => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ), |
| 3373 | ) |
| 3374 | ); |
| 3375 | |
| 3376 | $groups_membership_request = array( |
| 3377 | 'description' => __( 'A member has requested permission to join a group.', 'buddypress' ), |
| 3378 | 'unsubscribe' => array( |
| 3379 | 'meta_key' => 'notification_groups_membership_request', |
| 3380 | 'message' => __( 'You will no longer receive emails when someone requests to be a member of your group.', 'buddypress' ), |
| 3381 | ) |
| 3382 | ); |
| 3383 | |
| 3384 | $messages_unread = array( |
| 3385 | 'description' => __( 'Recipient has received a private message.', 'buddypress' ), |
| 3386 | 'unsubscribe' => array( |
| 3387 | 'meta_key' => 'notification_messages_new_message', |
| 3388 | 'message' => __( 'You will no longer receive emails when someone sends you a message.', 'buddypress' ), |
| 3389 | ) |
| 3390 | ); |
| 3391 | |
| 3392 | $settings_verify_email_change = array( |
| 3393 | 'description' => __( 'Recipient has changed their email address.', 'buddypress' ), |
| 3394 | 'unsubscribe' => false |
| 3395 | ); |
| 3396 | |
| 3397 | $groups_membership_request_accepted = array( |
| 3398 | 'description' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ), |
| 3399 | 'unsubscribe' => array( |
| 3400 | 'meta_key' => 'notification_membership_request_completed', |
| 3401 | 'message' => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ), |
| 3402 | ) |
| 3403 | ); |
| 3404 | |
| 3405 | $groups_membership_request_rejected = array( |
| 3406 | 'description' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ), |
| 3407 | 'unsubscribe' => array( |
| 3408 | 'meta_key' => 'notification_membership_request_completed', |
| 3409 | 'message' => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ), |
| 3410 | ) |
| 3411 | ); |
| 3412 | |
| 3413 | $email_type_schema_array = array( |
| 3414 | 'activity-comment' => $activity_comment, |
| 3415 | 'activity-comment-author' => $activity_comment_author, |
| 3416 | 'activity-at-message' => $activity_at_message, |
| 3417 | 'groups-at-message' => $groups_at_message, |
| 3418 | 'core-user-registration' => $core_user_registration, |
| 3419 | 'core-user-registration-with-blog' => $core_user_registration_with_blog, |
| 3420 | 'friends-request' => $friends_request, |
| 3421 | 'friends-request-accepted' => $friends_request_accepted, |
| 3422 | 'groups-details-updated' => $groups_details_updated, |
| 3423 | 'groups-invitation' => $groups_invitation, |
| 3424 | 'groups-member-promoted' => $groups_member_promoted, |
| 3425 | 'groups-membership-request' => $groups_membership_request, |
| 3426 | 'messages-unread' => $messages_unread, |
| 3427 | 'settings-verify-email-change' => $settings_verify_email_change, |
| 3428 | 'groups-membership-request-accepted' => $groups_membership_request_accepted, |
| 3429 | 'groups-membership-request-rejected' => $groups_membership_request_rejected, |
| 3430 | ); |
| 3431 | |
| 3432 | return apply_filters( 'bp_email_get_type_schema', $email_type_schema_array ); |
| 3434 | |
| 3435 | /** |
| 3436 | * Handles unsubscribe action to unsubscribe user from notification emails. |
| 3437 | * |
| 3438 | * @since |
| 3439 | * |
| 3440 | */ |
| 3441 | function bp_emails_unsubscribe(){ |
| 3442 | |
| 3443 | $request = $_GET; |
| 3444 | $admin_email = get_bloginfo( 'admin_email' ); |
| 3445 | $bp_email_schema = bp_email_get_type_schema(); |
| 3446 | |
| 3447 | $user_id = ( isset( $request['uid'] ) && !empty( $request['uid'] ) ) ? $request['uid'] : ''; |
| 3448 | $notification_type = ( isset( $request['nt'] ) && !empty( $request['nt'] ) ) ? $request['nt'] : ''; |
| 3449 | $to_check = ( isset( $request['nn'] ) && !empty( $request['nn'] ) ) ? $request['nn'] : ''; |
| 3450 | |
| 3451 | $check_args = array( |
| 3452 | 'uid' => $user_id, |
| 3453 | 'nt' => $notification_type |
| 3454 | ); |
| 3455 | |
| 3456 | $check = bp_check( $check_args ); |
| 3457 | |
| 3458 | $current_user = is_user_logged_in() ? wp_get_current_user() : false; |
| 3459 | |
| 3460 | if( empty( $user_id ) || empty( $notification_type ) || empty( $to_check ) || ! array_key_exists( $notification_type, $bp_email_schema ) ){ |
| 3461 | |
| 3462 | $settings_link = site_url( 'wp-login.php' ); |
| 3463 | $result_message = __( 'Sorry, something has gone wrong.', 'buddypress' ); |
| 3464 | $how_to_unsubscribe_message = __( 'Please log in and go to your settings to unsubscribe from notifications.', 'buddypress' ); |
| 3465 | } |
| 3466 | elseif( ! hash_equals( $check, $to_check ) ){ |
| 3467 | |
| 3468 | $settings_link = site_url( 'wp-login.php' ); |
| 3469 | $result_message = __( 'Sorry the security check failed.', 'buddypress' ); |
| 3470 | $how_to_unsubscribe_message = __( 'Please log in and go to your settings to unsubscribe from notifications.', 'buddypress' ); |
| 3471 | |
| 3472 | } |
| 3473 | elseif( is_user_logged_in() && (int)$current_user->ID !== (int)$user_id ){ |
| 3474 | |
| 3475 | $settings_link = esc_url( sprintf( |
| 3476 | '%s%s/notifications/', |
| 3477 | bp_core_get_user_domain( (int)$current_user->ID ), |
| 3478 | function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings' |
| 3479 | ) ); |
| 3480 | |
| 3481 | $result_message = __( 'Something has gone wrong.', 'buddypress' ); |
| 3482 | $how_to_unsubscribe_message = __( 'Please go to your settings to unsubscribe from notifications.', 'buddypress' ); |
| 3483 | } |
| 3484 | else{ |
| 3485 | |
| 3486 | $settings_link = esc_url( sprintf( |
| 3487 | '%s%s/notifications/', |
| 3488 | bp_core_get_user_domain( $user_id ), |
| 3489 | function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings' |
| 3490 | ) ); |
| 3491 | |
| 3492 | // unsubscribe them by setting the usermeta to 'no' |
| 3493 | $notification_meta_key = $bp_email_schema[ $notification_type ][ 'unsubscribe' ][ 'meta_key' ]; |
| 3494 | $is_unsubscribed = bp_update_user_meta( $user_id, $notification_meta_key, 'no' ); |
| 3495 | |
| 3496 | $result_message = ( empty( $is_unsubscribed ) && bp_get_user_meta( $user_id, $notification_meta_key, true ) !== 'no' ) ? __( 'Sorry, something has gone wrong with unsubscribing you from these emails.', 'buddypress' ) : $bp_email_schema[ $notification_type ][ 'unsubscribe' ][ 'message' ]; |
| 3497 | |
| 3498 | $how_to_unsubscribe_message = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' ); |
| 3499 | } |
| 3500 | |
| 3501 | $message = sprintf( |
| 3502 | '%1$s <a href="%2$s">%3$s</a>', |
| 3503 | $result_message, |
| 3504 | $settings_link, |
| 3505 | $how_to_unsubscribe_message |
| 3506 | ); |
| 3507 | |
| 3508 | bp_core_add_message( $message ); |
| 3509 | bp_core_redirect( esc_url( remove_query_arg( array_keys( $request ) ) ) ); |
| 3510 | } |
| 3511 | |
| 3512 | /** |
| 3513 | * Creates unsubscribe link for notification emails. |
| 3514 | * |
| 3515 | * @since |
| 3516 | * |
| 3517 | * @param string $link URL to which the unsubscribe query string is appended. |
| 3518 | * @param array $args Used to build unsubscribe query string. |
| 3519 | * |
| 3520 | * @return string The unsubscribe link. |
| 3521 | */ |
| 3522 | function bp_email_get_unsubscribe_link( $args = null ){ |
| 3523 | |
| 3524 | $bp_emails_type_schema = bp_email_get_type_schema(); |
| 3525 | |
| 3526 | if( ! is_array( $args ) || !isset( $args['nt'] ) || ! array_key_exists( $args['nt'], $bp_emails_type_schema ) ){ |
| 3527 | return site_url( 'wp-login.php' ); |
| 3528 | } |
| 3529 | $notification_type = $args['nt']; |
| 3530 | |
| 3531 | // if the activity type is not unsubscribable (ununsubscribable), return false |
| 3532 | if( empty( $bp_emails_type_schema[ $notification_type ]['unsubscribe'] ) ){ |
| 3533 | return false; |
| 3534 | } |
| 3535 | |
| 3536 | $link = ( isset( $bp_emails_type_schema[ $notification_type ]['unsubscribe']['link'] ) ) ? $bp_emails_type_schema[ $notification_type ]['unsubscribe']['link'] : bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/'; |
| 3537 | |
| 3538 | $check = bp_check( $args ); |
| 3539 | |
| 3540 | $args['nn'] = $check; |
| 3541 | $args['action'] = 'unsubscribe'; |
| 3542 | |
| 3543 | $unsubscribe_link = esc_url( add_query_arg( $args, $link ) ); |
| 3544 | |
| 3545 | /** |
| 3546 | * Filters the unsubscribe link. |
| 3547 | * |
| 3548 | * @since |
| 3549 | * |
| 3550 | * @param string $link URL to which the unsubscribe query string is appended. |
| 3551 | * @param array $args Used to build unsubscribe query string. |
| 3552 | */ |
| 3553 | return apply_filters( 'bp_email_get_unsubscribe_link', $unsubscribe_link, $link, $args ); |
| 3554 | } |
| 3555 | |