Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to Disable Private Message Notication #168

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/bp-core/admin/bp-core-admin-settings.php
Expand Up @@ -201,6 +201,29 @@ function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
return $value ? 0 : 1;
}

/** Notification Section *******************************************************************/

/**
* Notification settings section description for the settings page.
*
* @since 12.0.0
*/
function bp_admin_setting_callback_notifications_section() { }

/**
* Allow Private Message Notification
*
* @since 12.0.0
*/
function bp_admin_setting_callback_private_message_notifications() {
?>

<input id="bp-enable-pm-notifications" name="bp-enable-pm-notifications" type="checkbox" value="1" <?php checked( bp_is_private_message_notification_active( true ) ); ?> />
<label for="bp-enable-pm-notifications"><?php _e( 'Allow notifications for new incoming private messages', 'buddypress' ); ?></label>

<?php
}

/** Members *******************************************************************/

/**
Expand Down
21 changes: 21 additions & 0 deletions src/bp-core/bp-core-options.php
Expand Up @@ -696,6 +696,27 @@ function bp_is_activity_heartbeat_active( $default = true ) {
return (bool) apply_filters( 'bp_is_activity_heartbeat_active', (bool) bp_get_option( '_bp_enable_heartbeat_refresh', $default ) );
}

/**
* Check whether Private Message Notifications are enabled.
*
* @since 12.0.0
*
* @param bool $default Optional. Fallback value if not found in the database.
* Default: true.
* @return bool True if Private Message Notifications are enabled, otherwise false.
*/
function bp_is_private_message_notification_active( $default = true ) {

/**
* Filters whether or not Private Message Notificatios are enabled.
*
* @since 12.0.0
*
* @param bool $value Whether or not Private Message Notificatios are enabled.
*/
return (bool) apply_filters( 'bp_is_private_message_notifications_active', (bool) bp_get_option( 'bp-enable-pm-notifications', $default ) );
}

/**
* Get the current theme package ID.
*
Expand Down
12 changes: 12 additions & 0 deletions src/bp-core/classes/class-bp-admin.php
Expand Up @@ -568,6 +568,18 @@ public function register_admin_settings() {
register_setting( 'buddypress', '_bp_enable_akismet', 'intval' );
}
}

/* Notification Section **************************************************/

if ( bp_is_active( 'notifications' ) ) {

// Add the main section.
add_settings_section( 'bp_notifications', __( 'Notifications Settings', 'buddypress' ), 'bp_admin_setting_callback_notifications_section', 'buddypress' );

// Enable Private Message Notification
add_settings_field( 'bp-enable-pm-notifications', __( 'Private Message', 'buddypress' ), 'bp_admin_setting_callback_private_message_notifications', 'buddypress', 'bp_notifications' );
register_setting( 'buddypress', 'bp-enable-pm-notifications', 'intval' );
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/bp-messages/bp-messages-notifications.php
Expand Up @@ -194,6 +194,17 @@ function messages_format_notifications( $action, $item_id, $secondary_item_id, $
* @param BP_Messages_Message $message Message object.
*/
function bp_messages_message_sent_add_notification( $message ) {

/**
* Enable/Disables Notification for New Private Messages
*
* @since 12.0.0
*
*/
if( ! bp_is_private_message_notification_active() ) {
return;
}

if ( ! empty( $message->recipients ) ) {
foreach ( (array) $message->recipients as $recipient ) {
bp_notifications_add_notification( array(
Expand Down