xprofile_check_social_networks_added_previously()

Check if the social networks field has been added.

Description

Source

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

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.