xprofile_check_social_networks_added_previously()

Check if the social networks field has been added.

Description

Source

File: bp-xprofile/bp-xprofile-admin.php

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
function xprofile_check_social_networks_added_previously() {
 
    global $wpdb;
 
    $response = array();
    $response['message'] = __( 'You can only have one instance of the "Social Networks" profile field on the website.', 'buddyboss');
 
    $referer = filter_input( INPUT_POST, 'referer', FILTER_SANITIZE_STRING );
 
    parse_str( $referer, $parsed_array);
 
    if ( 'edit_field' === $parsed_array['mode'] ) {
 
        $current_edit_id = intval( $parsed_array['field_id'] );
 
        $exists_gender = $wpdb->get_results( "SELECT COUNT(*) as count, id FROM {$wpdb->prefix}bp_xprofile_fields a WHERE parent_id = 0 AND type = 'socialnetworks' ");
        if ( intval( $exists_gender[0]->count ) > 0 ) {
            if ( $current_edit_id === intval( $exists_gender[0]->id ) ) {
                $response['status'] = 'not_added';
            } else {
                $response['status'] = 'added';
            }
        } else {
            $response['status'] = 'not_added';
        }
    } else {
        $exists_gender = $wpdb->get_results( "SELECT COUNT(*) as count, id FROM {$wpdb->prefix}bp_xprofile_fields a WHERE parent_id = 0 AND type = 'socialnetworks' ");
        if ( intval( $exists_gender[0]->count ) > 0 ) {
            $response['status'] = 'added';
        } else {
            $response['status'] = 'not_added';
        }
    }
    echo wp_json_encode( $response );
    wp_die();
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.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.