diff --git src/bp-core/admin/bp-core-admin-tools.php src/bp-core/admin/bp-core-admin-tools.php
index 15058cb10..533586d09 100644
|
|
|
defined( 'ABSPATH' ) || exit;
|
| 16 | 16 | * @since 2.0.0 |
| 17 | 17 | */ |
| 18 | 18 | function bp_core_admin_tools() { |
| | 19 | $warnings = array(); |
| 19 | 20 | ?> |
| 20 | 21 | <div class="wrap"> |
| 21 | 22 | |
| … |
… |
function bp_core_admin_tools() {
|
| 26 | 27 | </p> |
| 27 | 28 | <p class="description"><?php esc_html_e( 'Some of these tools create substantial database overhead. Avoid running more than one repair job at a time.', 'buddypress' ); ?></p> |
| 28 | 29 | |
| 29 | | <form class="settings" method="post" action=""> |
| | 30 | <form class="settings" method="post" action="" id="bp-admin-repair-tools"> |
| 30 | 31 | |
| 31 | 32 | <fieldset> |
| 32 | 33 | <legend><?php esc_html_e( 'Repair tools', 'buddypress' ) ?></legend> |
| 33 | 34 | |
| 34 | 35 | <div class="checkbox"> |
| 35 | | <?php foreach ( bp_admin_repair_list() as $item ) : ?> |
| 36 | | <label for="<?php echo esc_attr( str_replace( '_', '-', $item[0] ) ); ?>"><input type="checkbox" class="checkbox" name="<?php echo esc_attr( $item[0] ) . '" id="' . esc_attr( str_replace( '_', '-', $item[0] ) ); ?>" value="1" /> <?php echo esc_html( $item[1] ); ?></label> |
| | 36 | <?php foreach ( bp_admin_repair_list() as $item ) : |
| | 37 | $repair_id = esc_attr( str_replace( '_', '-', $item[0] ) ); |
| | 38 | |
| | 39 | if ( isset( $item[3] ) ) { |
| | 40 | $warnings[ $repair_id ] = esc_html( $item[3] ); |
| | 41 | } |
| | 42 | ?> |
| | 43 | <label for="<?php echo esc_attr( str_replace( '_', '-', $item[0] ) ); ?>"><input type="checkbox" class="checkbox" name="<?php echo esc_attr( $item[0] ) . '" id="' . $repair_id; ?>" value="1" /> <?php echo esc_html( $item[1] ); ?></label> |
| 37 | 44 | <?php endforeach; ?> |
| 38 | 45 | </div> |
| 39 | 46 | |
| … |
… |
function bp_core_admin_tools() {
|
| 49 | 56 | </div> |
| 50 | 57 | |
| 51 | 58 | <?php |
| | 59 | // Adds a JavaScript confirmation prompt if needed. |
| | 60 | if ( $warnings ) { |
| | 61 | wp_enqueue_script( 'bp-warning-js' ); |
| | 62 | wp_localize_script( 'bp-warning-js', 'bpAdminRepairStrings', array( |
| | 63 | 'warnings' => $warnings, |
| | 64 | 'title' => _n( esc_html__( 'Warning!', 'buddypress' ), esc_html__( 'Warnings!', 'buddypress' ), count( $warnings ) ), |
| | 65 | 'confirm' => esc_html__( 'Do you confirm?', 'buddypress' ), |
| | 66 | 'formId' => 'bp-admin-repair-tools', |
| | 67 | ) ); |
| | 68 | } |
| 52 | 69 | } |
| 53 | 70 | |
| 54 | 71 | /** |
| … |
… |
function bp_admin_repair_list() {
|
| 147 | 164 | 'bp_admin_reinstall_emails', |
| 148 | 165 | ); |
| 149 | 166 | |
| | 167 | // Extended profiles: |
| | 168 | // - Reset custom field visibilities for all users. |
| | 169 | if ( bp_is_active( 'xprofile' ) ) { |
| | 170 | $repair_list[110] = array( |
| | 171 | 'bp-xprofile-user-visibilities', |
| | 172 | __( 'Remove custom field visibilities for all users.', 'buddypress' ), |
| | 173 | 'bp_admin_repair_xprofile_field_visibilities', |
| | 174 | __( 'You selected a repair tool that will completely erase all users custom visibilities.', 'buddypress' ), |
| | 175 | ); |
| | 176 | } |
| | 177 | |
| 150 | 178 | ksort( $repair_list ); |
| 151 | 179 | |
| 152 | 180 | /** |
| … |
… |
function bp_core_admin_debug_information( $debug_info = array() ) {
|
| 567 | 595 | return $debug_info; |
| 568 | 596 | } |
| 569 | 597 | add_filter( 'debug_information', 'bp_core_admin_debug_information' ); |
| | 598 | |
| | 599 | /** |
| | 600 | * Remove custom field visibilities for all users. |
| | 601 | * |
| | 602 | * @since 5.0.0 |
| | 603 | * |
| | 604 | * @return array |
| | 605 | */ |
| | 606 | function bp_admin_repair_xprofile_field_visibilities() { |
| | 607 | $statement = __( 'Removing custom field visibilities for all users… %s', 'buddypress' ); |
| | 608 | delete_metadata( 'user', 0, 'bp_xprofile_visibility_levels', '', true ); |
| | 609 | return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) ); |
| | 610 | } |
diff --git src/bp-core/admin/js/warning.js src/bp-core/admin/js/warning.js
new file mode 100644
index 000000000..96c533941
|
-
|
+
|
|
| | 1 | ( function() { |
| | 2 | if ( typeof window.bpAdminRepairStrings === 'undefined' ) { |
| | 3 | return; |
| | 4 | } |
| | 5 | |
| | 6 | var formId = window.bpAdminRepairStrings.formId || null; |
| | 7 | |
| | 8 | if ( ! formId ) { |
| | 9 | return; |
| | 10 | } |
| | 11 | |
| | 12 | document.querySelector( '#' + formId ).addEventListener( 'submit', function( event ) { |
| | 13 | var warningList = []; |
| | 14 | |
| | 15 | for( e in event.target.elements ) { |
| | 16 | if ( 'undefined' !== typeof event.target.elements[ e ].nodeName ) { |
| | 17 | if ( window.bpAdminRepairStrings.warnings[ event.target.elements[ e ].getAttribute( 'id' ) ] && event.target.elements[ e ].checked ) { |
| | 18 | warningList.push( window.bpAdminRepairStrings.warnings[ event.target.elements[ e ].getAttribute( 'id' ) ] ); |
| | 19 | } |
| | 20 | } |
| | 21 | } |
| | 22 | |
| | 23 | if ( ! warningList.length ) { |
| | 24 | return event; |
| | 25 | } else if ( ! confirm( window.bpAdminRepairStrings.title + "\n" + warningList.join( "\n" ) + "\n" + window.bpAdminRepairStrings.confirm ) ) { |
| | 26 | event.preventDefault(); |
| | 27 | return; |
| | 28 | } |
| | 29 | |
| | 30 | return event; |
| | 31 | } ); |
| | 32 | } () ); |
diff --git src/bp-core/classes/class-bp-admin.php src/bp-core/classes/class-bp-admin.php
index 4f0bd257a..e616209f9 100644
|
|
|
class BP_Admin {
|
| 1143 | 1143 | 'dependencies' => array(), |
| 1144 | 1144 | 'footer' => true, |
| 1145 | 1145 | ), |
| | 1146 | |
| | 1147 | // 5.0 |
| | 1148 | 'bp-warning-js' => array( |
| | 1149 | 'file' => "{$url}warning{$min}.js", |
| | 1150 | 'dependencies' => array(), |
| | 1151 | 'footer' => true, |
| | 1152 | ), |
| 1146 | 1153 | ) ); |
| 1147 | 1154 | |
| 1148 | 1155 | $version = bp_get_version(); |
diff --git src/bp-xprofile/bp-xprofile-functions.php src/bp-xprofile/bp-xprofile-functions.php
index 2ba68eaf8..13dbc0f52 100644
|
|
|
function xprofile_set_field_visibility_level( $field_id = 0, $user_id = 0, $visi
|
| 496 | 496 | // Stored in an array in usermeta. |
| 497 | 497 | $current_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); |
| 498 | 498 | |
| 499 | | if ( !$current_visibility_levels ) { |
| | 499 | if ( ! is_array( $current_visibility_levels ) ) { |
| 500 | 500 | $current_visibility_levels = array(); |
| 501 | 501 | } |
| 502 | 502 | |
| … |
… |
function bp_xprofile_get_fields_by_visibility_levels( $user_id, $levels = array(
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | $user_visibility_levels = bp_get_user_meta( $user_id, 'bp_xprofile_visibility_levels', true ); |
| | 1287 | if ( ! is_array( $user_visibility_levels ) ) { |
| | 1288 | $user_visibility_levels = array(); |
| | 1289 | } |
| 1287 | 1290 | |
| 1288 | 1291 | // Parse the user-provided visibility levels with the default levels, which may take |
| 1289 | 1292 | // precedence. |
diff --git src/bp-xprofile/bp-xprofile-template.php src/bp-xprofile/bp-xprofile-template.php
index 6f5a3c10a..5bf2606c2 100644
|
|
|
function bp_the_profile_field_visibility_level_label() {
|
| 891 | 891 | |
| 892 | 892 | $fields = bp_xprofile_get_visibility_levels(); |
| 893 | 893 | |
| | 894 | // Fallback on public if the level does not exist. |
| | 895 | if ( ! isset( $fields[ $level ]['label'] ) ) { |
| | 896 | $level = 'public'; |
| | 897 | } |
| | 898 | |
| 894 | 899 | /** |
| 895 | 900 | * Filters the profile field visibility level label. |
| 896 | 901 | * |