Changeset 12885
- Timestamp:
- 04/16/2021 05:29:26 AM (4 years ago)
- Location:
- trunk/src/bp-xprofile
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-functions.php
r12882 r12885 1422 1422 ); 1423 1423 } 1424 1425 /** 1426 * Returns the signup field IDs. 1427 * 1428 * @since 8.0.0 1429 * 1430 * @return int[] The signup field IDs. 1431 */ 1432 function bp_xprofile_get_signup_field_ids() { 1433 $signup_field_ids = wp_cache_get( 'signup_fields', 'bp_xprofile' ); 1434 1435 if ( ! $signup_field_ids ) { 1436 global $wpdb; 1437 $bp = buddypress(); 1438 1439 $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" ); 1440 1441 wp_cache_set( 'signup_fields', $signup_field_ids, 'bp_xprofile' ); 1442 } 1443 1444 return array_map( 'intval', $signup_field_ids ); 1445 } 1446 1447 /** 1448 * Returns xProfile loop's signup arguments. 1449 * 1450 * @since 8.0.0 1451 * 1452 * @param array $extra Optional extra arguments. 1453 * @return array The xProfile loop's signup arguments. 1454 */ 1455 function bp_xprofile_signup_args( $extra = array() ) { 1456 $signup_fields = (array) bp_xprofile_get_signup_field_ids(); 1457 $default_args = array( 1458 'fetch_fields' => true, 1459 'fetch_field_data' => false, 1460 ); 1461 1462 // No signup fields? Let's bring back primary group. 1463 if ( ! $signup_fields && bp_is_register_page() ) { 1464 $default_args['profile_group_id'] = 1; 1465 } else { 1466 $default_args['signup_fields_only'] = true; 1467 } 1468 1469 return array_merge( $default_args, $extra ); 1470 } -
trunk/src/bp-xprofile/bp-xprofile-template.php
r12868 r12885 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 … … 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 * } … … 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' ); -
trunk/src/bp-xprofile/classes/class-bp-xprofile-data-template.php
r12868 r12885 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 { … … 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 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. 123 125 * @type int|bool $update_meta_cache Should metadata cache be updated. 124 * @type string[] $hide_field_types List of field types to hide form loop. Default: empty array.125 126 * } 126 127 */ … … 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']; -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress-textbox.php
r12871 r12885 145 145 } 146 146 147 $field_value = ''; 147 148 if ( 'user_url' === $this->wp_user_key ) { 148 149 if ( bp_displayed_user_id() ) { -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field-type-wordpress.php
r12870 r12885 57 57 'allow_custom_visibility' => false, 58 58 'member_types' => false, 59 'signup_position' => true, 59 60 ); 60 61 -
trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php
r12868 r12885 139 139 */ 140 140 public $do_autolink; 141 142 /** 143 * The signup position of the field into the signups form. 144 * 145 * @since 8.0.0 146 * @var int 147 */ 148 public $signup_position; 141 149 142 150 /** … … 861 869 862 870 /** 871 * Get the field's signup position. 872 * 873 * @since 8.0.0 874 * 875 * @return int the field's signup position. 876 * 0 if the field has not been added to the signup form. 877 */ 878 public function get_signup_position() { 879 if ( ! isset( $this->signup_position ) ) { 880 $this->signup_position = (int) bp_xprofile_get_meta( $this->id, 'field', 'signup_position' ); 881 } 882 883 return $this->signup_position; 884 } 885 886 /** 863 887 * Get whether the field values should be auto-linked to a directory search. 864 888 * … … 1278 1302 $this->required_metabox(); 1279 1303 1304 // Output signup position metabox. 1305 $this->signup_position_metabox(); 1306 1280 1307 // Output the Member Types metabox. 1281 1308 $this->member_type_metabox(); … … 1346 1373 $supports = array( 1347 1374 'switch_fieldtype' => true, 1348 ' allow_required'=> true,1349 ' allow_autolink'=> true,1375 'required' => true, 1376 'do_autolink' => true, 1350 1377 'allow_custom_visibility' => true, 1351 1378 'member_types' => true, 1379 'signup_position' => true, 1352 1380 ); 1353 1381 … … 1503 1531 * 1504 1532 * @since 2.4.0 1533 * 1534 * @return void If default field or if the field does not support the feature. 1505 1535 */ 1506 1536 private function member_type_metabox() { 1507 1537 1508 1538 // The primary field is for all, so bail. 1509 if ( 1 === (int) $this->id|| ! $this->field_type_supports( 'member_types' ) ) {1539 if ( true === $this->is_default_field() || ! $this->field_type_supports( 'member_types' ) ) { 1510 1540 return; 1511 1541 } … … 1557 1587 * @since 2.3.0 1558 1588 * 1559 * @return void If default field id 1.1589 * @return void If default field or if the field does not support the feature. 1560 1590 */ 1561 1591 private function visibility_metabox() { … … 1606 1636 * @since 2.3.0 1607 1637 * 1608 * @return void If default field .1638 * @return void If default field or if the field does not support the feature. 1609 1639 */ 1610 1640 private function required_metabox() { … … 1633 1663 * @since 2.5.0 1634 1664 * 1635 * @return void If default field id 1.1665 * @return void If the field does not support the feature. 1636 1666 */ 1637 1667 private function autolink_metabox() { … … 1704 1734 1705 1735 <?php 1736 } 1737 1738 /** 1739 * Output the metabox for setting the field's position into the signup form. 1740 * 1741 * @since 8.0.0 1742 * 1743 * @return void If default field or if the field does not support the feature. 1744 */ 1745 private function signup_position_metabox() { 1746 // Field types not supporting the feature cannot be added to signups form. 1747 if ( ! $this->field_type_supports( 'signup_position' ) || true === $this->is_default_field() ) { 1748 return; 1749 } 1750 1751 $next_signup_position = 1; 1752 $signup_position = $this->get_signup_position(); 1753 1754 if ( 0 === $signup_position ) { 1755 $signup_fields_order = bp_xprofile_get_signup_field_ids(); 1756 $next_signup_position = count( $signup_fields_order ) + 1; 1757 } else { 1758 $next_signup_position = $signup_position; 1759 } 1760 ?> 1761 1762 <div class="postbox" id="field-signup-position-metabox"> 1763 <h2><label for="default-visibility"><?php esc_html_e( 'Signups', 'buddypress' ); ?></label></h2> 1764 <div class="inside"> 1765 <div> 1766 <ul> 1767 <li> 1768 <input type="checkbox" id="has-signup-position" name="signup-position" value="<?php echo esc_attr( $next_signup_position ); ?>" <?php checked( $signup_position, $next_signup_position ); ?> /> 1769 <label for="has-signup-position"><?php esc_html_e( 'Use the field into the registration form.', 'buddypress' ); ?></label> 1770 </li> 1771 </ul> 1772 </div> 1773 </div> 1774 </div> 1775 <?php 1706 1776 } 1707 1777 … … 1755 1825 'value' => 'textbox', 1756 1826 ), 1827 array( 1828 'name' => 'signup-position', 1829 'id' => 'has-signup-position', 1830 'value' => $this->get_signup_position(), 1831 ), 1757 1832 ); 1758 1833 } -
trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php
r12868 r12885 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. … … 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 … … 284 285 'hide_field_types' => array(), 285 286 'update_meta_cache' => true, 287 'signup_fields_only' => false, 286 288 ) ); 287 289 … … 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
Note: See TracChangeset
for help on using the changeset viewer.