- Timestamp:
- 03/21/2021 02:17:21 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php
r12725 r12868 183 183 $this->type_obj->field_obj = $this; 184 184 } 185 186 /** 187 * Fires when the xProfile field object has been constructed. 188 * 189 * @since 8.0.0 190 * 191 * @param BP_XProfile_Field $this The xProfile field object. 192 */ 193 do_action( 'bp_xprofile_field', $this ); 185 194 } 186 195 … … 807 816 public function get_default_visibility() { 808 817 if ( ! isset( $this->default_visibility ) ) { 809 $this->default_visibility = bp_xprofile_get_meta( $this->id, 'field', 'default_visibility' ); 810 811 if ( ! $this->default_visibility ) { 812 $this->default_visibility = 'public'; 818 $this->default_visibility = 'public'; 819 $this->visibility = ''; 820 821 if ( isset( $this->type_obj->visibility ) && $this->type_obj->visibility ) { 822 $this->visibility = $this->type_obj->visibility; 823 } 824 825 if ( $this->field_type_supports( 'allow_custom_visibility' ) ) { 826 $this->visibility = bp_xprofile_get_meta( $this->id, 'field', 'default_visibility' ); 827 } 828 829 if ( $this->visibility ) { 830 $this->default_visibility = $this->visibility; 813 831 } 814 832 } … … 1319 1337 1320 1338 /** 1339 * Gets field type supports. 1340 * 1341 * @since 8.0.0 1342 * 1343 * @return bool[] Supported features. 1344 */ 1345 public function get_field_type_supports() { 1346 $supports = array( 1347 'switch_fieldtype' => true, 1348 'allow_required' => true, 1349 'allow_autolink' => true, 1350 'allow_custom_visibility' => true, 1351 'member_types' => true, 1352 ); 1353 1354 if ( isset( $this->type_obj ) && $this->type_obj ) { 1355 $field_type = $this->type_obj; 1356 1357 if ( isset( $field_type::$supported_features ) ) { 1358 $supports = array_merge( $supports, $field_type::$supported_features ); 1359 } 1360 } 1361 1362 return $supports; 1363 } 1364 1365 /** 1366 * Checks whether the field type supports the requested feature. 1367 * 1368 * @since 8.0.0 1369 * 1370 * @param string $support The name of the feature. 1371 * @return boolean True if the field type supports the feature. False otherwise. 1372 */ 1373 public function field_type_supports( $support = '' ) { 1374 $retval = true; 1375 $features = $this->get_field_type_supports(); 1376 1377 if ( isset( $features[ $support ] ) ) { 1378 $retval = $features[ $support ]; 1379 } 1380 1381 return $retval; 1382 } 1383 1384 /** 1321 1385 * Private method used to display the submit metabox. 1322 1386 * … … 1443 1507 1444 1508 // The primary field is for all, so bail. 1445 if ( 1 === (int) $this->id ) {1509 if ( 1 === (int) $this->id || ! $this->field_type_supports( 'member_types' ) ) { 1446 1510 return; 1447 1511 } … … 1456 1520 ?> 1457 1521 1458 <div id=" member-types-div" class="postbox">1522 <div id="field-type-member-types" class="postbox"> 1459 1523 <h2><?php _e( 'Member Types', 'buddypress' ); ?></h2> 1460 1524 <div class="inside"> … … 1497 1561 private function visibility_metabox() { 1498 1562 1499 // Default field cannot have custom visibility.1500 if ( true === $this->is_default_field() ) {1563 // Default field and field types not supporting the feature cannot have custom visibility. 1564 if ( true === $this->is_default_field() || ! $this->field_type_supports( 'allow_custom_visibility' ) ) { 1501 1565 return; 1502 1566 } ?> 1503 1567 1504 <div class="postbox" >1568 <div class="postbox" id="field-type-visibiliy-metabox"> 1505 1569 <h2><label for="default-visibility"><?php esc_html_e( 'Visibility', 'buddypress' ); ?></label></h2> 1506 1570 <div class="inside"> … … 1546 1610 private function required_metabox() { 1547 1611 1548 // Default field is alwaysrequired.1549 if ( true === $this->is_default_field() ) {1612 // Default field and field types not supporting the feature cannot be required. 1613 if ( true === $this->is_default_field() || ! $this->field_type_supports( 'required' ) ) { 1550 1614 return; 1551 1615 } ?> 1552 1616 1553 <div class="postbox" >1617 <div class="postbox" id="field-type-required-metabox"> 1554 1618 <h2><label for="required"><?php esc_html_e( 'Requirement', 'buddypress' ); ?></label></h2> 1555 1619 <div class="inside"> … … 1572 1636 */ 1573 1637 private function autolink_metabox() { 1574 ?> 1575 1576 <div class="postbox"> 1638 1639 // Field types not supporting the feature cannot use autolink. 1640 if ( ! $this->field_type_supports( 'do_autolink' ) ) { 1641 return; 1642 } ?> 1643 1644 <div class="postbox" id="field-type-autolink-metabox"> 1577 1645 <h2><?php esc_html_e( 'Autolink', 'buddypress' ); ?></h2> 1578 1646 <div class="inside"> … … 1607 1675 if ( true === $this->is_default_field() ) { 1608 1676 return; 1609 } ?> 1677 } 1678 ?> 1610 1679 1611 1680 <div class="postbox"> 1612 1681 <h2><label for="fieldtype"><?php esc_html_e( 'Type', 'buddypress'); ?></label></h2> 1613 1682 <div class="inside" aria-live="polite" aria-atomic="true" aria-relevant="all"> 1614 <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)"> 1615 1616 <?php bp_xprofile_admin_form_field_types( $this->type ); ?> 1617 1618 </select> 1683 <?php if ( ! $this->field_type_supports( 'switch_fieldtype' ) ) : ?> 1684 <input type="text" disabled="true" value="<?php echo esc_attr( $this->type_obj->name ); ?>"> 1685 <input type="hidden" name="fieldtype" id="fieldtype" value="<?php echo esc_attr( $this->type ); ?>"> 1686 1687 <?php else : ?> 1688 <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)"> 1689 1690 <?php bp_xprofile_admin_form_field_types( $this->type ); ?> 1691 1692 </select> 1693 <?php endif; ?> 1619 1694 1620 1695 <?php … … 1643 1718 wp_nonce_field( 'bp_xprofile_admin_field', 'bp_xprofile_admin_field' ); 1644 1719 1645 // Field 1 is the fullname field, which cannot have custom visibility. 1646 if ( false === $this->is_default_field() ) { 1720 // Init default field hidden inputs. 1721 $default_field_hidden_inputs = array(); 1722 $hidden_fields = array( 1723 'required' => array( 1724 'name' => 'required', 1725 'id' => 'required', 1726 'value' => '0', 1727 ), 1728 'default_visibility' => array( 1729 'name' => 'default-visibility', 1730 'id' => 'default-visibility', 1731 'value' => $this->get_default_visibility(), 1732 ), 1733 'allow_custom_visibility' => array( 1734 'name' => 'allow-custom-visibility', 1735 'id' => 'allow-custom-visibility', 1736 'value' => 'disabled', 1737 ), 1738 'do_autolink' => array( 1739 'name' => 'do_autolink', 1740 'id' => 'do-autolink', 1741 'value' => '', 1742 ), 1743 ); 1744 1745 // Field 1 is the fullname field, which is required. 1746 if ( true === $this->is_default_field() ) { 1747 $default_field_required = $hidden_fields['required']; 1748 $default_field_required['value'] = '1'; 1749 1750 $default_field_hidden_inputs = array( 1751 $default_field_required, 1752 array( 1753 'name' => 'fieldtype', 1754 'id' => 'fieldtype', 1755 'value' => 'textbox', 1756 ), 1757 ); 1758 } 1759 1760 $supports = $this->get_field_type_supports(); 1761 if ( $supports ) { 1762 foreach ( $supports as $feature => $support ) { 1763 if ( true === $support || in_array( $feature, array( 'switch_fieldtype', 'member_types' ), true ) ) { 1764 continue; 1765 } 1766 1767 $default_field_hidden_inputs[] = $hidden_fields[ $feature ]; 1768 1769 if ( 'allow_custom_visibility' === $feature ) { 1770 $default_field_hidden_inputs[] = $hidden_fields['default_visibility']; 1771 } 1772 } 1773 } 1774 1775 if ( ! $default_field_hidden_inputs ) { 1647 1776 return; 1648 } ?> 1649 1650 <input type="hidden" name="required" id="required" value="1" /> 1651 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" /> 1652 1653 <?php 1777 } 1778 1779 foreach ( $default_field_hidden_inputs as $default_field_hidden_input ) { 1780 printf( 1781 '<input type="hidden" name="%1$s" id="%2$s" value="%3$s"/>', 1782 esc_attr( $default_field_hidden_input['name'] ), 1783 esc_attr( $default_field_hidden_input['id'] ), 1784 esc_attr( $default_field_hidden_input['value'] ) 1785 ); 1786 } 1654 1787 } 1655 1788
Note: See TracChangeset
for help on using the changeset viewer.