'bp-profile-setup', 'mode' => 'add_group', ), $url ); // Validate type. $type = preg_replace( '|[^a-z]|i', '', $type ); // Get all of the profile groups & fields. $groups = bp_xprofile_get_groups( array( 'fetch_fields' => true, ) ); ?>
name = $_POST['group_name']; // Set the group description. if ( ! empty( $_POST['group_description'] ) ) { $group->description = $_POST['group_description']; } else { $group->description = ''; } // Attempt to save the field group. if ( false === $group->save() ) { $message = __( 'There was an error saving the group. Please try again.', 'buddypress' ); $type = 'error'; // Save successful. } else { $message = __( 'The group was saved successfully.', 'buddypress' ); $type = 'success'; // @todo remove these old options. if ( 1 == $group_id ) { bp_update_option( 'bp-xprofile-base-group-name', $group->name ); } /** * Fires at the end of the group adding/saving process, if successful. * * @since 1.0.0 * * @param BP_XProfile_Group $group Current BP_XProfile_Group object. */ do_action( 'xprofile_groups_saved_group', $group ); } xprofile_admin_screen( $message, $type ); } else { $group->render_admin_form( $message ); } } else { $group->render_admin_form(); } } /** * Handles the deletion of profile data groups. * * @since 1.0.0 * * @global string $message The feedback message to show. * @global string $type The type of feedback message to show. * * @param int $group_id ID of the group to delete. */ function xprofile_admin_delete_group( $group_id ) { global $message, $type; check_admin_referer( 'bp_xprofile_delete_group' ); $mode = ! empty( $_GET['mode'] ) ? sanitize_key( $_GET['mode'] ) : false; // Display the group delete confirmation screen. if ( 'delete_group' === $mode ) { xprofile_admin_delete_group_screen( $group_id ); // Handle the deletion of group. } else { $group = new BP_XProfile_Group( $group_id ); if ( ! $group->delete() ) { $message = _x( 'There was an error deleting the group. Please try again.', 'Error when deleting profile fields group', 'buddypress' ); $type = 'error'; } else { $message = _x( 'The group was deleted successfully.', 'Profile fields group was deleted successfully', 'buddypress' ); $type = 'success'; /** * Fires at the end of group deletion process, if successful. * * @since 1.0.0 * * @param BP_XProfile_Group $group Current BP_XProfile_Group object. */ do_action( 'xprofile_groups_deleted_group', $group ); } xprofile_admin_screen( $message, $type ); } } /** * Display the delete confirmation screen of profile data groups. * * @since 7.0.0 */ function xprofile_admin_delete_group_screen( $group_id ) { if ( ! bp_current_user_can( 'bp_moderate' ) ) { die( '-1' ); } $group = new BP_XProfile_Group( $group_id ); $base_url = remove_query_arg( array( 'mode', 'group_id', '_wpnonce' ), $_SERVER['REQUEST_URI'] ); ?> group_id = $group_id; if ( isset( $_POST['saveField'] ) ) { // Check nonce. check_admin_referer( 'bp_xprofile_admin_field', 'bp_xprofile_admin_field' ); if ( BP_XProfile_Field::admin_validate() ) { $field->is_required = $_POST['required']; $field->type = $_POST['fieldtype']; $field->name = $_POST['title']; /* * By default a Textbox field is created. To run field type's feature * checks we need to set it to what it really is early. */ if ( is_null( $field_id ) ) { $field_type = bp_xprofile_create_field_type( $field->type ); // If it's a placeholder, then the field type is not registered. if ( ! $field_type instanceof BP_XProfile_Field_Type_Placeholder ) { $field->type_obj = $field_type; } } if ( ! $field->field_type_supports( 'required' ) ) { $field->is_required = "0"; } if ( ! empty( $_POST['description'] ) ) { $field->description = $_POST['description']; } else { $field->description = ''; } if ( ! empty( $_POST[ "sort_order_{$field->type}" ] ) ) { $field->order_by = $_POST[ "sort_order_{$field->type}" ]; } $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) ); if ( ! is_numeric( $field->field_order ) || is_wp_error( $field->field_order ) ) { $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) ); $field->field_order++; } // For new profile fields, set the $field_id. For existing profile // fields, this will overwrite $field_id with the same value. $field_id = $field->save(); if ( empty( $field_id ) ) { $message = __( 'There was an error saving the field. Please try again.', 'buddypress' ); $type = 'error'; } else { $message = __( 'The field was saved successfully.', 'buddypress' ); $type = 'success'; // @todo remove these old options. if ( 1 == $field_id ) { bp_update_option( 'bp-xprofile-fullname-field-name', $field->name ); } // Set member types. if ( isset( $_POST['has-member-types'] ) ) { $member_types = array(); if ( isset( $_POST['member-types'] ) ) { $member_types = stripslashes_deep( $_POST['member-types'] ); } $field->set_member_types( $member_types ); } // Validate default visibility. if ( ! empty( $_POST['default-visibility'] ) && in_array( $_POST['default-visibility'], wp_list_pluck( bp_xprofile_get_visibility_levels(), 'id' ) ) ) { $default_visibility = $_POST['default-visibility']; if ( ! $field->field_type_supports( 'allow_custom_visibility' ) ) { $default_visibility = 'public'; $available_visibility_levels = bp_xprofile_get_visibility_levels(); if ( isset( $field->type_obj->visibility ) && in_array( $field->type_obj->visibility, array_keys( $available_visibility_levels ), true ) ) { $default_visibility = $field->type_obj->visibility; } } bp_xprofile_update_field_meta( $field_id, 'default_visibility', $default_visibility ); } // Validate custom visibility. if ( ! empty( $_POST['allow-custom-visibility'] ) && in_array( $_POST['allow-custom-visibility'], array( 'allowed', 'disabled' ) ) ) { $allow_custom_visibility = $_POST['allow-custom-visibility']; if ( ! $field->field_type_supports( 'allow_custom_visibility' ) ) { $allow_custom_visibility = 'disabled'; } bp_xprofile_update_field_meta( $field_id, 'allow_custom_visibility', $allow_custom_visibility ); } // Validate signup. if ( $field->field_type_supports( 'signup_position' ) ) { if ( ! empty( $_POST['signup-position'] ) ) { bp_xprofile_update_field_meta( $field_id, 'signup_position', (int) $_POST['signup-position'] ); } else { bp_xprofile_delete_meta( $field_id, 'field', 'signup_position' ); } } $do_autolink = ''; if ( $field->field_type_supports( 'do_autolink' ) && isset( $_POST['do_autolink'] ) && $_POST['do_autolink'] ) { $do_autolink = wp_unslash( $_POST['do_autolink'] ); } // Save autolink settings. if ( 'on' === $do_autolink ) { bp_xprofile_update_field_meta( $field_id, 'do_autolink', 'on' ); } else { bp_xprofile_update_field_meta( $field_id, 'do_autolink', 'off' ); } if ( $field->type_obj->do_settings_section() ) { $settings = isset( $_POST['field-settings'] ) ? wp_unslash( $_POST['field-settings'] ) : array(); $field->admin_save_settings( $settings ); } /** * Fires at the end of the process to save a field for a user, if successful. * * @since 1.0.0 * * @param BP_XProfile_Field $field Current BP_XProfile_Field object. */ do_action( 'xprofile_fields_saved_field', $field ); $groups = bp_xprofile_get_groups(); } xprofile_admin_screen( $message, $type ); } else { $field->render_admin_form( $message ); } } else { $field->render_admin_form(); } } /** * Handles the deletion of a profile field (or field option). * * @since 1.0.0 * * @global string $message The feedback message to show. * @global string $type The type of feedback message to show. * * @param int $field_id The field to delete. * @param string $field_type The type of field being deleted. * @param bool $delete_data Should the field data be deleted too. */ function xprofile_admin_delete_field( $field_id, $field_type = 'field', $delete_data = false ) { global $message, $type; check_admin_referer( 'bp_xprofile_delete_field-' . $field_id, 'bp_xprofile_delete_field' ); $mode = ! empty( $_GET['mode'] ) ? sanitize_key( $_GET['mode'] ) : false; // Switch type to 'option' if type is not 'field'. // @todo trust this param. $field_type = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' ); // Display the field/option delete confirmation screen. if ( in_array( $mode, array( 'delete_field', 'delete_option' ) ) ) { xprofile_admin_delete_field_screen( $field_id, $field_type ); // Handle the deletion of field } else { $field = xprofile_get_field( $field_id, null, false ); if ( ! $field->delete( (bool) $delete_data ) ) { /* translators: %s: the field type */ $message = sprintf( __( 'There was an error deleting the %s. Please try again.', 'buddypress' ), $field_type ); $type = 'error'; } else { /* translators: %s: the field type */ $message = sprintf( __( 'The %s was deleted successfully!', 'buddypress' ), $field_type ); $type = 'success'; /** * Fires at the end of the field deletion process, if successful. * * @since 1.0.0 * * @param BP_XProfile_Field $field Current BP_XProfile_Field object. */ do_action( 'xprofile_fields_deleted_field', $field ); } xprofile_admin_screen( $message, $type ); } } /** * Display the delete confirmation screen of xprofile field/option. * * @since 7.0.0 */ function xprofile_admin_delete_field_screen( $field_id, $field_type ) { if ( ! bp_current_user_can( 'bp_moderate' ) ) { die( '-1' ); } $field = xprofile_get_field( $field_id, null, false ); $base_url = remove_query_arg( array( 'page', 'mode', 'field_id', 'bp_xprofile_delete_field' ), $_SERVER['REQUEST_URI'] ); ?>' . esc_html( $field->name ) . '' ); ?>