BP_Notifications_Notification::save()

Update or insert notification details into the database.

Description

Return

(bool) True on success, false on failure.

Source

File: bp-notifications/classes/class-bp-notifications-notification.php

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
public function save() {
    $retval = false;
 
    /**
     * Fires before the current notification item gets saved.
     *
     * Please use this hook to filter the properties above. Each part will be passed in.
     *
     * @since BuddyPress 2.0.0
     *
     * @param BP_Notifications_Notification $value Current instance of the notification item being saved. Passed by reference.
     */
    do_action_ref_array( 'bp_notification_before_save', array( &$this ) );
 
    $data = array(
        'user_id'           => $this->user_id,
        'item_id'           => $this->item_id,
        'secondary_item_id' => $this->secondary_item_id,
        'component_name'    => $this->component_name,
        'component_action'  => $this->component_action,
        'date_notified'     => $this->date_notified,
        'is_new'            => $this->is_new,
    );
    $data_format = array( '%d', '%d', '%d', '%s', '%s', '%s', '%d' );
 
    // Update.
    if ( ! empty( $this->id ) ) {
        $result = self::_update( $data, array( 'ID' => $this->id ), $data_format, array( '%d' ) );
 
    // Insert.
    } else {
        $result = self::_insert( $data, $data_format );
    }
 
    // Set the notification ID if successful.
    if ( ! empty( $result ) && ! is_wp_error( $result ) ) {
        global $wpdb;
 
        $this->id = $wpdb->insert_id;
        $retval   = $wpdb->insert_id;
    }
 
    /**
     * Fires after the current notification item gets saved.
     *
     * @since BuddyPress 2.0.0
     *
     * @param BP_Notifications_Notification $value Current instance of the notification item being saved.
     *                                             Passed by reference.
     */
    do_action_ref_array( 'bp_notification_after_save', array( &$this ) );
 
    // Return the result.
    return $retval;
}

Changelog

Changelog
Version Description
BuddyPress 1.9.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.