Ticket #4747: 4747-6.patch
File 4747-6.patch, 21.6 KB (added by , 3 years ago) |
---|
-
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..8393834d3 100644
183 183 */ 184 184 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 185 185 186 if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>187 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"><span id="<?php bp_the_profile_field_input_name(); ?>-2"> 188 <?php189 printf(190 /* translators: %s: level of visibility */191 __( 'This field can be seen by: %s', 'buddypress' ),192 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>'193 );194 ?>195 </span>196 <button type="button" class="visibility-toggle-link" aria-describedby="<?php bp_the_profile_field_input_name(); ?>-2" aria-expanded="false"><?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?></button>197 </p>198 199 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>">200 < fieldset>201 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend>202 203 <?php bp_profile_visibility_radio_buttons() ?>204 205 </fieldset>206 <button type="button" class="field-visibility-settings-close"><?php _e( 'Close', 'buddypress' )?></button>207 208 </div>209 <?php else : ?>210 <p class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">211 <?php212 printf(213 __( 'This field can be seen by: %s', 'buddypress' ),214 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>'215 );216 ?>217 < /p>218 <?php endif ?> 219 220 <?php186 if ( 'checkbox_acceptance' !== bp_get_the_profile_field_type() ) { 187 188 if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : 189 ?> 190 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id(); ?>"><span id="<?php bp_the_profile_field_input_name(); ?>-2"> 191 <?php 192 printf( 193 /* translators: %s: level of visibility */ 194 __( 'This field can be seen by: %s', 'buddypress' ), 195 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>' 196 ); 197 ?> 198 </span> 199 <button type="button" class="visibility-toggle-link" aria-describedby="<?php bp_the_profile_field_input_name(); ?>-2" aria-expanded="false"><?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?></button> 200 </p> 201 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id(); ?>"> 202 <fieldset> 203 <legend><?php _e( 'Who can see this field?', 'buddypress' ); ?></legend> 204 <?php bp_profile_visibility_radio_buttons(); ?> 205 </fieldset> 206 <button type="button" class="field-visibility-settings-close"><?php _e( 'Close', 'buddypress' ); ?></button> 207 </div> 208 <?php else : ?> 209 <p class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id(); ?>"> 210 <?php 211 printf( 212 __( 'This field can be seen by: %s', 'buddypress' ), 213 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>' 214 ); 215 ?> 216 </p> 217 <?php endif ?> 218 219 <?php 220 } 221 221 222 222 /** 223 223 * Fires after the display of the visibility options for xprofile fields. -
src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php src/bp-templates/bp-legacy/buddypress/members/single/profile/edit.php index 6353cccb0..71e8c2a4a 100644
if ( bp_has_profile( 'profile_group_id=' . bp_get_current_profile_group_id() ) ) 56 56 * @since 1.7.0 57 57 */ 58 58 do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); 59 ?>60 61 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?>62 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"><span id="<?php bp_the_profile_field_input_name(); ?>-2">63 <?php64 printf(65 __( 'This field can be seen by: %s', 'buddypress' ),66 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>'67 );68 ?>69 </span>70 <button type="button" class="visibility-toggle-link" aria-describedby="<?php bp_the_profile_field_input_name(); ?>-2" aria-expanded="false"><?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?></button>71 </p>72 73 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>">74 <fieldset>75 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend>76 77 <?php bp_profile_visibility_radio_buttons() ?>78 79 </fieldset>80 <button type="button" class="field-visibility-settings-close"><?php _e( 'Close', 'buddypress' ) ?></button>81 </div>82 <?php else : ?>83 <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>">84 <?php85 printf(86 __( 'This field can be seen by: %s', 'buddypress' ),87 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>'88 );89 ?>90 </div>91 <?php endif ?>92 59 93 <?php 60 if ( 'checkbox_acceptance' !== bp_get_the_profile_field_type() ) { 61 62 if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> 63 <p class="field-visibility-settings-toggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"><span id="<?php bp_the_profile_field_input_name(); ?>-2"> 64 <?php 65 printf( 66 __( 'This field can be seen by: %s', 'buddypress' ), 67 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>' 68 ); 69 ?> 70 </span> 71 <button type="button" class="visibility-toggle-link" aria-describedby="<?php bp_the_profile_field_input_name(); ?>-2" aria-expanded="false"><?php _ex( 'Change', 'Change profile field visibility level', 'buddypress' ); ?></button> 72 </p> 73 74 <div class="field-visibility-settings" id="field-visibility-settings-<?php bp_the_profile_field_id() ?>"> 75 <fieldset> 76 <legend><?php _e( 'Who can see this field?', 'buddypress' ) ?></legend> 77 78 <?php bp_profile_visibility_radio_buttons() ?> 79 80 </fieldset> 81 <button type="button" class="field-visibility-settings-close"><?php _e( 'Close', 'buddypress' ) ?></button> 82 </div> 83 <?php else : ?> 84 <div class="field-visibility-settings-notoggle" id="field-visibility-settings-toggle-<?php bp_the_profile_field_id() ?>"> 85 <?php 86 printf( 87 __( 'This field can be seen by: %s', 'buddypress' ), 88 '<span class="current-visibility-level">' . bp_get_the_profile_field_visibility_level_label() . '</span>' 89 ); 90 ?> 91 </div> 92 <?php endif ?> 93 94 <?php 95 } 94 96 95 97 /** 96 98 * Fires after the visibility options for a field. -
src/bp-templates/bp-legacy/buddypress/members/single/profile/profile-loop.php
diff --git src/bp-templates/bp-legacy/buddypress/members/single/profile/profile-loop.php src/bp-templates/bp-legacy/buddypress/members/single/profile/profile-loop.php index 4f2185051..eb25a3c85 100644
do_action( 'bp_before_profile_loop_content' ); ?> 27 27 28 28 <table class="profile-fields"> 29 29 30 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> 30 <?php while ( bp_profile_fields() ) : bp_the_profile_field(); 31 32 if ( 'checkbox_acceptance' === bp_get_the_profile_field_type() ) { 33 continue; 34 } 35 ?> 31 36 32 37 <?php if ( bp_field_has_data() ) : ?> 33 38 -
src/bp-templates/bp-nouveau/buddypress/members/single/parts/profile-visibility.php
diff --git src/bp-templates/bp-nouveau/buddypress/members/single/parts/profile-visibility.php src/bp-templates/bp-nouveau/buddypress/members/single/parts/profile-visibility.php index 24d9b43db..bba640059 100644
9 9 if ( empty( $GLOBALS['profile_template'] ) ) { 10 10 return; 11 11 } 12 13 if ( 'checkbox_acceptance' === bp_get_the_profile_field_type() ) { 14 return; 15 } 16 12 17 ?> 13 18 14 19 <?php if ( bp_current_user_can( 'bp_xprofile_change_field_visibility' ) ) : ?> -
src/bp-templates/bp-nouveau/buddypress/members/single/profile/profile-loop.php
diff --git src/bp-templates/bp-nouveau/buddypress/members/single/profile/profile-loop.php src/bp-templates/bp-nouveau/buddypress/members/single/profile/profile-loop.php index 2edf47815..1523481b7 100644
17 17 <?php 18 18 while ( bp_profile_groups() ) : 19 19 bp_the_profile_group(); 20 ?>20 ?> 21 21 22 22 <?php if ( bp_profile_group_has_fields() ) : ?> 23 23 … … 34 34 <?php 35 35 while ( bp_profile_fields() ) : 36 36 bp_the_profile_field(); 37 ?> 37 38 if ( 'checkbox_acceptance' === bp_get_the_profile_field_type() ) { 39 continue; 40 } 41 ?> 38 42 39 43 <?php if ( bp_field_has_data() ) : ?> 40 44 -
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..47b8c0a7c 100644
function xprofile_update_field_group_position( $field_group_id = 0, $position = 149 149 */ 150 150 function bp_xprofile_get_field_types() { 151 151 $fields = array( 152 'checkbox' => 'BP_XProfile_Field_Type_Checkbox', 153 'datebox' => 'BP_XProfile_Field_Type_Datebox', 154 'multiselectbox' => 'BP_XProfile_Field_Type_Multiselectbox', 155 'number' => 'BP_XProfile_Field_Type_Number', 156 'url' => 'BP_XProfile_Field_Type_URL', 157 'radio' => 'BP_XProfile_Field_Type_Radiobutton', 158 'selectbox' => 'BP_XProfile_Field_Type_Selectbox', 159 'textarea' => 'BP_XProfile_Field_Type_Textarea', 160 'textbox' => 'BP_XProfile_Field_Type_Textbox', 161 'telephone' => 'BP_XProfile_Field_Type_Telephone', 162 'wp-biography' => 'BP_XProfile_Field_Type_WordPress_Biography', 163 'wp-textbox' => 'BP_XProfile_Field_Type_WordPress_Textbox', 152 'checkbox' => 'BP_XProfile_Field_Type_Checkbox', 153 'datebox' => 'BP_XProfile_Field_Type_Datebox', 154 'multiselectbox' => 'BP_XProfile_Field_Type_Multiselectbox', 155 'number' => 'BP_XProfile_Field_Type_Number', 156 'url' => 'BP_XProfile_Field_Type_URL', 157 'radio' => 'BP_XProfile_Field_Type_Radiobutton', 158 'selectbox' => 'BP_XProfile_Field_Type_Selectbox', 159 'textarea' => 'BP_XProfile_Field_Type_Textarea', 160 'textbox' => 'BP_XProfile_Field_Type_Textbox', 161 'telephone' => 'BP_XProfile_Field_Type_Telephone', 162 'wp-biography' => 'BP_XProfile_Field_Type_WordPress_Biography', 163 'wp-textbox' => 'BP_XProfile_Field_Type_WordPress_Textbox', 164 'checkbox_acceptance' => 'BP_XProfile_Field_Type_Checkbox_Acceptance', 164 165 ); 165 166 166 167 /** -
new file src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox-acceptance.php
diff --git src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox-acceptance.php src/bp-xprofile/classes/class-bp-xprofile-field-type-checkbox-acceptance.php new file mode 100644 index 000000000..3e26551e1
- + 1 <?php 2 /** 3 * BuddyPress XProfile Classes. 4 * 5 * @package BuddyPress 6 * @subpackage XProfileClasses 7 * @since 8.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Checkbox Acceptance xProfile field type. 15 * 16 * @since 8.0.0 17 */ 18 class BP_XProfile_Field_Type_Checkbox_Acceptance extends BP_XProfile_Field_Type { 19 20 /** 21 * Supported features for the Checkbox Acceptance field type. 22 * 23 * @since 8.0.0 24 * @var bool[] The WordPress field supported features. 25 */ 26 public static $supported_features = array( 27 'switch_fieldtype' => false, 28 'required' => false, 29 'do_autolink' => false, 30 'allow_custom_visibility' => false, 31 ); 32 33 /** 34 * Constructor for the Checkbox Acceptance field type. 35 * 36 * @since 8.0.0 37 */ 38 public function __construct() { 39 parent::__construct(); 40 41 $this->name = _x( 'Checkbox Acceptance', 'xprofile field type', 'buddypress' ); 42 $this->category = _x( 'Single Fields', 'xprofile field type category', 'buddypress' ); 43 44 $this->supports_options = false; 45 $this->do_settings_section = true; 46 47 $this->set_format( '/^.+$/', 'replace' ); 48 49 /** 50 * Fires inside __construct() method for bp_xprofile_field_type_checkbox_acceptance class. 51 * 52 * @since 8.0.0 53 * 54 * @param BP_XProfile_Field_Type_Checkbox_Acceptance $this Current instance of the Checkbox Acceptance field type. 55 */ 56 do_action( 'bp_xprofile_field_type_checkbox_acceptance', $this ); 57 } 58 59 60 /** 61 * Output the edit field HTML for this field type. 62 * 63 * Must be used inside the {@link bp_profile_fields()} template loop. 64 * 65 * @since 8.0.0 66 * 67 * @param array $raw_properties Optional key/value array of 68 * {@link http://dev.w3.org/html5/markup/textarea.html permitted attributes} 69 * that you want to add. 70 */ 71 public function edit_field_html( array $raw_properties = array() ) { 72 $user_id = bp_displayed_user_id(); 73 74 if ( isset( $raw_properties['user_id'] ) ) { 75 $user_id = (int) $raw_properties['user_id']; 76 unset( $raw_properties['user_id'] ); 77 } 78 79 // HTML5 required attribute. 80 if ( bp_get_the_profile_field_is_required() ) { 81 $raw_properties['required'] = 'required'; 82 $required = true; 83 } else { 84 $raw_properties['required'] = 'required'; 85 $required = true; 86 } 87 ?> 88 <legend> 89 <?php bp_the_profile_field_name(); ?> 90 <?php bp_the_profile_field_required_label(); ?> 91 </legend> 92 93 <?php 94 /** This action is documented in bp-xprofile/bp-xprofile-classes */ 95 do_action( bp_get_the_profile_field_errors_action() ); 96 ?> 97 98 <?php 99 bp_the_profile_field_options( 100 array( 101 'user_id' => $user_id, 102 'required' => $required, 103 ) 104 ); 105 ?> 106 107 <?php if ( bp_get_the_profile_field_description() ) : ?> 108 <p class="description" tabindex="0"><?php bp_the_profile_field_description(); ?></p> 109 <?php 110 endif; 111 } 112 113 /** 114 * Field html for Admin-> User->Profile Fields screen. 115 * 116 * @since 8.0.0 117 * 118 * @param array $raw_properties properties. 119 */ 120 public function admin_field_html( array $raw_properties = array() ) { 121 122 $bp_xprofile_tos_page = bp_xprofile_get_meta( bp_get_the_profile_field_id(), 'field', 'bp_xprofile_tos_page', true ); 123 124 $raw_properties['required'] = 'required'; 125 $required = true; 126 $html = $this->get_edit_field_html_elements( 127 array_merge( 128 array( 'type' => 'checkbox' ), 129 $raw_properties 130 ) 131 ); 132 ?> 133 <label for="<?php bp_the_profile_field_input_name(); ?>"> 134 <input <?php echo wp_kses_post( $html ); ?>> 135 <?php 136 /* translators: %s: bp xprofile tos page */ 137 echo sprintf( __( 'I agree to %s ', 'buddypress' ), '<a href="' . esc_url( get_permalink( $bp_xprofile_tos_page ) ) . '">' . esc_html( get_the_title( $bp_xprofile_tos_page ) ) . '</a>' ); 138 ?> 139 </label> 140 <?php 141 } 142 143 /** 144 * Admin new field screen. 145 * 146 * @since 8.0.0 147 * 148 * @param BP_XProfile_Field $current_field Profile field object. 149 * @param string $control_type Control type. 150 */ 151 public function admin_new_field_html( BP_XProfile_Field $current_field, $control_type = '' ) { 152 $type = array_search( get_class( $this ), bp_xprofile_get_field_types() ); 153 154 if ( false === $type ) { 155 return; 156 } 157 158 $class = $current_field->type != $type ? 'display: none;' : ''; 159 $bp_xprofile_tos_page = bp_xprofile_get_meta( $current_field->id, 'field', 'bp_xprofile_tos_page', true ); 160 161 ?> 162 <div id="<?php echo esc_attr( $type ); ?>" class="postbox bp-options-box" style="<?php echo esc_attr( $class ); ?> margin-top: 15px;"> 163 <h3><?php esc_html_e( 'Please select page for Terms of Service:', 'buddypress' ); ?></h3> 164 <div class="inside"> 165 <p> 166 <?php 167 echo wp_dropdown_pages( 168 array( 169 'name' => 'bp_xprofile_tos_page', 170 'echo' => false, 171 'show_option_none' => __( '- None -', 'buddypress' ), 172 'selected' => ! empty( $bp_xprofile_tos_page ) ? $bp_xprofile_tos_page : false, 173 ) 174 ); 175 ?> 176 177 <?php if ( ! empty( $bp_xprofile_tos_page ) && get_post( $bp_xprofile_tos_page ) ) : ?> 178 179 <a href="<?php echo esc_url( get_permalink( $bp_xprofile_tos_page ) ); ?>" class="button-secondary" target="_bp"> 180 <?php esc_html_e( 'View', 'buddypress' ); ?> <span class="dashicons dashicons-external" aria-hidden="true"></span> 181 <span class="screen-reader-text"><?php esc_html_e( '(opens in a new tab)', 'buddypress' ); ?></span> 182 </a> 183 184 <?php endif; ?> 185 </p> 186 </div> 187 </div> 188 <?php 189 } 190 191 /** 192 * Save settings from the field edit screen in the Dashboard. 193 * 194 * @since 8.0.0 195 * 196 * @param int $field_id ID of the field. 197 * @param array $settings Array of settings. 198 * @return bool True on success. 199 */ 200 public function admin_save_settings( $field_id, $settings ) { 201 202 if ( isset( $_POST['bp_xprofile_tos_page'] ) ) { 203 bp_xprofile_update_meta( $field_id, 'field', 'bp_xprofile_tos_page', sanitize_text_field( wp_unslash( $_POST['bp_xprofile_tos_page'] ) ) ); 204 } 205 206 return true; 207 } 208 209 /** 210 * Profile edit/register options html. 211 * 212 * @since 8.0.0 213 * 214 * @param array $args args. 215 */ 216 public function edit_field_options_html( array $args = array() ) { 217 218 $checkbox_acceptance = maybe_unserialize( \BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ) ); 219 220 if ( ! empty( $_POST[ 'field_' . $this->field_obj->id ] ) ) { 221 $new_checkbox_acceptance = sanitize_text_field( wp_unslash( $_POST[ 'field_' . $this->field_obj->id ] ) ); 222 $checkbox_acceptance = ( $checkbox_acceptance != $new_checkbox_acceptance ) ? $new_checkbox_acceptance : $checkbox_acceptance; 223 } 224 225 $checkbox_acceptance = absint( $checkbox_acceptance ); 226 227 $atts = array( 228 'type' => 'checkbox', 229 'name' => bp_get_the_profile_field_input_name(), 230 'id' => bp_get_the_profile_field_input_name(), 231 'value' => 1, 232 'class' => 'bp-xprofile-tos-checkbox', 233 'required' => 'required', 234 ); 235 236 if ( 1 === $checkbox_acceptance ) { 237 $atts['checked'] = 'checked'; 238 $atts['readonly'] = 'readonly'; 239 $atts['onclick'] = 'return false;'; 240 } 241 242 $bp_xprofile_tos_page = bp_xprofile_get_meta( bp_get_the_profile_field_id(), 'field', 'bp_xprofile_tos_page', true ); 243 244 $html = '<div class="bp-xprofile-checkbox-acceptance-field"><input ' . $this->get_edit_field_html_elements( $atts ) . ' />'; 245 // we should most probably avoid kses on output. 246 $html .= sprintf( 247 /* translators: %s: search term */ 248 __( 'I agree to %s ', 'buddypress' ), 249 '<a href="' . esc_url( get_permalink( $bp_xprofile_tos_page ) ) . '">' . esc_html( get_the_title( $bp_xprofile_tos_page ) ) . '</a>' ); 250 251 $html .= '</div>'; 252 echo apply_filters( 'bp_get_the_profile_field_checkbox_acceptance', $html, $args['type'], $this->field_obj->id, $checkbox_acceptance ); 253 } 254 255 /** 256 * Check if field is valid? 257 * 258 * @since 8.0.0 259 * 260 * @param string|int $values value. 261 * @return bool 262 */ 263 public function is_valid( $value ) { 264 265 if ( empty( $value ) || '1' === $value ) { 266 return true; 267 } 268 269 return false; 270 } 271 272 /** 273 * Modify the appearance of value. 274 * 275 * @since 8.0.0 276 * 277 * @param string $field_value Original value of field. 278 * @param int $field_id field id. 279 * 280 * @return string Value formatted 281 */ 282 public static function display_filter( $field_value, $field_id = 0 ) { 283 return empty( $field_value ) ? __( 'No', 'buddypress' ) : __( 'Yes', 'buddypress' ); 284 } 285 286 287 /** 288 * Gte the field value by user id 289 * 290 * @param int $user_id User id whose field value to be get 291 * @param integer $field_id 292 * @return void 293 */ 294 public function get_field_value( $user_id, $field_id = 0 ) { 295 return $user_id; 296 } 297 } -
src/bp-xprofile/classes/class-bp-xprofile-user-admin.php
diff --git src/bp-xprofile/classes/class-bp-xprofile-user-admin.php src/bp-xprofile/classes/class-bp-xprofile-user-admin.php index ef71072c5..7eff5f446 100644
class BP_XProfile_User_Admin { 273 273 $r = bp_parse_args( $args['args'], array( 274 274 'profile_group_id' => 0, 275 275 'user_id' => $user->ID, 276 'hide_field_types' => array( 'wp-textbox', 'wp-biography' ),276 'hide_field_types' => array( 'wp-textbox', 'wp-biography', 'checkbox_acceptance' ), 277 277 ), 'bp_xprofile_user_admin_profile_loop_args' ); 278 278 279 279 // We really need these args.