BP_Admin_Setting_Xprofile
Main Profile Settings class.
Description
Source
File: bp-core/admin/settings/bp-admin-setting-xprofile.php
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | class BP_Admin_Setting_Xprofile extends BP_Admin_Setting_tab { public function initialize() { $this ->tab_label = __( 'Profiles' , 'buddyboss' ); $this ->tab_name = 'bp-xprofile' ; $this ->tab_order = 10; } public function settings_save() { $if_disabled_before_saving = bp_disable_advanced_profile_search(); parent::settings_save(); $if_disabled_after_saving = bp_disable_advanced_profile_search(); /** * sync bp-enable-member-dashboard with cutomizer settings. * * @since BuddyBoss 1.0.0 */ $bp_nouveau_appearance = bp_get_option( 'bp_nouveau_appearance' , array () ); $bp_nouveau_appearance [ 'user_front_page' ] = isset( $_POST [ 'bp-enable-member-dashboard' ] ) ? $_POST [ 'bp-enable-member-dashboard' ] : 0; $bp_nouveau_appearance [ 'user_front_page_redirect' ] = isset( $_POST [ 'bp-enable-member-dashboard-redirect' ] ) ? $_POST [ 'bp-enable-member-dashboard-redirect' ] : 0; bp_update_option( 'bp_nouveau_appearance' , $bp_nouveau_appearance ); //Set requirement for last name based on display format if ( isset( $_POST [ 'bp-display-name-format' ] ) && $_POST [ 'bp-display-name-format' ] == 'first_last_name' ) { if ( $last_name_field = xprofile_get_field( bp_xprofile_lastname_field_id() ) ) { $last_name_field ->is_required = true; $last_name_field ->save(); } } if ( $if_disabled_before_saving && ! $if_disabled_after_saving ) { /** * Advanced profile search was disabled before and is now enabled. * So ideally, the new 'profile search' menu should now be visible under users nav. * But that doesn't happen becuase by the time settings are updated, register_post_type hooks have already been executed. * So user doesn't see that untill next reload/request. * * To avoid that, we'll need to do a force redirect. */ wp_safe_redirect( bp_get_admin_url( 'admin.php?page=bp-settings&tab=bp-xprofile' ) ); exit (); } } public function register_fields() { $this ->add_section( 'bp_xprofile' , __( 'Profile Settings' , 'buddyboss' ) ); // Display name format. $this ->add_field( 'bp-display-name-format' , __( 'Display Name Format' , 'buddyboss' ), [ $this , 'callback_display_name_format' ] ); // Avatars. $this ->add_field( 'bp-disable-avatar-uploads' , __( 'Profile Avatars' , 'buddyboss' ), 'bp_admin_setting_callback_avatar_uploads' , 'intval' ); // cover photos. if ( bp_is_active( 'xprofile' , 'cover_image' ) ) { $this ->add_field( 'bp-disable-cover-image-uploads' , __( 'Profile Cover Images' , 'buddyboss' ), 'bp_admin_setting_callback_cover_image_uploads' , 'intval' ); } // Profile Settings Tutorial $this ->add_field( 'bp-profile-setting-tutorial' , '' , 'bp_profile_setting_tutorial' ); // @todo will use this later on // Section for profile dashboard. //$this->add_section( 'bp_profile_dashboard_settings', __( 'Profile Dashboard', 'buddyboss' ) ); // @todo will use this later on // Enable/Disable profile dashboard. //$this->add_field( 'bp-enable-member-dashboard', __( 'Profile Dashboard', 'buddyboss' ), [$this, 'bp_admin_setting_callback_member_dashboard'], 'intval' ); // @todo will use this later on //$this->add_field( 'bp-enable-member-dashboard-redirect', __( 'Redirect on Login', 'buddyboss' ), [$this, 'bp_admin_setting_callback_member_dashboard_redirect'], 'intval' ); // Section for profile types. $this ->add_section( 'bp_member_type_settings' , __( 'Profile Types' , 'buddyboss' ) ); // Enable/Disable profile types. $this ->add_field( 'bp-member-type-enable-disable' , __( 'Profile Types' , 'buddyboss' ), [ $this , 'bp_admin_setting_callback_member_type_enable_disable' ], 'intval' ); // Profile Type enabled then display profile types. if ( true === bp_member_type_enable_disable() ) { // Enable/Disable Display on profiles. $this ->add_field( 'bp-member-type-display-on-profile' ,__( 'Display Profile Types' , 'buddyboss' ),[ $this , 'bp_admin_setting_callback_member_type_display_on_profile' ], 'intval' ); } // Default profile type on registration. if ( true === bp_member_type_enable_disable() ) { $this ->add_field( 'bp-member-type-default-on-registration' ,__( 'Default Profile Type' , 'buddyboss' ),[ $this , 'bp_admin_setting_callback_member_type_default_on_registration' ] ); } // Profile Types Tutorial $this ->add_field( 'bp-profile-types-tutorial' , '' , [ $this , 'bp_profile_types_tutorial' ] ); // Section for profile search. $this ->add_section( 'bp_profile_search_settings' , __( 'Profile Search' , 'buddyboss' ) ); // Enable/Disable profile search. $this ->add_field( 'bp-enable-profile-search' , __( 'Profile Search' , 'buddyboss' ), [ $this , 'bp_admin_setting_callback_profile_search' ], 'intval' ); // Profile Search Tutorial $this ->add_field( 'bp-profile-search-tutorial' , '' , [ $this , 'bp_profile_search_tutorial' ] ); } /** * Enable profile dashboard template. * * @since BuddyBoss 1.0.0 * */ public function bp_admin_setting_callback_member_dashboard() { ?> <input id= "bp-enable-member-dashboard" name= "bp-enable-member-dashboard" type= "checkbox" value= "1" <?php checked( bp_nouveau_get_appearance_settings( 'user_front_page' ) ); ?> /> <label for = "bp-enable-member-dashboard" ><?php _e( 'Use a WordPress page as each user\'s personal Profile Dashboard' , 'buddyboss' ); ?></label> <?php printf( '<p class="description">%s</p>' , sprintf( __( 'This page is only accessible to logged-in users. Create a WordPress page and assign it in the <a href="%s">Pages</a> settings.' , 'buddyboss' ), add_query_arg([ 'page' => 'bp-pages' , ], admin_url( 'admin.php' ) ) ) ); } /** * Enable profile dashboard template. * * @since BuddyBoss 1.0.0 * */ public function bp_admin_setting_callback_member_dashboard_redirect() { ?> <input id= "bp-enable-member-dashboard-redirect" name= "bp-enable-member-dashboard-redirect" type= "checkbox" value= "1" <?php checked( bp_nouveau_get_appearance_settings( 'user_front_page_redirect' ) ); ?> /> <label for = "bp-enable-member-dashboard-redirect" ><?php _e( 'Redirect users to their Profile Dashboard on login' , 'buddyboss' ); ?></label> <?php } public function callback_display_name_format() { $options = [ 'first_name' => __( 'First Name' , 'buddyboss' ), 'first_last_name' => __( 'First Name & Last Name' , 'buddyboss' ), 'nickname' => __( 'Nickname' , 'buddyboss' ), ]; $current_value = bp_get_option( 'bp-display-name-format' ); printf( '<select name="%1$s" for="%1$s">' , 'bp-display-name-format' ); foreach ( $options as $key => $value ) { printf( '<option value="%s" %s>%s</option>' , $key , $key == $current_value ? 'selected' : '' , $value ); } printf( '</select>' ); printf( '<p class="description">%s</p>' , sprintf( __( 'After the format has been updated, remember to run <a href="%s">Repair Community</a> tools to update all the users.' , 'buddyboss' ), add_query_arg( [ 'page' => 'bp-repair-community' , 'tab' => 'bp-repair-community' , 'tool' => 'bp-wordpress-update-display-name' ], admin_url( 'admin.php' ) ) ) ); } /** * Enable profile types. * * @since BuddyBoss 1.0.0 * */ public function bp_admin_setting_callback_member_type_enable_disable() { ?> <input id= "bp-member-type-enable-disable" name= "bp-member-type-enable-disable" type= "checkbox" value= "1" <?php checked( bp_member_type_enable_disable() ); ?> /> <?php if ( true === bp_member_type_enable_disable() ) { printf( '<label for="bp-member-type-enable-disable">%s</label>' , sprintf( __( 'Enable <a href="%s">profile types</a> to give members unique profile fields and permissions' , 'buddyboss' ), add_query_arg([ 'post_type' => bp_get_member_type_post_type(), ], admin_url( 'edit.php' ) ) ) ); } else { ?> <label for = "bp-member-type-enable-disable" ><?php _e( 'Enable profile types to give members unique profile fields and permissions' , 'buddyboss' ); ?></label> <?php } } /** * Enable display of profile type on member profile page. * * @since BuddyBoss 1.0.0 * */ public function bp_admin_setting_callback_member_type_display_on_profile() { ?> <input id= "bp-member-type-display-on-profile" name= "bp-member-type-display-on-profile" type= "checkbox" value= "1" <?php checked( bp_member_type_display_on_profile() ); ?> /> <label for = "bp-member-type-display-on-profile" ><?php _e( 'Display each member\'s profile type on their profile page' , 'buddyboss' ); ?></label> <?php } /** * Default profile type on registration. * * @since BuddyBoss 1.0.0 * */ public function bp_admin_setting_callback_member_type_default_on_registration(){ $member_types = bp_get_active_member_types(); $existing_selected = bp_member_type_default_on_registration(); if ( empty ( $member_types ) ) { printf( '<p class="description">%s</p>' , sprintf( __( 'You first need to create some <a href="%s">Profile Types</a>.' , 'buddyboss' ), add_query_arg( [ 'post_type' => bp_get_member_type_post_type(), ], admin_url( 'edit.php' ) ) ) ); } else { ?> <select name= "bp-member-type-default-on-registration" id= "bp-member-type-default-on-registration" > <option value= "" ><?php esc_html_e( '----' , 'buddyboss' ); ?></option><?php foreach ( $member_types as $member_type_id ) { $type_name = bp_get_member_type_key( $member_type_id ); //$type_id = bp_member_type_term_taxonomy_id( $type_name ); $member_type_name = get_post_meta( $member_type_id , '_bp_member_type_label_name' , true ); //if ( ! empty( $type_id ) ) { ?> <option <?php selected( $existing_selected , $type_name ); ?> value= "<?php echo $type_name; ?>" ><?php esc_html_e( $member_type_name , 'buddyboss' ); ?></option><?php //} } ?> </select> <?php printf( '<p class="description">%s</p>' , sprintf( __( 'Select a default profile type to be auto-assigned to users during registration. After the profile type has been selected, you can run <a href="%s">Repair Community</a> tools to assign the profile type to existing users.' , 'buddyboss' ), add_query_arg( [ 'page' => 'bp-tools' , 'tab' => 'bp-tools' , 'tool' => 'bp-assign-member-type' ], admin_url( 'admin.php' ) ) ) ); } } /** * Link to Profile Types tutorial * * @since BuddyBoss 1.0.0 * */ function bp_profile_types_tutorial() { ?> <p> <a class = "button" href= "<?php echo bp_core_help_docs_link( 'components/profiles/profile-types.md' ); ?>" ><?php _e( 'View Tutorial' , 'buddyboss' ); ?></a> </p> <?php } /** * Enable member profile search. * * @since BuddyBoss 1.0.0 * */ public function bp_admin_setting_callback_profile_search() { ?> <input id= "bp-enable-profile-search" name= "bp-enable-profile-search" type= "checkbox" value= "1" <?php checked( ! bp_disable_advanced_profile_search() ); ?> /> <?php if ( false === bp_disable_advanced_profile_search() ) { printf( '<label for="bp-enable-profile-search">%s</label>' , sprintf( __( 'Enable <a href="%s">advanced profile search</a> on the members directory.' , 'buddyboss' ), add_query_arg([ 'post_type' => 'bp_ps_form' , ], admin_url( 'edit.php' ) ) ) ); } else { ?> <label for = "bp-enable-profile-search" ><?php _e( 'Enable advanced profile search on the members directory' , 'buddyboss' ); ?></label> <?php } } /** * Link to Profile Search tutorial * * @since BuddyBoss 1.0.0 * */ function bp_profile_search_tutorial() { ?> <p> <a class = "button" href= "<?php echo bp_core_help_docs_link( 'components/profiles/profile-search.md' ); ?>" ><?php _e( 'View Tutorial' , 'buddyboss' ); ?></a> </p> <?php } } |
Changelog
Version | Description |
---|---|
BuddyBoss 1.0.0 | Introduced. |
Methods
- bp_admin_setting_callback_member_dashboard — Enable profile dashboard template.
- bp_admin_setting_callback_member_dashboard_redirect — Enable profile dashboard template.
- bp_admin_setting_callback_member_type_default_on_registration — Default profile type on registration.
- bp_admin_setting_callback_member_type_display_on_profile — Enable display of profile type on member profile page.
- bp_admin_setting_callback_member_type_enable_disable — Enable profile types.
- bp_admin_setting_callback_profile_search — Enable member profile search.
- bp_admin_setting_profile_layout_default_option — Admin Settings for Settings > Profiles > Profile Directories > Default Format
- bp_admin_setting_profile_layout_type_format — Admin Settings for Settings > Profiles > Profile Directories > Default Format
- bp_profile_directories_tutorial — Link to Profile Directories tutorial
- bp_profile_search_tutorial — Link to Profile Search tutorial
- bp_profile_types_tutorial — Link to Profile Types tutorial
- callback_display_name_format
- initialize
- register_fields
- settings_save
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.