Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/10/2018 09:34:15 PM (9 years ago)
Author:
johnjamesjacoby
Message:

XProfile: use bp_get_admin_url() where appropriate.

This change updates all inline and querystring-based URL references to users.php to instead use the built-in supplied wrapper function. This comes with a few benefits:

  • URLs will be consistent across BuddyPress installation configurations (rather than relative to the current admin dashboard area)
  • Code is cleaner and easier to understand
  • Variable IDs are now cast to integers as needed (where they were not all previously)

Bonus: also updates a few bp_get_admin_url() calls in the about page to use the second parameter of add_query_arg() rather than wrapping it entirely, to match the expected usage format of all add_query_arg() calls.

Fixes #7536. Props JohnPBloch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r11741 r11808  
    125125function xprofile_admin_screen( $message = '', $type = 'error' ) {
    126126
     127        // Users admin URL
     128        $url = bp_get_admin_url( 'users.php' );
     129
     130        // Add Group
     131        $add_group_url = add_query_arg( array(
     132                'page' => 'bp-profile-setup',
     133                'mode' => 'add_group'
     134        ), $url );
     135
    127136        // Validate type.
    128137        $type = preg_replace( '|[^a-z]|i', '', $type );
     
    138147                        <h1 class="wp-heading-inline"><?php _ex( 'Profile Fields', 'Settings page header', 'buddypress'); ?></h1>
    139148
    140                                 <a id="add_group" class="page-title-action" href="users.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a>
     149                                <a id="add_group" class="page-title-action" href="<?php echo esc_url( $add_group_url ); ?>"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a>
    141150
    142151                        <hr class="wp-header-end">
     
    146155                        <h1>
    147156                                <?php _ex( 'Profile Fields', 'Settings page header', 'buddypress'); ?>
    148                                 <a id="add_group" class="add-new-h2" href="users.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a>
     157                                <a id="add_group" class="add-new-h2" href="<?php echo esc_url( $add_group_url ); ?>"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a>
    149158                        </h1>
    150159
     
    190199                                </ul>
    191200
    192                                 <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) : ?>
     201                                <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) :
     202
     203                                        // Add Field to Group URL
     204                                        $add_field_url = add_query_arg( array(
     205                                                'page'     => 'bp-profile-setup',
     206                                                'mode'     => 'add_field',
     207                                                'group_id' => (int) $group->id
     208                                        ), $url );
     209
     210                                        // Edit Group URL
     211                                        $edit_group_url = add_query_arg( array(
     212                                                'page'     => 'bp-profile-setup',
     213                                                'mode'     => 'edit_group',
     214                                                'group_id' => (int) $group->id
     215                                        ), $url );
     216
     217                                        // Delete Group URL
     218                                        $delete_group_url = wp_nonce_url( add_query_arg( array(
     219                                                'page'     => 'bp-profile-setup',
     220                                                'mode'     => 'delete_group',
     221                                                'group_id' => (int) $group->id
     222                                        ), $url ), 'bp_xprofile_delete_group' ); ?>
    193223
    194224                                        <noscript>
     
    202232                                                <div class="tab-toolbar">
    203233                                                        <div class="tab-toolbar-left">
    204                                                                 <a class="button-primary" href="users.php?page=bp-profile-setup&amp;group_id=<?php echo esc_attr( $group->id ); ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ); ?></a>
    205                                                                 <a class="button edit" href="users.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=<?php echo esc_attr( $group->id ); ?>"><?php _ex( 'Edit Group', 'Edit Profile Fields Group', 'buddypress' ); ?></a>
     234                                                                <a class="button-primary" href="<?php echo esc_url( $add_field_url ); ?>"><?php _e( 'Add New Field', 'buddypress' ); ?></a>
     235                                                                <a class="button edit" href="<?php echo esc_url( $edit_group_url ); ?>"><?php _ex( 'Edit Group', 'Edit Profile Fields Group', 'buddypress' ); ?></a>
    206236
    207237                                                                <?php if ( $group->can_delete ) : ?>
    208238
    209239                                                                        <div class="delete-button">
    210                                                                                 <a class="confirm submitdelete deletion ajax-option-delete" href="<?php echo esc_url( wp_nonce_url( 'users.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=' . intval( $group->id ), 'bp_xprofile_delete_group' ) ); ?>"><?php _ex( 'Delete Group', 'Delete Profile Fields Group', 'buddypress' ); ?></a>
     240                                                                                <a class="confirm submitdelete deletion ajax-option-delete" href="<?php echo esc_url( $delete_group_url ); ?>"><?php _ex( 'Delete Group', 'Delete Profile Fields Group', 'buddypress' ); ?></a>
    211241                                                                        </div>
    212242
     
    284314
    285315                                        <div id="message" class="error"><p><?php _ex( 'You have no groups.', 'You have no profile fields groups.', 'buddypress' ); ?></p></div>
    286                                         <p><a href="users.php?page=bp-profile-setup&amp;mode=add_group"><?php _ex( 'Add New Group', 'Add New Profile Fields Group', 'buddypress' ); ?></a></p>
     316                                        <p><a href="<?php echo esc_url( $add_group_url ); ?>"><?php _ex( 'Add New Group', 'Add New Profile Fields Group', 'buddypress' ); ?></a></p>
    287317
    288318                                <?php endif; ?>
     
    620650        $field = $admin_field;
    621651
    622         $field_edit_url = add_query_arg(
    623                 array(
     652        // Users admin URL
     653        $url = bp_get_admin_url( 'users.php' );
     654
     655        // Edit
     656        $field_edit_url = add_query_arg( array(
     657                'page'     => 'bp-profile-setup',
     658                'mode'     => 'edit_field',
     659                'group_id' => (int) $field->group_id,
     660                'field_id' => (int) $field->id
     661        ), $url );
     662
     663        // Delete
     664        if ( $field->can_delete ) {
     665                $field_delete_url = add_query_arg( array(
    624666                        'page'     => 'bp-profile-setup',
    625                         'group_id' => (int) $field->group_id,
    626                         'field_id' => (int) $field->id,
    627                         'mode'     => 'edit_field'
    628                 ),
    629                 bp_get_admin_url( 'users.php' )
    630         );
    631 
    632         if ( $field->can_delete ) {
    633                 $field_delete_url = add_query_arg(
    634                         array(
    635                                 'page'     => 'bp-profile-setup',
    636                                 'field_id' => (int) $field->id,
    637                                 'mode'     => 'delete_field'
    638                         ),
    639                         bp_get_admin_url( 'users.php' ) . '#tabs-' . (int) $field->group_id
    640                 );
    641         }
    642         ?>
     667                        'mode'     => 'delete_field',
     668                        'field_id' => (int) $field->id
     669                ), $url . '#tabs-' . (int) $field->group_id );
     670        } ?>
    643671
    644672        <fieldset id="draggable_field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>">
     
    647675                                <?php bp_the_profile_field_name(); ?>
    648676
    649                                 <?php if ( empty( $field->can_delete )                                    ) : ?><?php esc_html_e( '(Primary)',  'buddypress' ); endif; ?>
     677                                <?php if ( empty( $field->can_delete )                                    ) : ?><?php esc_html_e( '(Primary)', 'buddypress' ); endif; ?>
    650678                                <?php bp_the_profile_field_required_label(); ?>
    651                                 <?php if ( bp_xprofile_get_meta( $field->id, 'field', 'signup_position' ) ) : ?><?php esc_html_e( '(Sign-up)',  'buddypress' ); endif; ?>
     679                                <?php if ( bp_xprofile_get_meta( $field->id, 'field', 'signup_position' ) ) : ?><?php esc_html_e( '(Sign-up)', 'buddypress' ); endif; ?>
    652680                                <?php if ( bp_get_member_types() ) : echo $field->get_member_type_label(); endif; ?>
    653681
Note: See TracChangeset for help on using the changeset viewer.