bp_nouveau_ajax_xprofile_get_field()
Ajax callback for get the conditional field based on the selected member type.
Description
Source
File: bp-templates/bp-nouveau/includes/xprofile/ajax.php
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 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 168 169 170 171 172 173 174 175 176 177 178 179 180 | function bp_nouveau_ajax_xprofile_get_field() { global $wpdb ; $response = array ( 'feedback' => sprintf( '<div class="bp-feedback error bp-ajax-message"><span class="bp-icon" aria-hidden="true"></span><p>%s</p></div>' , esc_html__( 'There was a problem performing this action. Please try again.' , 'buddyboss' ) ), ); // Bail if not a GET action. if ( ! bp_is_get_request() ) { wp_send_json_error( $response ); } if ( empty ( $_GET [ '_wpnonce' ] ) ) { wp_send_json_error( $response ); } // Use default nonce $nonce = $_GET [ '_wpnonce' ]; $check = 'bp-core-register-page-js' ; // Nonce check! if ( empty ( $nonce ) || ! wp_verify_nonce( $nonce , $check ) ) { wp_send_json_error( $response ); } $bp = buddypress(); $member_type_id = filter_input( INPUT_GET, 'type' , FILTER_VALIDATE_INT ); $existing_fields = filter_input( INPUT_GET, 'fields' , FILTER_SANITIZE_STRING ); $existing_fields_exclude = filter_input( INPUT_GET, 'fields' , FILTER_SANITIZE_STRING ); $existing_fields_fixed_ids = filter_input( INPUT_GET, 'fixedIds' , FILTER_SANITIZE_STRING ); $prevId = filter_input( INPUT_GET, 'prevId' , FILTER_SANITIZE_STRING ); $member_type_key = bp_get_member_type_key( $member_type_id ); $prev_type_key = bp_get_member_type_key( $prevId ); $existing_fields_arr = explode ( ',' , $existing_fields ); $tinymce_added = filter_input( INPUT_GET, 'tinymce' , FILTER_VALIDATE_INT ); $signup_group_id = bp_xprofile_base_group_id(); //FOr prev data $get_prev_ids = []; if ( 0 < strlen ( $prev_type_key ) ) { $query = "SELECT object_id FROM {$bp->profile->table_name_meta} WHERE meta_key = 'member_type' AND meta_value = '{$prev_type_key}' AND object_type = 'field'" ; $get_db_prev_ids = $wpdb ->get_results( $query ); if ( isset( $get_db_prev_ids ) ) { foreach ( $get_db_prev_ids as $id ) { $get_prev_ids [] = $id ->object_id; } } } $query = "SELECT object_id FROM {$bp->profile->table_name_meta} WHERE meta_key = 'member_type' AND meta_value = '{$member_type_key}' AND object_type = 'field'" ; $get_db_ids = $wpdb ->get_results( $query ); $new_fields = array (); if ( isset( $get_db_ids ) ) { foreach ( $get_db_ids as $id ) { if ( ! in_array( $id ->object_id, $existing_fields_arr ) ) { $field = xprofile_get_field( $id ->object_id, null, false ); if ( $field ->group_id === (int) $signup_group_id ) { if ( ! in_array( $id ->object_id, $get_prev_ids ) ) { $new_fields [] = $id ->object_id; } $existing_fields_arr [] = $id ->object_id; } } } } $existing_fields = implode( ',' , $existing_fields_arr ); $include_fields = implode( ',' , $new_fields ); $fixed_fields_arr = explode ( ',' , $existing_fields_fixed_ids ); ob_start(); if ( 0 === $tinymce_added ) { $check_editor = array (); foreach ( $fixed_fields_arr as $id ) { $fields = xprofile_get_field( $id , null, false ); if ( isset( $fields ->type ) && 'textarea' === $fields ->type ) { $check_editor [] = $id ; } } if ( empty ( $check_editor ) ) { $tinymce_added = 1; ?> <script type= 'text/javascript' src= '<?php echo esc_url( site_url( ' / ' ) . WPINC . ' /js/tinymce/tinymce.min.js ' ); ?>' ></script> <?php } } if ( bp_has_profile( "profile_group_id=$signup_group_id&exclude_fields=$existing_fields_exclude&include_fields=$include_fields" ) ) : // Get the current display settings from BuddyBoss > Settings > Profiles > Display Name Format. $current_value = bp_get_option( 'bp-display-name-format' ); while ( bp_profile_groups() ) : bp_the_profile_group(); while ( bp_profile_fields() ) : bp_the_profile_field(); // If First Name selected then do not add last name field. if ( 'first_name' === $current_value && bp_get_the_profile_field_id() === bp_xprofile_lastname_field_id() && false === bp_hide_last_name() ) { continue ; // If Nick Name selected then do not add last name field. } elseif ( 'nickname' === $current_value && bp_get_the_profile_field_id() === bp_xprofile_lastname_field_id() && false === bp_hide_nickname_last_name() ) { continue ; // If Nick Name selected then do not add first name field. } elseif ( 'nickname' === $current_value && bp_get_the_profile_field_id() === bp_xprofile_firstname_field_id() && false === bp_hide_nickname_first_name() ) { continue ; } ?> <div<?php bp_field_css_class( 'editfield ajax_added' ); bp_field_data_attribute(); ?>> <fieldset> <?php $field_type = bp_xprofile_create_field_type( bp_get_the_profile_field_type() ); $field_type ->edit_field_html(); ?> </fieldset> </div> <?php endwhile ; endwhile ; endif ; $content = ob_get_clean(); $response = array (); $response [ 'field_ids' ] = $existing_fields ; $response [ 'field_html' ] = $content ; $response [ 'field_tiny' ] = $tinymce_added ; wp_send_json_success( $response ); } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.1.6 | 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.