Ticket #6347: 6347.alt.patch
File 6347.alt.patch, 38.6 KB (added by , 4 years ago) |
---|
-
src/bp-core/admin/bp-core-admin-functions.php
diff --git src/bp-core/admin/bp-core-admin-functions.php src/bp-core/admin/bp-core-admin-functions.php index c9a5259e9..73fe02737 100644
function bp_core_add_contextual_help_content( $tab = '' ) { 586 586 break; 587 587 588 588 case 'bp-profile-overview': 589 $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '<br /><br />' . __( 'Note: Any fields in the first group will appear on the signup page.', 'buddypress' );589 $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '<br /><br />' . __( 'Note: Drag fields from other groups and drop them on the "Signup Fields" tab to include them into your signup form.', 'buddypress' ); 590 590 break; 591 591 592 592 default: -
src/bp-core/admin/bp-core-admin-schema.php
diff --git src/bp-core/admin/bp-core-admin-schema.php src/bp-core/admin/bp-core-admin-schema.php index d7cab5bbe..7a10e39eb 100644
function bp_core_install_extended_profiles() { 389 389 // Make sure the custom visibility is disabled for the default field. 390 390 if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_meta WHERE id = 1" ) ) { 391 391 $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_meta ( object_id, object_type, meta_key, meta_value ) VALUES ( 1, 'field', 'allow_custom_visibility', 'disabled' );"; 392 $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_meta ( object_id, object_type, meta_key, meta_value ) VALUES ( 1, 'field', 'signup_position', 1 );"; 392 393 } 393 394 } 394 395 -
src/bp-core/bp-core-update.php
diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php index a7791c445..cd6accb21 100644
function bp_update_to_2_7() { 552 552 bp_add_option( '_bp_ignore_deprecated_code', false ); 553 553 } 554 554 555 /** 556 * Retuns needed the fullname field ID for an update task. 557 * 558 * @since 8.0.0 559 * 560 * @return int The fullname field ID. 561 */ 562 function bp_get_fullname_field_id_for_update() { 563 /** 564 * The xProfile component is active by default on new installs, even if it 565 * might be inactive during this update, we need to set the custom visibility 566 * for the default field, in case the Administrator decides to reactivate it. 567 */ 568 global $wpdb; 569 $bp_prefix = bp_core_get_table_prefix(); 570 return (int) $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE name = %s", addslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) ); 571 } 572 555 573 /** 556 574 * 5.0.0 update routine. 557 575 * … … function bp_update_to_2_7() { 562 580 * @since 5.0.0 563 581 */ 564 582 function bp_update_to_5_0() { 565 /**566 * The xProfile component is active by default on new installs, even if it567 * might be inactive during this update, we need to set the custom visibility568 * for the default field, in case the Administrator decides to reactivate it.569 */570 583 global $wpdb; 571 584 $bp_prefix = bp_core_get_table_prefix(); 572 $field_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE name = %s", addslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ));585 $field_id = bp_get_fullname_field_id_for_update(); 573 586 574 587 $wpdb->insert( 575 588 $bp_prefix . 'bp_xprofile_meta', … … function bp_update_to_5_0() { 598 611 * 8.0.0 update routine. 599 612 * 600 613 * - Edit the `new_avatar` activity type's component to `members`. 614 * - Make the BP fullname field a signup field by default. 601 615 * 602 616 * @since 8.0.0 603 617 */ … … function bp_update_to_8_0() { 621 635 '%s', 622 636 ) 623 637 ); 638 639 // Make the BP fullname field a signup field by default. 640 $wpdb->insert( 641 $bp_prefix . 'bp_xprofile_meta', 642 array( 643 'object_id' => bp_get_fullname_field_id_for_update(), 644 'object_type' => 'field', 645 'meta_key' => 'signup_position', 646 'meta_value' => 1, 647 ), 648 array( 649 '%d', 650 '%s', 651 '%s', 652 '%d', 653 ) 654 ); 624 655 } 625 656 626 657 /** -
src/bp-templates/bp-legacy/buddypress/members/register.php
diff --git src/bp-templates/bp-legacy/buddypress/members/register.php src/bp-templates/bp-legacy/buddypress/members/register.php index 4e8418e7f..b7cbcc023 100644
165 165 <h2><?php _e( 'Profile Details', 'buddypress' ); ?></h2> 166 166 167 167 <?php /* Use the profile field loop to render input fields for the 'base' profile field group */ ?> 168 <?php if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( array( ' profile_group_id' => 1, 'fetch_field_data' => false ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>168 <?php if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( array( 'fetch_fields' => true, 'fetch_field_data' => false, 'signup_fields_only' => true ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?> 169 169 170 170 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 171 171 -
src/bp-templates/bp-nouveau/buddypress/members/register.php
diff --git src/bp-templates/bp-nouveau/buddypress/members/register.php src/bp-templates/bp-nouveau/buddypress/members/register.php index 2c0a688f2..ca5560e57 100644
38 38 39 39 <?php /***** Extra Profile Details ******/ ?> 40 40 41 <?php if ( bp_is_active( 'xprofile' ) && bp_nouveau_ base_account_has_xprofile() ) : ?>41 <?php if ( bp_is_active( 'xprofile' ) && bp_nouveau_has_signup_xprofile_fields( true ) ) : ?> 42 42 43 43 <?php bp_nouveau_signup_hook( 'before', 'signup_profile' ); ?> 44 44 -
src/bp-templates/bp-nouveau/includes/template-tags.php
diff --git src/bp-templates/bp-nouveau/includes/template-tags.php src/bp-templates/bp-nouveau/includes/template-tags.php index 3439280fb..5ee755a05 100644
function bp_nouveau_container_classes() { 1515 1515 } 1516 1516 1517 1517 // Provide a class token to acknowledge additional extended profile fields added to default account reg screen 1518 if ( 'register' === bp_current_component() && bp_is_active( 'xprofile' ) && bp_nouveau_ base_account_has_xprofile()) {1518 if ( 'register' === bp_current_component() && bp_is_active( 'xprofile' ) && bp_nouveau_has_signup_xprofile_fields()) { 1519 1519 $classes[] = 'extended-default-reg'; 1520 1520 } 1521 1521 -
src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php
diff --git src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php src/bp-templates/bp-nouveau/includes/xprofile/template-tags.php index 26ef5199f..9782d1aad 100644
3 3 * xProfile Template tags 4 4 * 5 5 * @since 3.0.0 6 * @version 3.0.06 * @version 8.0.0 7 7 */ 8 8 9 9 // Exit if accessed directly. … … function bp_nouveau_xprofile_edit_visibilty() { 62 62 * profile fields added to it for the registration screen. 63 63 * 64 64 * @since 3.0.0 65 * @deprecated 8.0.0 65 66 */ 66 67 function bp_nouveau_base_account_has_xprofile() { 67 return (bool) bp_has_profile( 68 _deprecated_function( __FUNCTION__, '8.0.0', 'bp_nouveau_has_signup_xprofile_fields()' ); 69 return bp_nouveau_has_signup_xprofile_fields(); 70 } 71 72 /** 73 * Checks whether there are signup profile fields to display. 74 * 75 * @since 8.0.0 76 * 77 * @param bool Whether to init an xProfile loop. 78 * @return bool True if there are signup profile fields to display. False otherwise. 79 */ 80 function bp_nouveau_has_signup_xprofile_fields( $do_loop = false ) { 81 $signup_fields = (array) bp_xprofile_get_signup_field_ids(); 82 83 if ( ! $do_loop ) { 84 return 1 <= count( $signup_fields ); 85 } 86 87 return bp_has_profile( 68 88 array( 69 'profile_group_id' => 1, 70 'fetch_field_data' => false, 89 'fetch_fields' => true, 90 'fetch_field_data' => false, 91 'signup_fields_only' => true, 71 92 ) 72 93 ); 73 94 } -
src/bp-xprofile/admin/css/admin.css
diff --git src/bp-xprofile/admin/css/admin.css src/bp-xprofile/admin/css/admin.css index b84db929a..36d01b81c 100644
ul#field-group-tabs li.ui-state-active a.ui-tab { 62 62 color: #000; 63 63 } 64 64 65 li#signup-group a:focus { 66 box-shadow: none; 67 } 68 65 69 /* Toolbar */ 66 70 .tab-toolbar { 67 71 clear: left; -
src/bp-xprofile/admin/js/admin.js
diff --git src/bp-xprofile/admin/js/admin.js src/bp-xprofile/admin/js/admin.js index 99a5b4b5d..1f296869b 100644
jQuery( function() { 248 248 cursor: 'move', 249 249 axis: 'x', 250 250 opacity: 1, 251 items: 'li ',251 items: 'li:not(.not-sortable)', 252 252 tolerance: 'intersect', 253 253 254 254 update: function() { … … jQuery( function() { 348 348 // When field is dropped on tab. 349 349 drop: function( ev, ui ) { 350 350 var $item = jQuery(this), // The tab 351 $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ); // The tab body 351 $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ), // The tab body 352 dropInGroup = function( fieldId ) { 353 var fieldOrder, postData = { 354 action: 'xprofile_reorder_fields', 355 'cookie': encodeURIComponent(document.cookie), 356 '_wpnonce_reorder_fields': jQuery( 'input#_wpnonce_reorder_fields' ).val(), 357 }; 358 359 // Select new tab as current. 360 $tabs.tabs( 'option', 'active', $tab_items.index( $item ) ); 361 362 // Refresh $list variable. 363 $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ); 364 jQuery($list).find( 'p.nofields' ).hide( 'slow' ); 365 366 jQuery.extend( postData, { 367 'field_group_id': jQuery( $list ).attr( 'id' ), 368 'group_tab': jQuery( $item ).prop( 'id' ) 369 } ); 370 371 // Set serialized data 372 fieldOrder = jQuery( $list ).sortable( 'serialize' ); 373 374 if ( fieldId ) { 375 var serializedField = fieldId.replace( 'draggable_field_', 'draggable_signup_field[]=' ); 376 if ( fieldOrder ) { 377 fieldOrder += '&' + serializedField; 378 } else { 379 fieldOrder = serializedField; 380 } 381 382 jQuery.extend( postData, { 383 'new_signup_field_id': serializedField, 384 } ); 385 } else { 386 // Show new placement. 387 jQuery( this ).appendTo( $list ).show( 'slow' ).animate( { opacity: '1' }, 500 ); 388 389 // Refresh $list variable. 390 $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ); 391 392 // Reset serialized data. 393 fieldOrder = jQuery( $list ).sortable( 'serialize' ); 394 395 jQuery.extend( postData, { 396 'field_group_id': jQuery( $list ).attr( 'id' ) 397 } ); 398 } 399 400 jQuery.extend( postData, { 401 'field_order': fieldOrder, 402 } ); 403 404 // Ajax update field locations and orders. 405 jQuery.post( ajaxurl, postData, function( response ) { 406 if ( response.data && response.data.signup_field ) { 407 jQuery( $list ).append( response.data.signup_field ); 408 } 409 }, 'json' ); 410 }; 352 411 353 412 // Remove helper class. 354 413 jQuery($item).removeClass( 'drop-candidate' ); 355 414 356 // Hide field, change selected tab, and show new placement. 357 ui.draggable.hide( 'slow', function() { 358 359 // Select new tab as current. 360 $tabs.tabs( 'option', 'active', $tab_items.index( $item ) ); 361 362 // Show new placement. 363 jQuery(this).appendTo($list).show( 'slow' ).animate( {opacity: '1'}, 500 ); 364 365 // Refresh $list variable. 366 $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' ); 367 jQuery($list).find( 'p.nofields' ).hide( 'slow' ); 368 369 // Ajax update field locations and orders. 370 jQuery.post( ajaxurl, { 371 action: 'xprofile_reorder_fields', 372 'cookie': encodeURIComponent(document.cookie), 373 '_wpnonce_reorder_fields': jQuery( 'input#_wpnonce_reorder_fields' ).val(), 374 'field_order': jQuery( $list ).sortable( 'serialize' ), 375 'field_group_id': jQuery( $list ).attr( 'id' ) 376 }, 377 function() {} ); 378 }); 415 if ( 'signup-group' === jQuery( $item ).prop( 'id' ) ) { 416 // Simply add the field to signup ones. 417 dropInGroup( ui.draggable.prop( 'id' ) ); 418 } else if ( ! ui.draggable.prop( 'id' ).match( /draggable_signup_field_([0-9]+)/ ) ) { 419 // Hide field, change selected tab, and show new placement. 420 ui.draggable.hide( 'slow', dropInGroup ); 421 } 379 422 }, 380 423 over: function() { 381 424 jQuery(this).addClass( 'drop-candidate' ); … … jQuery( function() { 385 428 } 386 429 }); 387 430 } 431 432 jQuery( '#signup-fields' ).on( 'click', '.removal', function( e ) { 433 e.preventDefault(); 434 435 var fieldId = jQuery( e.target ).attr( 'href' ).replace( '#remove_field-', '' ), 436 container = jQuery( e.target ).closest( '#draggable_signup_field_' + fieldId ); 437 438 if ( ! fieldId ) { 439 return false; 440 } 441 442 // Ajax update field locations and orders. 443 jQuery.post( ajaxurl, { 444 action: 'xprofile_remove_signup_field', 445 'cookie': encodeURIComponent(document.cookie), 446 '_wpnonce_reorder_fields': jQuery( 'input#_wpnonce_reorder_fields' ).val(), 447 'signup_field_id': fieldId 448 }, function( response ) { 449 if ( response.success ) { 450 jQuery( container ).remove(); 451 } 452 }, 'json' ); 453 } ); 388 454 }); -
src/bp-xprofile/bp-xprofile-admin.php
diff --git src/bp-xprofile/bp-xprofile-admin.php src/bp-xprofile/bp-xprofile-admin.php index 5bd8a899d..07f447c30 100644
function xprofile_admin_screen( $message = '', $type = 'error' ) { 188 188 189 189 <?php endforeach; endif; ?> 190 190 191 <?php if ( bp_get_signup_allowed() ) : ?> 192 <li id="signup-group" class="not-sortable last"> 193 <a href="#tabs-signup-group" class="ui-tab"> 194 <?php esc_html_e( 'Signup Fields', 'buddypress' ); ?> 195 </a> 196 </li> 197 <?php endif; ?> 198 191 199 </ul> 192 200 193 201 <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) : … … function xprofile_admin_screen( $message = '', $type = 'error' ) { 294 302 295 303 </fieldset> 296 304 297 <?php if ( empty( $group->can_delete ) ) : ?>298 299 <p><?php esc_html_e( '* Fields in this group appear on the signup page.', 'buddypress' ); ?></p>300 301 <?php endif; ?>302 303 305 </div> 304 306 305 307 <?php endforeach; else : ?> … … function xprofile_admin_screen( $message = '', $type = 'error' ) { 309 311 310 312 <?php endif; ?> 311 313 314 <?php 315 // List fields to use into the signup form. 316 if ( bp_get_signup_allowed() ) { 317 $signup_groups = bp_xprofile_get_groups( 318 array( 319 'fetch_fields' => true, 320 'signup_fields_only' => true, 321 ) 322 ); 323 $has_signup_fields = false; 324 $signup_fields = array(); 325 $signup_fields_order = bp_xprofile_get_signup_field_ids(); 326 ?> 327 <div id="tabs-signup-group"" class="tab-wrapper"> 328 <div class="tab-toolbar"> 329 <p class="description"><?php esc_html_e( 'Drag fields from other groups and drop them on the above tab to include them into your signup form.', 'buddypress' ); ?></a> 330 </div> 331 <fieldset id="signup-fields" class="connectedSortable field-group" aria-live="polite" aria-atomic="true" aria-relevant="all"> 332 <legend class="screen-reader-text"> 333 <?php esc_html_e( 'Fields to use into the signup form', 'buddypress' );?> 334 </legend> 335 336 <?php 337 if ( ! empty( $signup_groups ) ) { 338 foreach ( $signup_groups as $signup_group ) { 339 if ( ! empty( $signup_group->fields ) ) { 340 $has_signup_fields = true; 341 342 foreach ( $signup_group->fields as $signup_field ) { 343 // Load the field. 344 $_signup_field = xprofile_get_field( $signup_field, null, false ); 345 346 /** 347 * This function handles the WYSIWYG profile field 348 * display for the xprofile admin setup screen. 349 */ 350 $signup_fields[ $_signup_field->id ] = bp_xprofile_admin_get_signup_field( $_signup_field, $signup_group, '' ); 351 } 352 } 353 } 354 355 // Output signup fields according to their signup position. 356 foreach ( $signup_fields_order as $ordered_signup_field_id ) { 357 if ( ! isset( $signup_fields[ $ordered_signup_field_id ] ) ) { 358 continue; 359 } 360 361 echo $signup_fields[ $ordered_signup_field_id ]; 362 } 363 } 364 365 if ( ! $has_signup_fields ) { 366 ?> 367 <p class="nodrag nofields"><?php esc_html_e( 'There are no signup fields set. The signup form uses the primary group by default.', 'buddypress' ); ?></p> 368 <?php 369 } 370 ?> 371 </fieldset> 372 373 <p><?php esc_html_e( '* Fields in this group appear on the signup page.', 'buddypress' ); ?></p> 374 </div> 375 <?php 376 } 377 ?> 312 378 </div> 313 379 </form> 314 380 </div> 315 316 381 <?php 317 382 } 318 383 … … function xprofile_admin_delete_field_screen( $field_id, $field_type ) { 730 795 * Handles the ajax reordering of fields within a group. 731 796 * 732 797 * @since 1.0.0 798 * @since 8.0.0 Returns a JSON object. 733 799 */ 734 800 function xprofile_ajax_reorder_fields() { 735 736 801 // Check the nonce. 737 802 check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); 738 803 739 804 if ( empty( $_POST['field_order'] ) ) { 740 return false;805 return wp_send_json_error(); 741 806 } 742 807 743 parse_str( $_POST['field_order'], $order );744 745 808 $field_group_id = $_POST['field_group_id']; 809 $group_tab = ''; 746 810 747 foreach ( (array) $order['draggable_field'] as $position => $field_id ) { 748 xprofile_update_field_position( (int) $field_id, (int) $position, (int) $field_group_id ); 811 if ( isset( $_POST['group_tab'] ) && $_POST['group_tab'] ) { 812 $group_tab = wp_unslash( $_POST['group_tab'] ); 813 } 814 815 if ( 'signup-fields' === $field_group_id ) { 816 parse_str( $_POST['field_order'], $order ); 817 $fields = (array) $order['draggable_signup_field']; 818 $fields = array_map( 'intval', $fields ); 819 820 if ( isset( $_POST['new_signup_field_id'] ) && $_POST['new_signup_field_id'] ) { 821 parse_str( $_POST['new_signup_field_id'], $signup_field ); 822 $signup_fields = (array) $signup_field['draggable_signup_field']; 823 } 824 825 if ( 'signup-group' === $group_tab ) { 826 $field_id = (int) reset( $signup_fields ); 827 828 // Load the field. 829 $field = xprofile_get_field( $field_id, null, false ); 830 831 if ( $field instanceof BP_XProfile_Field ) { 832 $signup_position = bp_xprofile_get_meta( $field_id, 'field', 'signup_position' ); 833 834 if ( ! $signup_position ) { 835 $position = array_search( $field_id, $fields, true ); 836 if ( false !== $position ) { 837 $position += 1; 838 } else { 839 $position = 1; 840 } 841 842 // Set the signup position. 843 bp_xprofile_update_field_meta( $field_id, 'signup_position', $position ); 844 845 // Get the real Group object. 846 $group = xprofile_get_field_group( $field->id ); 847 848 // Gets the HTML Output of the signup field. 849 $signup_field = bp_xprofile_admin_get_signup_field( $field, $group ); 850 851 /** 852 * Fires once a signup field has been inserted. 853 * 854 * @since 8.0.0 855 */ 856 do_action( 'bp_xprofile_inserted_signup_field' ); 857 858 // Send the signup field to output. 859 wp_send_json_success( 860 array( 861 'signup_field' => $signup_field, 862 ) 863 ); 864 } else { 865 wp_send_json_error( 866 array( 867 'message' => __( 'This field has been already added to the signup form.', 'buddypress' ), 868 ) 869 ); 870 } 871 872 } else { 873 wp_send_json_error(); 874 } 875 } else { 876 // it's a sort operation. 877 foreach ( $fields as $position => $field_id ) { 878 bp_xprofile_update_field_meta( (int) $field_id, 'signup_position', (int) $position + 1 ); 879 } 880 881 /** 882 * Fires once the signup fields have been reordered. 883 * 884 * @since 8.0.0 885 */ 886 do_action( 'bp_xprofile_reordered_signup_fields' ); 887 888 wp_send_json_success(); 889 } 890 } else { 891 /** 892 * @todo there's something going wrong here. 893 * moving a field to another tab when there's only the fullname field fails. 894 */ 895 parse_str( $_POST['field_order'], $order ); 896 $fields = (array) $order['draggable_field']; 897 898 foreach ( $fields as $position => $field_id ) { 899 xprofile_update_field_position( (int) $field_id, (int) $position, (int) $field_group_id ); 900 } 901 902 wp_send_json_success(); 749 903 } 750 904 } 751 905 add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' ); 752 906 907 /** 908 * Removes a field from signup fields. 909 * 910 * @since 8.0.0 911 */ 912 function bp_xprofile_ajax_remove_signup_field() { 913 // Check the nonce. 914 check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); 915 916 if ( ! isset( $_POST['signup_field_id'] ) || ! $_POST['signup_field_id'] ) { 917 return wp_send_json_error(); 918 } 919 920 $signup_field_id = (int) wp_unslash( $_POST['signup_field_id'] ); 921 922 // Validate the field ID. 923 $signup_position = bp_xprofile_get_meta( $signup_field_id, 'field', 'signup_position' ); 924 925 if ( ! $signup_position ) { 926 wp_send_json_error(); 927 } 928 929 bp_xprofile_delete_meta( $signup_field_id, 'field', 'signup_position' ); 930 931 /** 932 * Fires when a signup field is removed from the signup form. 933 * 934 * @since 8.0.0 935 */ 936 do_action( 'bp_xprofile_removed_signup_field' ); 937 938 wp_send_json_success(); 939 } 940 add_action( 'wp_ajax_xprofile_remove_signup_field', 'bp_xprofile_ajax_remove_signup_field' ); 941 753 942 /** 754 943 * Handles the reordering of field groups. 755 944 * … … add_action( 'wp_ajax_xprofile_reorder_groups', 'xprofile_ajax_reorder_field_grou 776 965 * Handles the WYSIWYG display of each profile field on the edit screen. 777 966 * 778 967 * @since 1.5.0 968 * @since 8.0.0 Adds the `$is_signup` parameter. 779 969 * 780 970 * @param BP_XProfile_Field $admin_field Admin field. 781 971 * @param object $admin_group Admin group object. 782 972 * @param string $class Classes to append to output. 973 * @param bool $is_signup Whether the admin field output is made inside the signup group. 783 974 */ 784 function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) {975 function xprofile_admin_field( $admin_field, $admin_group, $class = '', $is_signup = false ) { 785 976 global $field; 786 977 787 $field = $admin_field; 978 $field = $admin_field; 979 $fieldset_id = sprintf( 'draggable_field_%d', $field->id ); 788 980 789 981 // Users admin URL. 790 982 $url = bp_get_admin_url( 'users.php' ); … … function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 804 996 'mode' => 'delete_field', 805 997 'field_id' => (int) $field->id 806 998 ), $url . '#tabs-' . (int) $field->group_id ); 807 } ?> 999 } 1000 1001 // Avoid duplicate IDs into the signup group. 1002 if ( $is_signup ) { 1003 $fieldset_id = sprintf( 'draggable_signup_field_%d', $field->id ); 1004 } 1005 ?> 808 1006 809 <fieldset id=" draggable_field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>">1007 <fieldset id="<?php echo esc_attr( $fieldset_id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>"> 810 1008 <legend> 811 1009 <span> 812 1010 <?php bp_the_profile_field_name(); ?> 813 1011 814 1012 <?php if ( empty( $field->can_delete ) ) : ?><?php esc_html_e( '(Primary)', 'buddypress' ); endif; ?> 815 1013 <?php bp_the_profile_field_required_label(); ?> 816 <?php if ( bp_ xprofile_get_meta( $field->id, 'field', 'signup_position' ) ) : ?><?php esc_html_e( '(Sign-up)', 'buddypress' ); endif; ?>1014 <?php if ( bp_get_signup_allowed() && bp_xprofile_get_meta( $field->id, 'field', 'signup_position' ) ) : ?><?php esc_html_e( '(Sign-up)', 'buddypress' ); endif; ?> 817 1015 <?php if ( bp_get_member_types() ) : echo $field->get_member_type_label(); endif; ?> 818 1016 819 1017 <?php … … function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 859 1057 <div class="actions"> 860 1058 <a class="button edit" href="<?php echo esc_url( $field_edit_url ); ?>"><?php _ex( 'Edit', 'Edit field link', 'buddypress' ); ?></a> 861 1059 862 <?php if ( $field->can_delete ) : ?>1060 <?php if ( $field->can_delete && ! $is_signup ) : ?> 863 1061 864 1062 <div class="delete-button"> 865 1063 <a class="confirm submit-delete deletion" href="<?php echo esc_url( wp_nonce_url( $field_delete_url, 'bp_xprofile_delete_field-' . $field->id, 'bp_xprofile_delete_field' ) ); ?>"><?php _ex( 'Delete', 'Delete field link', 'buddypress' ); ?></a> … … function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 867 1065 868 1066 <?php endif; ?> 869 1067 1068 <?php if ( $field->can_delete && $is_signup ) : ?> 1069 1070 <div class="delete-button"> 1071 <a class="submit-delete removal" href="<?php echo esc_attr( sprintf( '#remove_field-%d', $field->id ) ); ?>"><?php echo esc_html_x( 'Remove', 'Remove field link', 'buddypress' ); ?></a> 1072 </div> 1073 1074 <?php endif; ?> 1075 870 1076 <?php 871 1077 872 1078 /** … … function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { 882 1088 </div> 883 1089 </div> 884 1090 </fieldset> 885 886 1091 <?php 887 1092 } 888 1093 1094 /** 1095 * Handles the WYSIWYG display of signup profile fields on the edit screen. 1096 * 1097 * @since 8.0.0 1098 * 1099 * @param BP_XProfile_Field $signup_field The field to use into the signup form. 1100 * @param object $field_group The real field group object. 1101 * @param string $class Classes to append to output. 1102 * @param bool $echo Whether to return or display the HTML output. 1103 * @return string The HTML output. 1104 */ 1105 function bp_xprofile_admin_get_signup_field( $signup_field, $field_group = null, $class = '', $echo = false ) { 1106 add_filter( 'bp_get_the_profile_field_input_name', 'bp_get_the_profile_signup_field_input_name' ); 1107 1108 if ( ! $echo ) { 1109 // Set up an output buffer. 1110 ob_start(); 1111 xprofile_admin_field( $signup_field, $field_group, $class, true ); 1112 $output = ob_get_contents(); 1113 ob_end_clean(); 1114 } else { 1115 xprofile_admin_field( $signup_field, $field_group, $class, true ); 1116 } 1117 1118 remove_filter( 'bp_get_the_profile_field_input_name', 'bp_get_the_profile_signup_field_input_name' ); 1119 1120 if ( ! $echo ) { 1121 return $output; 1122 } 1123 } 1124 889 1125 /** 890 1126 * Print <option> elements containing the xprofile field types. 891 1127 * -
src/bp-xprofile/bp-xprofile-cache.php
diff --git src/bp-xprofile/bp-xprofile-cache.php src/bp-xprofile/bp-xprofile-cache.php index 5c5badae5..6881b7082 100644
function bp_xprofile_reset_user_mid_cache( $user_id ) { 314 314 wp_cache_delete( $user_id, 'bp_user_mid' ); 315 315 } 316 316 add_action( 'profile_update', 'bp_xprofile_reset_user_mid_cache', 10, 1 ); 317 318 /** 319 * Resets the signup field IDs cache. 320 * 321 * @since 8.0.0 322 */ 323 function bp_xprofile_reset_signup_field_cache() { 324 wp_cache_delete( 'signup_fields', 'bp_xprofile' ); 325 } 326 add_action( 'bp_xprofile_inserted_signup_field', 'bp_xprofile_reset_signup_field_cache' ); 327 add_action( 'bp_xprofile_reordered_signup_fields', 'bp_xprofile_reset_signup_field_cache' ); 328 add_action( 'bp_xprofile_removed_signup_field', 'bp_xprofile_reset_signup_field_cache' ); -
src/bp-xprofile/bp-xprofile-filters.php
diff --git src/bp-xprofile/bp-xprofile-filters.php src/bp-xprofile/bp-xprofile-filters.php index 7a2fc06be..e182ec234 100644
function bp_xprofile_register_personal_data_exporter( $exporters ) { 691 691 692 692 return $exporters; 693 693 } 694 695 /** 696 * Used to edit the field input name inside the xProfile Admin Screen 697 * 698 * @see bp_xprofile_admin_get_signup_field() 699 * 700 * @since 8.0.0 701 * 702 * @param string $field_selector The text to use as the input name/id attribute. 703 * @return string The text to use as the input name/id attribute. 704 */ 705 function bp_get_the_profile_signup_field_input_name( $field_selector = '' ) { 706 global $field; 707 708 if ( isset( $field->id ) && $field->id ) { 709 $field_selector = sprintf( 'signup_field_%d', $field->id ); 710 } 711 712 return $field_selector; 713 } -
src/bp-xprofile/bp-xprofile-functions.php
diff --git src/bp-xprofile/bp-xprofile-functions.php src/bp-xprofile/bp-xprofile-functions.php index 9764102f4..284cab369 100644
function bp_xprofile_get_wp_user_keys() { 1420 1420 array_keys( wp_get_user_contact_methods() ) 1421 1421 ); 1422 1422 } 1423 1424 /** 1425 * Returns the signup field IDs. 1426 * 1427 * @since 8.0.0 1428 * 1429 * @return int[] The signup field IDs. 1430 */ 1431 function bp_xprofile_get_signup_field_ids() { 1432 $signup_field_ids = wp_cache_get( 'signup_fields', 'bp_xprofile' ); 1433 1434 if ( ! $signup_field_ids ) { 1435 global $wpdb; 1436 $bp = buddypress(); 1437 1438 $signup_field_ids = $wpdb->get_col( "SELECT object_id FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND meta_key = 'signup_position' ORDER BY meta_value ASC" ); 1439 1440 wp_cache_set( 'signup_fields', $signup_field_ids, 'bp_xprofile' ); 1441 } 1442 1443 return array_map( 'intval', $signup_field_ids ); 1444 } -
src/bp-xprofile/bp-xprofile-template.php
diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php index 10b5188c9..78fff208c 100644
defined( 'ABSPATH' ) || exit; 15 15 * 16 16 * @since 1.0.0 17 17 * @since 2.4.0 Introduced `$member_type` argument. 18 * @since 8.0.0 Introduced `$hide_field_types` argument.18 * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments. 19 19 * 20 20 * @global object $profile_template 21 21 * @see BP_XProfile_Group::get() for full description of `$args` array. … … defined( 'ABSPATH' ) || exit; 36 36 * @type int[]|bool $exclude_groups Default: false. 37 37 * @type int[]|bool $exclude_fields Default: false. 38 38 * @type string[] $hide_field_types Default: empty array. 39 * @type bool $signup_fields_only Default: false. 39 40 * @type bool $update_meta_cache Default: true. 40 41 * } 41 42 * … … function bp_has_profile( $args = '' ) { 68 69 'exclude_groups' => false, // Comma-separated list of profile field group IDs to exclude. 69 70 'exclude_fields' => false, // Comma-separated list of profile field IDs to exclude. 70 71 'hide_field_types' => array(), // List of field types to hide from profile fields loop. 72 'signup_fields_only' => false, // Whether to only return signup fields. 71 73 'update_meta_cache' => true, 72 74 ), 'has_profile' ); 73 75 -
src/bp-xprofile/classes/class-bp-xprofile-data-template.php
diff --git src/bp-xprofile/classes/class-bp-xprofile-data-template.php src/bp-xprofile/classes/class-bp-xprofile-data-template.php index 8aa3a4909..ca478f174 100644
class BP_XProfile_Data_Template { 105 105 * 106 106 * @since 1.5.0 107 107 * @since 2.4.0 Introduced `$member_type` argument. 108 * @since 8.0.0 Introduced `$hide_field_types` argument.108 * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments. 109 109 * 110 110 * @param array|string $args { 111 111 * An array of arguments. All items are optional. … … class BP_XProfile_Data_Template { 120 120 * @type array $exclude_fields Exclude these fields. 121 121 * @type int|bool $hide_empty_fields Should empty fields be skipped. 122 122 * @type int|bool $fetch_visibility_level Fetch visibility levels. 123 * @type int|bool $update_meta_cache Should metadata cache be updated.124 123 * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array. 124 * @type bool $signup_fields_only Whether to only return signup fields. Default: false. 125 * @type int|bool $update_meta_cache Should metadata cache be updated. 125 126 * } 126 127 */ 127 128 public function __construct( $args = '' ) { … … class BP_XProfile_Data_Template { 159 160 'exclude_groups' => false, 160 161 'exclude_fields' => false, 161 162 'hide_field_types' => array(), 163 'signup_fields_only' => false, 162 164 'update_meta_cache' => true 163 165 ) ); 164 166 165 $this->groups = bp_xprofile_get_groups( $r ); 167 $groups = bp_xprofile_get_groups( $r ); 168 169 if ( true === $r['signup_fields_only'] && bp_get_signup_allowed() ) { 170 $signup_fields_order = bp_xprofile_get_signup_field_ids(); 171 $signup_group = new BP_XProfile_Group(); 172 $signup_group->id = 0; 173 $signup_group->name = __( 'Signup Fields', 'buddypress' ); 174 $signup_group->description = ''; 175 $signup_group->can_delete = 0; 176 $signup_group->group_order = 0; 177 $fields = array(); 178 $signup_group->fields = array(); 179 180 // Get all group fields. 181 foreach ( $groups as $group ) { 182 if ( ! $group->fields ) { 183 continue; 184 } 185 186 // Populate fields using the field ID as key. 187 foreach ( $group->fields as $signup_field ) { 188 $fields[ $signup_field->id ] = $signup_field; 189 } 190 } 191 192 if ( $fields ) { 193 // Reorder signup fields. 194 foreach ( $signup_fields_order as $ordered_signup_field_id ) { 195 if ( ! isset( $fields[ $ordered_signup_field_id ] ) ) { 196 continue; 197 } 198 199 $signup_group->fields[] = $fields[ $ordered_signup_field_id ]; 200 } 201 } 202 203 // Override groups with the signup one. 204 $groups = array( $signup_group ); 205 } 206 207 $this->groups = $groups; 166 208 $this->group_count = count( $this->groups ); 167 209 $this->user_id = $r['user_id']; 168 210 } -
src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php
diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php index 3c5828a73..0a2d17404 100644
class BP_XProfile_Field_Type_WordPress_Textbox extends BP_XProfile_Field_Type_Wo 144 144 $this->wp_user_key = self::get_field_settings( bp_get_the_profile_field_id() ); 145 145 } 146 146 147 $field_value = ''; 147 148 if ( 'user_url' === $this->wp_user_key ) { 148 149 if ( bp_displayed_user_id() ) { 149 150 $field_value = bp_get_displayed_user()->userdata->{$this->wp_user_key}; -
src/bp-xprofile/classes/class-bp-xprofile-group.php
diff --git src/bp-xprofile/classes/class-bp-xprofile-group.php src/bp-xprofile/classes/class-bp-xprofile-group.php index b6f196838..6b50d35b6 100644
class BP_XProfile_Group { 238 238 * 239 239 * @since 1.2.0 240 240 * @since 2.4.0 Introduced `$member_type` argument. 241 * @since 8.0.0 Introduced `$hide_field_types` argument.241 * @since 8.0.0 Introduced `$hide_field_types` & `$signup_fields_only` arguments. 242 242 * 243 243 * @global object $wpdb WordPress DB access object. 244 244 * 245 245 * @param array $args { 246 246 * Array of optional arguments: 247 * @type int $profile_group_id Limit results to a single profile group. 248 * @type int $user_id Required if you want to load a specific user's data. 249 * Default: displayed user's ID. 250 * @type array|string $member_type Limit fields by those restricted to a given member type, or array of 251 * member types. If `$user_id` is provided, the value of `$member_type` 252 * will be overridden by the member types of the provided user. The 253 * special value of 'any' will return only those fields that are 254 * unrestricted by member type - i.e., those applicable to any type. 255 * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false. 256 * @type bool $hide_empty_fields True to hide fields where the user has not provided data. 257 * Default: false. 258 * @type bool $fetch_fields Whether to fetch each group's fields. Default: false. 259 * @type bool $fetch_field_data Whether to fetch data for each field. Requires a $user_id. 260 * Default: false. 261 * @type int[]|bool $exclude_groups Comma-separated list or array of group IDs to exclude. 262 * @type int[]|bool $exclude_fields Comma-separated list or array of field IDs to exclude. 263 * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array. 264 * @type bool $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields, 265 * and data. Default: true. 247 * @type int $profile_group_id Limit results to a single profile group. 248 * @type int $user_id Required if you want to load a specific user's data. 249 * Default: displayed user's ID. 250 * @type array|string $member_type Limit fields by those restricted to a given member type, or array of 251 * member types. If `$user_id` is provided, the value of `$member_type` 252 * will be overridden by the member types of the provided user. The 253 * special value of 'any' will return only those fields that are 254 * unrestricted by member type - i.e., those applicable to any type. 255 * @type bool $hide_empty_groups True to hide groups that don't have any fields. Default: false. 256 * @type bool $hide_empty_fields True to hide fields where the user has not provided data. 257 * Default: false. 258 * @type bool $fetch_fields Whether to fetch each group's fields. Default: false. 259 * @type bool $fetch_field_data Whether to fetch data for each field. Requires a $user_id. 260 * Default: false. 261 * @type int[]|bool $exclude_groups Comma-separated list or array of group IDs to exclude. 262 * @type int[]|bool $exclude_fields Comma-separated list or array of field IDs to exclude. 263 * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array. 264 * @type bool $signup_fields_only Whether to only return signup fields. Default: false. 265 * @type bool $update_meta_cache Whether to pre-fetch xprofilemeta for all retrieved groups, fields, 266 * and data. Default: true. 266 267 * } 267 268 * @return array $groups 268 269 */ … … class BP_XProfile_Group { 283 284 'exclude_fields' => false, 284 285 'hide_field_types' => array(), 285 286 'update_meta_cache' => true, 287 'signup_fields_only' => false, 286 288 ) ); 287 289 288 290 // Keep track of object IDs for cache-priming. … … class BP_XProfile_Group { 342 344 // Pull field objects from the cache. 343 345 $fields = array(); 344 346 foreach ( $field_ids as $field_id ) { 347 if ( true === $r['signup_fields_only'] && ! in_array( $field_id, bp_xprofile_get_signup_field_ids(), true ) ) { 348 continue; 349 } 350 345 351 $_field = xprofile_get_field( $field_id, null, false ); 346 352 347 353 if ( in_array( $_field->type, $r['hide_field_types'], true ) ) {