BP_XProfile_Group::save()
Save a profile field group.
Description
Return
(boolean)
Source
File: bp-xprofile/classes/class-bp-xprofile-group.php
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 168 169 170 171 172 173 174 175 176 177 178 | public function save() { global $wpdb ; // Filter the field group attributes. $this ->name = apply_filters( 'xprofile_group_name_before_save' , $this ->name, $this ->id ); $this ->description = apply_filters( 'xprofile_group_description_before_save' , $this ->description, $this ->id ); /** * Fires before the current group instance gets saved. * * Please use this hook to filter the properties above. Each part will be passed in. * * @since BuddyPress 1.0.0 * * @param BP_XProfile_Group $this Current instance of the group being saved. Passed by reference. */ do_action_ref_array( 'xprofile_group_before_save' , array ( & $this ) ); $bp = buddypress(); // Update or insert. if ( ! empty ( $this ->id ) ) { $sql = $wpdb ->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d" , $this ->name, $this ->description, $this ->id ); } else { $sql = $wpdb ->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)" , $this ->name, $this ->description ); } // Attempt to insert or update. $query = $wpdb ->query( $sql ); // Bail if query fails. If `$query` is 0, it means the save was successful, but no fields were updated. if ( false === $query || is_wp_error( $query ) ) { return false; } // If not set, update the ID in the group object. if ( empty ( $this ->id ) ) { $this ->id = $wpdb ->insert_id; } // Save metadata $repeater_enabled = isset( $_POST [ 'group_is_repeater' ] ) && 'on' == $_POST [ 'group_is_repeater' ] ? 'on' : 'off' ; self::update_group_meta( $this ->id, 'is_repeater_enabled' , $repeater_enabled ); /** * Fires after the current group instance gets saved. * * @since BuddyPress 1.0.0 * * @param BP_XProfile_Group $this Current instance of the group being saved. Passed by reference. */ do_action_ref_array( 'xprofile_group_after_save' , array ( & $this ) ); return $this ->id; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.1.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.