Skip to:
Content

BuddyPress.org

Changeset 11808


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.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-admin.php

    r11764 r11808  
    577577                                                                <ul>
    578578                                                                        <?php if ( bp_is_active( 'members' ) ) : ?>
    579                                                                                 <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add User Profile Fields', 'buddypress' ) . '</a>', esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-profile-setup' ), 'users.php' ) ) ) ); ?></li>
     579                                                                                <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Add User Profile Fields', 'buddypress' ) . '</a>', esc_url( add_query_arg( array( 'page' => 'bp-profile-setup' ), bp_get_admin_url( 'users.php' ) ) ) ); ?></li>
    580580                                                                        <?php endif; ?>
    581                                                                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Manage User Signups', 'buddypress' ) . '</a>', esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-signups' ), 'users.php' ) ) ) ); ?></li>
     581                                                                        <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Manage User Signups', 'buddypress' ) . '</a>', esc_url( add_query_arg( array( 'page' => 'bp-signups' ), bp_get_admin_url( 'users.php' ) ) ) ); ?></li>
    582582                                                                        <?php if ( bp_is_active( 'activity' ) ) : ?>
    583                                                                                 <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Moderate Activity Streams', 'buddypress' ) . '</a>', esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-activity' ), 'admin.php' ) ) ) ); ?></li>
     583                                                                                <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Moderate Activity Streams', 'buddypress' ) . '</a>', esc_url( add_query_arg( array( 'page' => 'bp-activity' ), bp_get_admin_url( 'admin.php' ) ) ) ); ?></li>
    584584                                                                        <?php endif; ?>
    585585                                                                        <?php if ( bp_is_active( 'groups' ) ) : ?>
    586                                                                                 <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Manage Groups', 'buddypress' ) . '</a>', esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-groups' ), 'admin.php' ) ) ) ); ?></li>
     586                                                                                <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Manage Groups', 'buddypress' ) . '</a>', esc_url( add_query_arg( array( 'page' => 'bp-groups' ), bp_get_admin_url( 'admin.php' ) ) ) ); ?></li>
    587587                                                                        <?php endif; ?>
    588                                                                         <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Repair Data', 'buddypress' ) . '</a>', esc_url( bp_get_admin_url( add_query_arg( array( 'page' => 'bp-tools' ), 'tools.php' ) ) ) ); ?>
     588                                                                        <li><?php printf( '<a href="%s" class="welcome-icon welcome-add-page">' . __( 'Repair Data', 'buddypress' ) . '</a>', esc_url( add_query_arg( array( 'page' => 'bp-tools' ), bp_get_admin_url( 'tools.php' ) ) ) ); ?>
    589589                                                                        </li>
    590590                                                                </ul>
  • 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
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-field.php

    r11700 r11808  
    11641164         */
    11651165        public function render_admin_form( $message = '' ) {
     1166
     1167                // Users Admin URL
     1168                $users_url = bp_get_admin_url( 'users.php' );
     1169
     1170                // Add New
    11661171                if ( empty( $this->id ) ) {
    11671172                        $title  = __( 'Add New Field', 'buddypress' );
    1168                         $action = "users.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field#tabs-" . $this->group_id;
    1169                         $button = __( 'Save', 'buddypress' );
     1173                        $button = __( 'Save',          'buddypress' );
     1174                        $action = add_query_arg( array(
     1175                                'page'     => 'bp-profile-setup',
     1176                                'mode'     => 'add_field',
     1177                                'group_id' => (int) $this->group_id
     1178                        ), $users_url . '#tabs-' . (int) $this->group_id );
    11701179
    11711180                        if ( !empty( $_POST['saveField'] ) ) {
     
    11801189                                }
    11811190                        }
     1191
     1192                // Edit
    11821193                } else {
    11831194                        $title  = __( 'Edit Field', 'buddypress' );
    1184                         $action = "users.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id . "#tabs-" . $this->group_id;
    1185                         $button = __( 'Update', 'buddypress' );
     1195                        $button = __( 'Update',     'buddypress' );
     1196                        $action = add_query_arg( array(
     1197                                'page'     => 'bp-profile-setup',
     1198                                'mode'     => 'edit_field',
     1199                                'group_id' => (int) $this->group_id,
     1200                                'field_id' => (int) $this->id
     1201                        ), $users_url . '#tabs-' . (int) $this->group_id );
    11861202                } ?>
    11871203
     
    12871303        private function submit_metabox( $button_text = '' ) {
    12881304
     1305                // Setup the URL for deleting
     1306                $users_url  = bp_get_admin_url( 'users.php' );
     1307                $cancel_url = add_query_arg( array(
     1308                        'page' => 'bp-profile-setup'
     1309                ), $users_url );
     1310
    12891311                /**
    12901312                 * Fires before XProfile Field submit metabox.
     
    13241346
    13251347                                                <div id="delete-action">
    1326                                                         <a href="users.php?page=bp-profile-setup" class="deletion"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a>
     1348                                                        <a href="<?php echo esc_url( $cancel_url ); ?>" class="deletion"><?php esc_html_e( 'Cancel', 'buddypress' ); ?></a>
    13271349                                                </div>
    13281350
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r11468 r11808  
    717717                global $message;
    718718
     719                // Users Admin URL
     720                $users_url = bp_get_admin_url( 'users.php' );
     721
     722                // URL to cancel to
     723                $cancel_url = add_query_arg( array(
     724                        'page' => 'bp-profile-setup'
     725                ), $users_url );
     726
    719727                // New field group.
    720728                if ( empty( $this->id ) ) {
    721729                        $title  = __( 'Add New Field Group', 'buddypress' );
    722                         $action = add_query_arg( array( 'page' => 'bp-profile-setup', 'mode' => 'add_group' ), 'users.php' );
    723                         $button = __( 'Save', 'buddypress' );
     730                        $button = __( 'Save',                'buddypress' );
     731                        $action = add_query_arg( array(
     732                                'page' => 'bp-profile-setup',
     733                                'mode' => 'add_group'
     734                        ), $users_url );
    724735
    725736                // Existing field group.
    726737                } else {
    727738                        $title  = __( 'Edit Field Group', 'buddypress' );
    728                         $action = add_query_arg( array( 'page' => 'bp-profile-setup', 'mode' => 'edit_group', 'group_id' => $this->id ), 'users.php' );
    729                         $button = __( 'Update', 'buddypress' );
     739                        $button = __( 'Update',           'buddypress' );
     740                        $action = add_query_arg( array(
     741                                'page'     => 'bp-profile-setup',
     742                                'mode'     => 'edit_group',
     743                                'group_id' => (int) $this->id
     744                        ), $users_url );
    730745                } ?>
    731746
     
    814829                                                                                        </div>
    815830                                                                                        <div id="delete-action">
    816                                                                                                 <a href="users.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
     831                                                                                                <a href="<?php echo esc_url( $cancel_url ); ?>" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    817832                                                                                        </div>
    818833                                                                                        <div class="clear"></div>
Note: See TracChangeset for help on using the changeset viewer.