Skip to:
Content

BuddyPress.org

Changeset 5699


Ignore:
Timestamp:
02/11/2012 02:14:07 AM (15 years ago)
Author:
johnjamesjacoby
Message:

Remove unneeded globals and clean up some code in XProfile component. See #3989.

Location:
trunk/bp-xprofile
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/bp-xprofile-actions.php

    r5329 r5699  
    11<?php
    2 /*******************************************************************************
    3  * Action functions are exactly the same as screen functions, however they do
    4  * not have a template screen associated with them. Usually they will send the
    5  * user back to the default screen after execution.
     2
     3/**
     4 * BuddyPress XProfile Actions
     5 *
     6 * Action functions are exactly the same as screen functions, however they do not
     7 * have a template screen associated with them. Usually they will send the user
     8 * back to the default screen after execution.
     9 *
     10 * @package BuddyPress
     11 * @subpackage XProfileActions
    612 */
    713
    … …  
    1622 *
    1723 * @package BuddyPress Xprofile
    18  * @global object $bp Global BuddyPress settings object
    1924 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user.
    2025 * @uses add_action() Runs a specific function for an action when it fires.
    … …  
    2227 */
    2328function xprofile_action_delete_avatar() {
    24         global $bp;
    2529
    2630        if ( !bp_is_user_change_avatar() || !bp_is_action_variable( 'delete-avatar', 0 ) )
  • trunk/bp-xprofile/bp-xprofile-activity.php

    r5437 r5699  
    11<?php
     2
    23/**
    34 * BuddyPress XProfile Activity & Notification Functions
    … …  
    78 *
    89 * @package BuddyPress
    9  * @subpackage XProfile
     10 * @subpackage XProfileActivity
    1011 */
    1112
    … …  
    2930 * it will show in the users activity stream (if installed)
    3031 *
    31  * @package BuddyPress XProfile
     32 * @package BuddyPress
     33 * @subpackage XProfileActivity
    3234 * @param $args Array containing all variables used after extract() call
    3335 * @global $bp The global BuddyPress settings variable created in bp_core_current_times()
    … …  
    3537 */
    3638function xprofile_record_activity( $args = '' ) {
    37         global $bp;
    3839
    3940        if ( !bp_is_active( 'activity' ) )
    4041                return false;
     42
     43        global $bp;
    4144
    4245        $defaults = array (
    … …  
    8083 */
    8184function xprofile_delete_activity( $args = '' ) {
     85
     86        if ( ! bp_is_active( 'activity' ) )
     87                return false;
     88
    8289        global $bp;
    8390
    84         if ( bp_is_active( 'activity' ) ) {
     91        extract( $args );
    8592
    86                 extract( $args );
    87 
    88                 bp_activity_delete_by_item_id( array(
    89                         'item_id'           => $item_id,
    90                         'component'         => $bp->profile->id,
    91                         'type'              => $type,
    92                         'user_id'           => $user_id,
    93                         'secondary_item_id' => $secondary_item_id
    94                 ) );
    95         }
     93        bp_activity_delete_by_item_id( array(
     94                'item_id'           => $item_id,
     95                'component'         => $bp->profile->id,
     96                'type'              => $type,
     97                'user_id'           => $user_id,
     98                'secondary_item_id' => $secondary_item_id
     99        ) );
    96100}
    97101
    … …  
    113117 */
    114118function bp_xprofile_new_avatar_activity() {
    115         global $bp;
    116119
    117120        if ( !bp_is_active( 'activity' ) )
    … …  
    130133}
    131134add_action( 'xprofile_avatar_uploaded', 'bp_xprofile_new_avatar_activity' );
     135
    132136?>
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r5598 r5699  
    11<?php
     2
     3/**
     4 * BuddyPress XProfile Admin
     5 *
     6 * @package BuddyPress
     7 * @subpackage XProfileAdmin
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    … …  
    816 *
    917 * @package BuddyPress XProfile
    10  * @global object $bp Global BuddyPress settings object
    11  * @global $wpdb WordPress DB access object.
    1218 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
    1319 * @uses bp_xprofile_install() runs the installation of DB tables for the xprofile component
    … …  
    1824 */
    1925function xprofile_add_admin_menu() {
    20         global $wpdb, $bp;
    2126
    2227        if ( !bp_current_user_can( 'bp_moderate' ) )
    … …  
    3439 */
    3540function xprofile_admin( $message = '', $type = 'error' ) {
    36         global $bp;
    3741
    3842        $type = preg_replace( '|[^a-z]|i', '', $type );
    … …  
    4044        $groups = BP_XProfile_Group::get( array(
    4145                'fetch_fields' => true
    42         ));
     46        ) );
    4347
    4448        if ( isset( $_GET['mode'] ) && isset( $_GET['group_id'] ) && 'add_field' == $_GET['mode'] )
    … …  
    6367                xprofile_admin_manage_group( $_GET['group_id'] );
    6468
    65         else {
    66 ?>
     69        else { ?>
    6770
    6871        <div class="wrap">
    … …  
    7174
    7275                <h2>
    73 
    7476                        <?php _e( 'Profile Fields', 'buddypress'); ?>
    75 
    76                         <a id="add_group" class="add-new-h2" href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a>
     77                        <a id="add_group" class="add-new-h2" href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a>
    7778                </h2>
    7879
    79                 <p><?php _e( 'Your users will distinguish themselves through their profile page. You must give them profile fields that allow them to describe themselves in a way that is relevant to the theme of your social network.', 'buddypress'); ?></p>
    80                 <p><?php echo sprintf( __( 'NOTE: Any fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p>
     80                <p><?php echo sprintf( __( 'Fields in the "%s" group will appear on the signup page.', 'buddypress' ), esc_html( stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) ) ?></p>
    8181
    8282                <form action="" id="profile-field-form" method="post">
    8383
    84                         <?php wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); ?>
    85 
    86                         <?php wp_nonce_field( 'bp_reorder_groups', '_wpnonce_reorder_groups', false );
     84                        <?php
     85                       
     86                        wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields'        );
     87                        wp_nonce_field( 'bp_reorder_groups', '_wpnonce_reorder_groups', false );
    8788
    8889                        if ( !empty( $message ) ) :
    … …  
    9394                                </div>
    9495
    95 <?php           endif; ?>
     96                        <?php endif; ?>
    9697
    9798                        <div id="tabs">
    9899                                <ul id="field-group-tabs">
    99 <?php
    100                         if ( !empty( $groups ) ) :
    101                                 foreach ( $groups as $group ) { ?>
    102 
    103                                         <li id="group_<?php echo $group->id; ?>"><a href="#tabs-<?php echo $group->id; ?>" class="ui-tab"><?php echo esc_attr( $group->name ); ?><?php if ( !$group->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress'); endif; ?></a></li>
    104 
    105 <?php                   }
    106                         endif; ?>
     100
     101                                        <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) : ?>
     102
     103                                                <li id="group_<?php echo $group->id; ?>"><a href="#tabs-<?php echo $group->id; ?>" class="ui-tab"><?php echo esc_attr( $group->name ); ?><?php if ( !$group->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress'); endif; ?></a></li>
     104
     105                                        <?php endforeach; endif; ?>
    107106
    108107                                </ul>
    109108
    110 <?php           if ( !empty( $groups ) ) :
    111                                 foreach ( $groups as $group ) { ?>
     109                                <?php if ( !empty( $groups ) ) : foreach ( $groups as $group ) : ?>
    112110
    113111                                        <noscript>
    … …  
    121119                                                                <a class="button edit" href="admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Edit Group', 'buddypress' ); ?></a>
    122120
    123 <?php                           if ( $group->can_delete ) : ?>
    124 
    125                                                                 <a class="submitdelete deletion ajax-option-delete" href="admin.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Delete Group', 'buddypress' ); ?></a>
    126 
    127 <?php                           endif; ?>
     121                                                                <?php if ( $group->can_delete ) : ?>
     122
     123                                                                        <a class="submitdelete deletion ajax-option-delete" href="admin.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=<?php echo esc_attr( $group->id ); ?>"><?php _e( 'Delete Group', 'buddypress' ); ?></a>
     124
     125                                                                <?php endif; ?>
    128126
    129127                                                        </div>
    … …  
    132130                                                <fieldset id="<?php echo $group->id; ?>" class="connectedSortable field-group">
    133131
    134 <?php                           if( $group->description ) : ?>
    135 
    136                                                         <legend><?php echo esc_attr( $group->description ) ?></legend>
    137 
    138 <?php                           endif;
    139 
    140                                         if ( !empty( $group->fields ) ) :
    141                                                 foreach ( $group->fields as $field ) {
    142 
    143                                                         // Load the field
    144                                                         $field = new BP_XProfile_Field( $field->id );
    145 
    146                                                         $class = '';
    147                                                         if ( !$field->can_delete )
    148                                                                 $class = ' core nodrag';
    149 
    150                                                         /* This function handles the WYSIWYG profile field
    151                                                          * display for the xprofile admin setup screen
    152                                                          */
    153                                                         xprofile_admin_field( $field, $group, $class );
    154 
    155                                                 } // end for
    156 
    157                                         else : // !$group->fields
    158 ?>
    159 
    160                                                         <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p>
    161 
    162 <?php
    163                                         endif; // end $group->fields
    164 ?>
     132                                                        <?php if ( $group->description ) : ?>
     133
     134                                                                <legend><?php echo esc_attr( $group->description ) ?></legend>
     135
     136                                                        <?php endif;
     137
     138                                                        if ( !empty( $group->fields ) ) :
     139                                                                foreach ( $group->fields as $field ) {
     140
     141                                                                        // Load the field
     142                                                                        $field = new BP_XProfile_Field( $field->id );
     143
     144                                                                        $class = '';
     145                                                                        if ( !$field->can_delete )
     146                                                                                $class = ' core nodrag';
     147
     148                                                                        /* This function handles the WYSIWYG profile field
     149                                                                        * display for the xprofile admin setup screen
     150                                                                        */
     151                                                                        xprofile_admin_field( $field, $group, $class );
     152
     153                                                                } // end for
     154
     155                                                        else : // !$group->fields ?>
     156
     157                                                                <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p>
     158
     159                                                        <?php endif; // end $group->fields ?>
    165160
    166161                                                </fieldset>
    167162                                        </div>
    168163
     164                                <?php endforeach; else : ?>
     165
     166                                        <div id="message" class="error"><p><?php _e( 'You have no groups.', 'buddypress' ); ?></p></div>
     167                                        <p><a href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a></p>
     168
     169                                <?php endif; ?>
     170
     171                                <div id="tabs-bottom">&nbsp;</div>
     172                        </div>
     173                </form>
     174        </div>
     175
    169176<?php
    170                                         } // End For ?>
    171 
    172                                 </div>
    173 <?php
    174                                 else :
    175 ?>
    176 
    177                                 <div id="message" class="error"><p><?php _e( 'You have no groups.', 'buddypress' ); ?></p></div>
    178                                 <p><a href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a></p>
    179 
    180 <?php
    181                                 endif;
    182 ?>
    183                                 <div id="tabs-bottom">
    184                                         &nbsp;
    185                                 </div>
    186                         </form>
    187                 </div>
    188 <?php
    189         }
    190 }
    191 
    192 /**************************************************************************
    193  xprofile_admin_manage_group()
    194 
    195  Handles the adding or editing of groups.
    196  **************************************************************************/
    197 
     177        }
     178}
     179
     180/**
     181 * Handles the adding or editing of groups.
     182 */
    198183function xprofile_admin_manage_group( $group_id = null ) {
    199184        global $message, $type;
    … …  
    230215}
    231216
    232 /**************************************************************************
    233  xprofile_admin_delete_group()
    234 
    235  Handles the deletion of profile data groups.
    236  **************************************************************************/
    237 
     217/**
     218 * Handles the deletion of profile data groups.
     219 */
    238220function xprofile_admin_delete_group( $group_id ) {
    239221        global $message, $type;
    … …  
    255237}
    256238
    257 
    258 /**************************************************************************
    259  xprofile_admin_manage_field()
    260 
    261  Handles the adding or editing of profile field data for a user.
    262  **************************************************************************/
    263 
     239/**
     240 * Handles the adding or editing of profile field data for a user.
     241 */
    264242function xprofile_admin_manage_field( $group_id, $field_id = null ) {
    265243        global $bp, $wpdb, $message, $groups;
    266244
    267         $field = new BP_XProfile_Field( $field_id );
     245        $field           = new BP_XProfile_Field( $field_id );
    268246        $field->group_id = $group_id;
    269247
    … …  
    329307        // @todo trust this param
    330308        $field_type  = ( 'field' == $field_type ) ? __( 'field', 'buddypress' ) : __( 'option', 'buddypress' );
    331 
    332         $field = new BP_XProfile_Field( $field_id );
     309        $field       = new BP_XProfile_Field( $field_id );
    333310
    334311        if ( !$field->delete( (bool) $delete_data ) ) {
    … …  
    346323}
    347324
    348 /**************************************************************************
    349  xprofile_ajax_reorder_fields()
    350 
    351  Handles the ajax reordering of fields within a group
    352 **************************************************************************/
     325/**
     326 * Handles the ajax reordering of fields within a group
     327 */
    353328function xprofile_ajax_reorder_fields() {
    354         global $bp;
    355329
    356330        // Check the nonce
    … …  
    361335
    362336        parse_str( $_POST['field_order'], $order );
     337
    363338        $field_group_id = $_POST['field_group_id'];
    364339
    365         foreach ( (array) $order['field'] as $position => $field_id )
     340        foreach ( (array) $order['field'] as $position => $field_id ) {
    366341                xprofile_update_field_position( (int) $field_id, (int) $position, (int) $field_group_id );
    367 
     342        }
    368343}
    369344add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' );
    370345
    371 /**************************************************************************
    372  xprofile_ajax_reorder_field_groups()
    373 
    374  Handles the reordering of field groups
    375 **************************************************************************/
     346/**
     347 * Handles the reordering of field groups
     348 */
    376349function xprofile_ajax_reorder_field_groups() {
    377         global $bp;
    378350
    379351        // Check the nonce
    … …  
    385357        parse_str( $_POST['group_order'], $order );
    386358
    387         foreach ( (array) $order['group'] as $position => $field_group_id )
     359        foreach ( (array) $order['group'] as $position => $field_group_id ) {
    388360                xprofile_update_field_group_position( (int) $field_group_id, (int) $position );
    389 
     361        }
    390362}
    391363add_action( 'wp_ajax_xprofile_reorder_groups', 'xprofile_ajax_reorder_field_groups' );
    392364
    393 /**************************************************************************
    394  xprofile_admin_field()
    395 
    396  Handles the WYSIWYG display of each profile field on the edit screen
    397 **************************************************************************/
    398 function xprofile_admin_field( $admin_field, $admin_group, $class='' ) {
     365/**
     366 * Handles the WYSIWYG display of each profile field on the edit screen
     367 */
     368function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) {
    399369        global $field;
    400370
    401371        $field = $admin_field; ?>
    402                                                 <fieldset id="field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( $class ) echo ' ' . $class; ?>">
    403                                                         <legend><span><?php bp_the_profile_field_name(); ?> <?php if( !$field->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress' ); endif; ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(Required)', 'buddypress' ) ?><?php endif; ?></span></legend>
    404                                                         <div class="field-wrapper">
     372
     373        <fieldset id="field_<?php echo esc_attr( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( !empty( $class ) ) echo ' ' . $class; ?>">
     374                <legend><span><?php bp_the_profile_field_name(); ?> <?php if( !$field->can_delete ) : ?> <?php _e( '(Primary)', 'buddypress' ); endif; ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(Required)', 'buddypress' ) ?><?php endif; ?></span></legend>
     375                <div class="field-wrapper">
     376
     377                        <?php switch ( $field->type ) : case 'textbox' : ?>
     378
     379                                <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="" />
     380
     381                        <?php break; case 'textarea' : ?>
     382
     383                                <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"></textarea>
     384
     385                        <?php break; case 'selectbox' : ?>
     386
     387                                <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>">
     388
     389                                        <?php bp_the_profile_field_options() ?>
     390
     391                                </select>
     392
     393                        <?php break; case 'multiselectbox' : ?>
     394
     395                                <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" multiple="multiple">
     396
     397                                        <?php bp_the_profile_field_options() ?>
     398
     399                                </select>
     400
     401                        <?php break; case 'radio' : ?>
     402
     403                                <?php bp_the_profile_field_options() ?>
     404
     405                                <?php if ( !bp_get_the_profile_field_is_required() ) : ?>
     406
     407                                        <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a>
     408
     409                                <?php endif; ?>
     410
     411                        <?php break; case 'checkbox' : ?>
     412
     413                                <?php bp_the_profile_field_options(); ?>
     414
     415                        <?php break; case 'datebox' : ?>
     416
     417                                <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day">
     418
     419                                        <?php bp_the_profile_field_options( 'type=day' ); ?>
     420
     421                                </select>
     422
     423                                <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month">
     424
     425                                        <?php bp_the_profile_field_options( 'type=month' ); ?>
     426
     427                                </select>
     428
     429                                <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year">
     430
     431                                        <?php bp_the_profile_field_options( 'type=year' ); ?>
     432
     433                                </select>
     434
     435                        <?php break; default : ?>
     436
     437                        <?php do_action( 'xprofile_admin_field', $field, 1 ); ?>
     438
     439                        <?php endswitch; ?>
     440
     441                        <?php if ( $field->description ) : ?>
     442
     443                                <p class="description"><?php echo esc_attr( $field->description ); ?></p>
     444
     445                        <?php endif; ?>
     446
     447                        <div class="actions">
     448                                <a class="button edit" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo esc_attr( $admin_group->id ); ?>&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a>
     449
     450                                <?php if ( $field->can_delete ) : ?>
     451
     452                                        <a class="submit-delete deletion" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a>
     453
     454                                <?php endif; ?>
     455                        </div>
     456                </div>
     457        </fieldset>
    405458
    406459<?php
    407         switch ( $field->type ) {
    408                 case 'textbox' : ?>
    409 
    410                                                                 <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="" />
    411 
    412 <?php           break; case 'textarea' : ?>
    413 
    414                                                                 <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"></textarea>
    415 
    416 <?php           break; case 'selectbox' : ?>
    417 
    418                                                                 <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>">
    419                                                                         <?php bp_the_profile_field_options() ?>
    420 
    421                                                                 </select>
    422 
    423 <?php           break; case 'multiselectbox' : ?>
    424 
    425                                                                 <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" multiple="multiple">
    426                                                                         <?php bp_the_profile_field_options() ?>
    427 
    428                                                                 </select>
    429 
    430 <?php           break; case 'radio' : ?>
    431 
    432                                                                 <?php bp_the_profile_field_options() ?>
    433 
    434 <?php                   if ( !bp_get_the_profile_field_is_required() ) : ?>
    435 
    436                                                                 <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a>
    437 
    438 <?php                   endif; ?>
    439 
    440 <?php           break; case 'checkbox' : ?>
    441 
    442 <?php bp_the_profile_field_options(); ?>
    443 
    444 <?php           break; case 'datebox' : ?>
    445 
    446                                                                 <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day">
    447                                                                         <?php bp_the_profile_field_options( 'type=day' ); ?>
    448 
    449                                                                 </select>
    450 
    451                                                                 <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month">
    452                                                                         <?php bp_the_profile_field_options( 'type=month' ); ?>
    453 
    454                                                                 </select>
    455 
    456                                                                 <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year">
    457                                                                         <?php bp_the_profile_field_options( 'type=year' ); ?>
    458 
    459                                                                 </select>
    460 
    461 <?php           break; default : ?>
    462 
    463 <?php   do_action( 'xprofile_admin_field', $field, 1 ); ?>
    464 
    465 <?php } ?>
    466 
    467 <?php if ( $field->description ) : ?>
    468 
    469                                                                 <p class="description"><?php echo esc_attr( $field->description ); ?></p>
    470 
    471 <?php endif; ?>
    472 
    473                                                                 <div class="actions">
    474                                                                         <a class="button edit" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo esc_attr( $admin_group->id ); ?>&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a>
    475 
    476                                                                         <?php if ( $field->can_delete ) : ?>
    477 
    478                                                                                 <a class="submit-delete deletion" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo esc_attr( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a>
    479 
    480                                                                         <?php endif; ?>
    481                                                                 </div>
    482                                                         </div>
    483                                                 </fieldset>
    484 <?php
    485 }
     460}
     461
     462?>
  • trunk/bp-xprofile/bp-xprofile-buddybar.php

    r4827 r5699  
    11<?php
     2
    23// Exit if accessed directly
    34if ( !defined( 'ABSPATH' ) ) exit;
     5
    46?>
  • trunk/bp-xprofile/bp-xprofile-cache.php

    r5302 r5699  
    11<?php
    2 /********************************************************************************
    3  * Caching
     2
     3/**
     4 * BuddyPress XProfile Template Tags
    45 *
    56 * Caching functions handle the clearing of cached objects and pages on specific
    67 * actions throughout BuddyPress.
     8 *
     9 * @package BuddyPress
     10 * @subpackage XProfileTemplate
    711 */
    812
    … …  
    1115
    1216function xprofile_clear_profile_groups_object_cache( $group_obj ) {
    13         wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' );
    14         wp_cache_delete( 'xprofile_group_' . $group_obj->id );
     17        wp_cache_delete( 'xprofile_groups_inc_empty',        'bp' );
     18        wp_cache_delete( 'xprofile_group_' . $group_obj->id, 'bp' );
    1519}
    1620
    1721function xprofile_clear_profile_data_object_cache( $group_id ) {
    18         global $bp;
    1922        wp_cache_delete( 'bp_user_fullname_' . bp_loggedin_user_id(), 'bp' );
    2023}
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r5697 r5699  
    11<?php
     2
     3/**
     4 * BuddyPress XProfile Classes
     5 *
     6 * @package BuddyPress
     7 * @subpackage XProfileClasses
     8 */
     9
    210// Exit if accessed directly
    311if ( !defined( 'ABSPATH' ) ) exit;
    … …  
    1119        var $fields;
    1220
    13         function bp_xprofile_group( $id = null ) {
    14                 $this->__construct( $id );
    15         }
    16 
    1721        function __construct( $id = null ) {
    18                 global $bp, $wpdb;
    19 
    20                 if ( $id )
     22                if ( !empty( $id ) )
    2123                        $this->populate( $id );
    22 
    2324        }
    2425
    … …  
    4647                do_action_ref_array( 'xprofile_group_before_save', array( $this ) );
    4748
    48                 if ( $this->id )
     49                if ( !empty( $this->id ) )
    4950                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id );
    5051                else
    … …  
    5657                do_action_ref_array( 'xprofile_group_after_save', array( $this ) );
    5758
    58                 if ( $this->id )
     59                if ( !empty( $this->id ) )
    5960                        return $this->id;
    6061                else
    … …  
    6566                global $wpdb, $bp;
    6667
    67                 if ( !$this->can_delete )
    68                         return false;
    69 
    70                 /* Delete field group */
     68                if ( empty( $this->can_delete ) )
     69                        return false;
     70
     71                // Delete field group
    7172                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ) ) ) {
    7273                        return false;
    7374                } else {
    74                         /* Remove the group's fields. */
     75
     76                        // Remove the group's fields.
    7577                        if ( BP_XProfile_Field::delete_for_group( $this->id ) ) {
    76                                 /* Remove profile data for the groups fields */
     78
     79                                // Remove profile data for the groups fields
    7780                                for ( $i = 0, $count = count( $this->fields ); $i < $count; ++$i ) {
    7881                                        BP_XProfile_ProfileData::delete_for_field( $this->fields[$i]->id );
    … …  
    8487        }
    8588
    86         /** Static Functions **/
     89        /** Static Methods ********************************************************/
    8790
    8891        /**
    … …  
    126129                $where_sql = '';
    127130
    128                 if ( $profile_group_id )
     131                if ( !empty( $profile_group_id ) )
    129132                        $where_sql = $wpdb->prepare( 'WHERE g.id = %d', $profile_group_id );
    130133                elseif ( $exclude_groups )
    131134                        $where_sql = $wpdb->prepare( "WHERE g.id NOT IN ({$exclude_groups})");
    132135
    133                 if ( $hide_empty_groups )
     136                if ( !empty( $hide_empty_groups ) )
    134137                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g INNER JOIN {$bp->profile->table_name_fields} f ON g.id = f.group_id {$where_sql} ORDER BY g.group_order ASC" ) );
    135138                else
    136139                        $groups = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT g.* FROM {$bp->profile->table_name_groups} g {$where_sql} ORDER BY g.group_order ASC" ) );
    137140
    138                 if ( !$fetch_fields )
     141                if ( empty( $fetch_fields ) )
    139142                        return $groups;
    140143
    … …  
    151154
    152155                $exclude_fields_sql = '';
    153                 if ( $exclude_fields )
     156                if ( !empty( $exclude_fields ) )
    154157                        $exclude_fields_sql = $wpdb->prepare( "AND id NOT IN ({$exclude_fields})" );
    155158
    … …  
    160163                        return $groups;
    161164
    162                 if ( $fetch_field_data ) {
     165                if ( !empty( $fetch_field_data ) ) {
     166
    163167                        // Fetch the field data for the user.
    164                         foreach( (array)$fields as $field )
     168                        foreach( (array) $fields as $field ) {
    165169                                $field_ids[] = $field->id;
     170                        }
    166171
    167172                        $field_ids_sql = implode( ',', (array) $field_ids );
    … …  
    171176
    172177                        // Remove data-less fields, if necessary
    173                         if ( $hide_empty_fields ) {
     178                        if ( !empty( $hide_empty_fields ) ) {
    174179
    175180                                // Loop through the results and find the fields that have data.
    176181                                foreach( (array)$field_data as $data ) {
     182
    177183                                        // Empty fields may contain a serialized empty array
    178184                                        $maybe_value = maybe_unserialize( $data->value );
    … …  
    220226
    221227                        foreach( (array) $fields as $field ) {
    222                                 if ( $group->id == $field->group_id )
     228                                if ( $group->id == $field->group_id ) {
    223229                                        $groups[$index]->fields[] = $field;
     230                                }
    224231                        }
    225232
    … …  
    265272                global $message;
    266273
    267                 if ( !$this->id ) {
     274                if ( empty( $this->id ) ) {
    268275                        $title  = __( 'Add New Field Group', 'buddypress' );
    269276                        $action = "admin.php?page=bp-profile-setup&amp;mode=add_group";
    … …  
    273280                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;
    274281                        $button = __( 'Save Changes', 'buddypress' );
    275                 }
    276 ?>
     282                } ?>
     283
    277284                <div class="wrap">
    278285
    … …  
    282289                        <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
    283290
    284 <?php if ( $message != '' ) :
    285                 $type = ( 'error' == $type ) ? 'error' : 'updated'; ?>
     291                        <?php if ( !empty( $message ) ) :
     292                                        $type = ( 'error' == $type ) ? 'error' : 'updated'; ?>
     293
    286294                                <div id="message" class="<?php echo $type; ?> fade">
    287295                                        <p><?php echo $message; ?></p>
    288296                                </div>
    289 <?php endif; ?>
     297
     298                        <?php endif; ?>
     299
    290300                        <div id="poststuff">
    291301                                <form action="<?php echo esc_attr( $action ); ?>" method="post">
    … …  
    297307                                        </div>
    298308
    299 <?php if ( '0' != $this->can_delete ) : ?>
    300                                         <div id="titlediv">
    301                                                 <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3>
    302                                                 <div id="titlewrap">
    303                                                         <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     309                                        <?php if ( '0' != $this->can_delete ) : ?>
     310
     311                                                <div id="titlediv">
     312                                                        <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3>
     313                                                        <div id="titlewrap">
     314                                                                <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     315                                                        </div>
    304316                                                </div>
    305                                         </div>
    306 <?php endif; ?>
     317
     318                                        <?php endif; ?>
    307319
    308320                                        <p class="submit">
    … …  
    314326                        </div>
    315327                </div>
     328
    316329<?php
    317330        }
    318331}
    319 
    320332
    321333class BP_XProfile_Field {
    … …  
    337349        var $message_type = 'err';
    338350
    339         function bp_xprofile_field( $id = null, $user_id = null, $get_data = true ) {
    340                 $this->__construct( $id, $user_id, $get_data );
    341         }
    342 
    343351        function __construct( $id = null, $user_id = null, $get_data = true ) {
    344                 if ( $id )
     352                if ( !empty( $id ) )
    345353                        $this->populate( $id, $user_id, $get_data );
    346354        }
    … …  
    349357                global $wpdb, $userdata, $bp;
    350358
     359                // @todo Why are we nooping the user_id ?
    351360                $user_id = 0;
    352361                if ( is_null( $user_id ) )
    … …  
    369378                        $this->is_default_option = $field->is_default_option;
    370379
    371                         if ( $get_data && $user_id )
    372                                 $this->data            = $this->get_field_data( $user_id );
     380                        if ( $get_data && $user_id ) {
     381                                $this->data          = $this->get_field_data( $user_id );
     382                        }
    373383                }
    374384        }
    … …  
    380390                // Prevent deletion by url when can_delete is false.
    381391                // Prevent deletion of option 1 since this invalidates fields with options.
    382                 if ( !$this->id || !$this->can_delete || ( $this->parent_id && $this->option_order == 1 ) )
     392                if ( empty( $this->id ) || empty( $this->can_delete ) || ( $this->parent_id && $this->option_order == 1 ) )
    383393                        return false;
    384394
    … …  
    396406                global $wpdb, $bp;
    397407
    398                 $error = false;
    399 
    400408                $this->group_id    = apply_filters( 'xprofile_field_group_id_before_save',    $this->group_id,    $this->id );
    401409                $this->parent_id   = apply_filters( 'xprofile_field_parent_id_before_save',   $this->parent_id,   $this->id );
    402                 $this->type        = apply_filters( 'xprofile_field_type_before_save',        $this->type,        $this->id );
    403                 $this->name        = apply_filters( 'xprofile_field_name_before_save',        $this->name,        $this->id );
     410                $this->type            = apply_filters( 'xprofile_field_type_before_save',        $this->type,        $this->id );
     411                $this->name            = apply_filters( 'xprofile_field_name_before_save',        $this->name,        $this->id );
    404412                $this->description = apply_filters( 'xprofile_field_description_before_save', $this->description, $this->id );
    405413                $this->is_required = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id );
    … …  
    409417                do_action_ref_array( 'xprofile_field_before_save', array( $this ) );
    410418
    411                 if ( $this->id != null )
     419                if ( $this->id != null ) {
    412420                        $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d, parent_id = 0, type = %s, name = %s, description = %s, is_required = %d, order_by = %s, field_order = %d WHERE id = %d", $this->group_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order, $this->id );
    413                 else
     421                } else {
    414422                        $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, order_by, field_order ) VALUES (%d, %d, %s, %s, %s, %d, %s, %d )", $this->group_id, $this->parent_id, $this->type, $this->name, $this->description, $this->is_required, $this->order_by, $this->field_order );
    415 
    416                 /*
     423                }
     424
     425                /**
    417426                 * Check for null so field options can be changed without changing any other part of the field.
    418427                 * The described situation will return 0 here.
    419428                 */
    420429                if ( $wpdb->query( $sql ) !== null ) {
    421                         if ( $this->id )
     430
     431                        if ( !empty( $this->id ) ) {
    422432                                $field_id = $this->id;
    423                         else
     433                        } else {
    424434                                $field_id = $wpdb->insert_id;
    425 
    426                         /* Only do this if we are editing an existing field */
     435                        }
     436
     437                        // Only do this if we are editing an existing field
    427438                        if ( $this->id != null ) {
    428                                 /*
     439
     440                                /**
    429441                                 * Remove any radio or dropdown options for this
    430442                                 * field. They will be re-added if needed.
    … …  
    435447                        }
    436448
    437                         /*
     449                        /**
    438450                         * Check to see if this is a field with child options.
    439451                         * We need to add the options to the db, if it is.
    440452                         */
    441453                        if ( 'radio' == $this->type || 'selectbox' == $this->type || 'checkbox' == $this->type || 'multiselectbox' == $this->type ) {
    442                                 if ( $this->id )
     454
     455                                if ( !empty( $this->id ) ) {
    443456                                        $parent_id = $this->id;
    444                                 else
     457                                } else {
    445458                                        $parent_id = $wpdb->insert_id;
     459                                }
    446460
    447461                                if ( 'radio' == $this->type ) {
    … …  
    452466                                        $defaults       = apply_filters( 'xprofile_field_default_before_save', $post_default, 'radio' );
    453467
    454                                 } else if ( 'selectbox' == $this->type ) {
     468                                } elseif ( 'selectbox' == $this->type ) {
    455469                                        $post_option  = !empty( $_POST['selectbox_option']           ) ? $_POST['selectbox_option']           : '';
    456470                                        $post_default = !empty( $_POST['isDefault_selectbox_option'] ) ? $_POST['isDefault_selectbox_option'] : '';
    … …  
    459473                                        $defaults       = apply_filters( 'xprofile_field_default_before_save', $post_default, 'selectbox' );
    460474
    461                                 } else if ( 'multiselectbox' == $this->type ) {
     475                                } elseif ( 'multiselectbox' == $this->type ) {
    462476                                        $post_option  = !empty( $_POST['multiselectbox_option']           ) ? $_POST['multiselectbox_option']           : '';
    463477                                        $post_default = !empty( $_POST['isDefault_multiselectbox_option'] ) ? $_POST['isDefault_multiselectbox_option'] : '';
    … …  
    466480                                        $defaults       = apply_filters( 'xprofile_field_default_before_save', $post_default, 'multiselectbox' );
    467481
    468                                 } else if ( 'checkbox' == $this->type ) {
     482                                } elseif ( 'checkbox' == $this->type ) {
    469483                                        $post_option  = !empty( $_POST['checkbox_option']           ) ? $_POST['checkbox_option']           : '';
    470484                                        $post_default = !empty( $_POST['isDefault_checkbox_option'] ) ? $_POST['isDefault_checkbox_option'] : '';
    … …  
    475489
    476490                                $counter = 1;
    477                                 if ( $options ) {
     491                                if ( !empty( $options ) ) {
    478492                                        foreach ( (array)$options as $option_key => $option_value ) {
    479493                                                $is_default = 0;
    … …  
    488502
    489503                                                if ( '' != $option_value ) {
    490                                                         if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) )
     504                                                        if ( !$wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_fields} (group_id, parent_id, type, name, description, is_required, option_order, is_default_option) VALUES (%d, %d, 'option', %s, '', 0, %d, %d)", $this->group_id, $parent_id, $option_value, $counter, $is_default ) ) ) {
    491505                                                                return false;
     506                                                        }
    492507                                                }
    493508
    … …  
    513528
    514529                // This is done here so we don't have problems with sql injection
    515                 if ( 'asc' == $this->order_by && !$for_editing )
     530                if ( 'asc' == $this->order_by && empty( $for_editing ) ) {
    516531                        $sort_sql = 'ORDER BY name ASC';
    517                 else if ( 'desc' == $this->order_by && !$for_editing )
     532                } elseif ( 'desc' == $this->order_by && empty( $for_editing ) ) {
    518533                        $sort_sql = 'ORDER BY name DESC';
    519                 else
     534                } else {
    520535                        $sort_sql = 'ORDER BY option_order ASC';
     536                }
    521537
    522538                // This eliminates a problem with getting all fields when there is no id for the object
    523                 if ( !$this->id )
     539                if ( empty( $this->id ) ) {
    524540                        $parent_id = -1;
    525                 else
     541                } else {
    526542                        $parent_id = $this->id;
     543                }
    527544
    528545                $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d $sort_sql", $parent_id, $this->group_id );
    … …  
    547564                global $wpdb, $bp;
    548565
    549                 if ( $field_id ) {
     566                if ( !empty( $field_id ) ) {
    550567                        $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id );
    551568
    552                         if ( !$field_type = $wpdb->get_var( $sql ) )
     569                        if ( !$field_type = $wpdb->get_var( $sql ) ) {
    553570                                return false;
     571                        }
    554572
    555573                        return $field_type;
    … …  
    562580                global $wpdb, $bp;
    563581
    564                 if ( $group_id ) {
     582                if ( !empty( $group_id ) ) {
    565583                        $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id );
    566584
    567                         if ( $wpdb->get_var( $sql ) === false )
     585                        if ( $wpdb->get_var( $sql ) === false ) {
    568586                                return false;
     587                        }
    569588
    570589                        return true;
    … …  
    589608                        return false;
    590609
    591                 /* Update $field_id with new $position and $field_group_id */
     610                // Update $field_id with new $position and $field_group_id
    592611                if ( $parent = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d, group_id = %d WHERE id = %d", $position, $field_group_id, $field_id ) ) ) {;
    593                         /* Update any children of this $field_id */
     612
     613                        // Update any children of this $field_id
    594614                        $children = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET group_id = %d WHERE parent_id = %d", $field_group_id, $field_id ) );
    595615
    … …  
    608628                $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' );
    609629
    610                 foreach ($input_types as $type) {
     630                foreach ( $input_types as $type ) {
    611631                        $default_name = '';
    612632
    613                         if ( 'multiselectbox' == $type || 'checkbox' == $type )
     633                        if ( ( 'multiselectbox' == $type ) || ( 'checkbox' == $type ) ) {
    614634                                $default_input = 'checkbox';
    615                         else
     635                        } else {
    616636                                $default_input = 'radio';
    617 ?>
    618                         <div id="<?php echo $type; ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;">
     637                        }
     638
     639                        if ( $this->type != $type ) {
     640                                $class = 'display: none;';
     641                        }
     642
     643                        ?>
     644
     645                        <div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;">
    619646                                <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4>
    620647                                <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label>
    … …  
    624651                                                <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option>
    625652                                        </select>
    626 <?php
    627                                 if ( !$options = $this->get_children( true ) ) {
     653
     654                                <?php if ( !$options = $this->get_children( true ) ) {
     655
    628656                                        $i = 1;
    629657                                        while ( isset( $_POST[$type . '_option'][$i] ) ) {
    630658                                                (array) $options[] = (object) array(
    631                                                         'id' => -1,
    632                                                         'name' => $_POST[$type . '_option'][$i],
    633                                                         'is_default_option' => ( 'multiselectbox' != $type &&
    634                                                                 'checkbox' != $type &&
    635                                                                 $_POST["isDefault_{$type}_option"] == $i ) ?
    636                                                                         1 :
    637                                                                         $_POST["isDefault_{$type}_option"][$i]
     659                                                        'id'                => -1,
     660                                                        'name'              => $_POST[$type . '_option'][$i],
     661                                                        'is_default_option' => ( ( 'multiselectbox' != $type ) && ( 'checkbox' != $type ) && ( $_POST["isDefault_{$type}_option"] == $i ) ) ? 1 : $_POST["isDefault_{$type}_option"][$i]
    638662                                                );
    639663
    … …  
    647671
    648672                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
    649                                                         $default_name = '[' . $j . ']';
    650 ?>
    651                                                 <p><?php _e('Option', 'buddypress'); ?> <?php echo $j; ?>:
     673                                                        $default_name = '[' . $j . ']'; ?>
     674
     675                                                <p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>:
    652676                                                   <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" />
    653677                                                   <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?>
    654 <?php
    655                                         if ( $j != 1 && $options[$i]->id != -1 ) : ?>
    656                                                         <a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a>
    657 <?php                           endif; ?>
     678
     679                                                        <?php if ( $j != 1 && $options[$i]->id != -1 ) : ?>
     680
     681                                                                <a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a>
     682
     683                                                        <?php endif; ?>
     684
    658685                                                </p>
    659 <?php                           } /* end for */ ?>
     686
     687                                        <?php } /* end for */ ?>
    660688
    661689                                        <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="<?php echo $j + 1; ?>" />
    662 <?php
    663                                 } else {
     690
     691                                <?php } else {
     692
    664693                                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    665                                                 $default_name = '[1]';
    666 ?>
     694                                                $default_name = '[1]'; ?>
    667695
    668696                                        <p><?php _e( 'Option', 'buddypress' ); ?> 1: <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" />
    … …  
    670698                                        <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" />
    671699
    672 <?php                   } /* end if */ ?>
     700                                <?php } /* end if */ ?>
    673701
    674702                                <div id="<?php echo $type; ?>_more"></div>
    … …  
    680708
    681709        function render_admin_form( $message = '' ) {
    682                 if ( !$this->id ) {
     710                if ( empty( $this->id ) ) {
    683711                        $title                          = __( 'Add Field', 'buddypress' );
    684712                        $action                         = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field#tabs-" . $this->group_id;
    685713
    686714                        if ( !empty( $_POST['saveField'] ) ) {
    687                                 $this->name             = $_POST['title'];
    688                                 $this->description      = $_POST['description'];
    689                                 $this->is_required      = $_POST['required'];
    690                                 $this->type             = $_POST['fieldtype'];
    691                                 $this->order_by         = $_POST["sort_order_{$this->type}"];
    692                                 $this->field_order      = $_POST['field_order'];
    693                         }
    694                 } else {
    695                         $title                          = __( 'Edit Field', 'buddypress' );
    696                         $action                         = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id . "#tabs-" . $this->group_id;
    697                 }
    698 ?>
    699         <div class="wrap">
    700                 <div id="icon-users" class="icon32"><br /></div>
    701                 <h2><?php echo $title; ?></h2>
    702                 <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
    703 
    704 <?php
    705                 if ( $message != '' ) {
    706 ?>
    707                         <div id="message" class="error fade">
    708                                 <p><?php echo $message; ?></p>
    709                         </div>
    710 <?php   } ?>
    711 
    712                 <form action="<?php echo $action; ?>" method="post">
    713                         <div id="poststuff">
    714                                 <div id="titlediv">
    715                                         <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3>
    716                                         <div id="titlewrap">
    717                                                 <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" />
     715                                $this->name        = $_POST['title'];
     716                                $this->description = $_POST['description'];
     717                                $this->is_required = $_POST['required'];
     718                                $this->type        = $_POST['fieldtype'];
     719                                $this->order_by    = $_POST["sort_order_{$this->type}"];
     720                                $this->field_order = $_POST['field_order'];
     721                        }
     722                } else {
     723                        $title  = __( 'Edit Field', 'buddypress' );
     724                        $action = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id . "#tabs-" . $this->group_id;
     725                } ?>
     726
     727                <div class="wrap">
     728                        <div id="icon-users" class="icon32"><br /></div>
     729                        <h2><?php echo $title; ?></h2>
     730                        <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
     731
     732                        <?php if ( !empty( $message ) ) : ?>
     733
     734                                <div id="message" class="error fade">
     735                                        <p><?php echo $message; ?></p>
     736                                </div>
     737
     738                        <?php endif; ?>
     739
     740                        <form action="<?php echo $action; ?>" method="post">
     741                                <div id="poststuff">
     742                                        <div id="titlediv">
     743                                                <h3><label for="title"><?php _e( 'Field Title', 'buddypress' ); ?> *</label></h3>
     744                                                <div id="titlewrap">
     745                                                        <input type="text" name="title" id="title" value="<?php echo esc_attr( $this->name ); ?>" style="width:50%" />
     746                                                </div>
    718747                                        </div>
     748
     749                                        <div id="titlediv">
     750                                                <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3>
     751                                                <div id="titlewrap">
     752                                                        <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     753                                                </div>
     754                                        </div>
     755
     756                                        <?php if ( '0' != $this->can_delete ) { ?>
     757
     758                                                <div id="titlediv">
     759                                                        <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3>
     760                                                        <select name="required" id="required" style="width: 30%">
     761                                                                <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option>
     762                                                                <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option>
     763                                                        </select>
     764                                                </div>
     765
     766                                                <div id="titlediv">
     767                                                        <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3>
     768                                                        <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%">
     769                                                                <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option>
     770                                                                <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option>
     771                                                                <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option>
     772                                                                <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option>
     773                                                                <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option>
     774                                                                <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option>
     775                                                                <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option>
     776                                                        </select>
     777                                                </div>
     778
     779                                                <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?>
     780
     781                                                <?php $this->render_admin_form_children(); ?>
     782
     783                                        <?php } else { ?>
     784
     785                                                <input type="hidden" name="required" id="required" value="1" />
     786                                                <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" />
     787
     788                                        <?php } ?>
     789
     790                                        <p class="submit">
     791                                                <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" />
     792                                                <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" />
     793                                                <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
     794                                        </p>
     795
    719796                                </div>
    720797
    721                                 <div id="titlediv">
    722                                         <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3>
    723                                         <div id="titlewrap">
    724                                                 <textarea name="description" id="description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
    725                                         </div>
    726                                 </div>
    727 
    728 <?php
    729                 if ( '0' != $this->can_delete ) {
    730 ?>
    731                                 <div id="titlediv">
    732                                         <h3><label for="required"><?php _e( "Is This Field Required?", 'buddypress' ); ?> *</label></h3>
    733                                         <select name="required" id="required" style="width: 30%">
    734                                                 <option value="0"<?php if ( $this->is_required == '0' ) { ?> selected="selected"<?php } ?>><?php _e( 'Not Required', 'buddypress' ); ?></option>
    735                                                 <option value="1"<?php if ( $this->is_required == '1' ) { ?> selected="selected"<?php } ?>><?php _e( 'Required', 'buddypress' ); ?></option>
    736                                         </select>
    737                                 </div>
    738 
    739                                 <div id="titlediv">
    740                                         <h3><label for="fieldtype"><?php _e("Field Type", 'buddypress'); ?> *</label></h3>
    741                                         <select name="fieldtype" id="fieldtype" onchange="show_options(this.value)" style="width: 30%">
    742                                                 <option value="textbox"<?php if ( $this->type == 'textbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Text Box', 'buddypress' ); ?></option>
    743                                                 <option value="textarea"<?php if ( $this->type == 'textarea' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi-line Text Box', 'buddypress' ); ?></option>
    744                                                 <option value="datebox"<?php if ( $this->type == 'datebox' ) {?> selected="selected"<?php } ?>><?php _e( 'Date Selector', 'buddypress' ); ?></option>
    745                                                 <option value="radio"<?php if ( $this->type == 'radio' ) {?> selected="selected"<?php } ?>><?php _e( 'Radio Buttons', 'buddypress' ); ?></option>
    746                                                 <option value="selectbox"<?php if ( $this->type == 'selectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Drop Down Select Box', 'buddypress' ); ?></option>
    747                                                 <option value="multiselectbox"<?php if ( $this->type == 'multiselectbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Multi Select Box', 'buddypress' ); ?></option>
    748                                                 <option value="checkbox"<?php if ( $this->type == 'checkbox' ) {?> selected="selected"<?php } ?>><?php _e( 'Checkboxes', 'buddypress' ); ?></option>
    749                                         </select>
    750                                 </div>
    751 
    752                                 <?php do_action_ref_array( 'xprofile_field_additional_options', array( $this ) ); ?>
    753 
    754                                 <?php $this->render_admin_form_children(); ?>
    755 <?php   } else { ?>
    756                                 <input type="hidden" name="required" id="required" value="1" />
    757                                 <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" />
    758 <?php   } ?>
    759                                 <p class="submit">
    760                                         <input type="hidden" name="field_order" id="field_order" value="<?php echo esc_attr( $this->field_order ); ?>" />
    761                                         <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" />
    762                                         <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    763                                 </p>
    764 
    765                         </div>
    766 
    767                         <?php wp_nonce_field( 'xprofile_delete_option' ); ?>
    768 
    769                 </form>
    770         </div>
     798                                <?php wp_nonce_field( 'xprofile_delete_option' ); ?>
     799
     800                        </form>
     801                </div>
    771802
    772803<?php
    … …  
    776807                global $message;
    777808
    778                 /* Validate Form */
     809                // Validate Form
    779810                if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) {
    780811                        $message = __( 'Please make sure you fill out all required fields.', 'buddypress' );
    … …  
    806837        var $last_updated;
    807838
    808         function bp_xprofile_profiledata( $field_id = null, $user_id = null ) {
    809                 $this->__construct( $field_id, $user_id );
    810         }
    811 
    812839        function __construct( $field_id = null, $user_id = null ) {
    813                 if ( $field_id )
     840                if ( !empty( $field_id ) )
    814841                        $this->populate( $field_id, $user_id );
    815842        }
    … …  
    923950                $profile_data = array();
    924951
    925                 if ( $results ) {
     952                if ( !empty( $results ) ) {
    926953                        $profile_data['user_login']             = $results[0]->user_login;
    927954                        $profile_data['user_nicename']  = $results[0]->user_nicename;
    … …  
    945972                global $wpdb, $bp;
    946973
    947                 if ( !$user_ids )
     974                if ( empty( $user_ids ) )
    948975                        $user_ids = bp_displayed_user_id();
    949976
    … …  
    961988                global $bp, $wpdb;
    962989
    963                 if ( !$fields )
    964                         return false;
    965 
    966                 if ( !$user_id )
     990                if ( empty( $fields ) )
     991                        return false;
     992
     993                if ( empty( $user_id ) )
    967994                        $user_id = bp_displayed_user_id();
    968995
    … …  
    10061033
    10071034        function delete_for_field( $field_id ) {
    1008                 global $wpdb, $userdata, $bp;
     1035                global $wpdb, $bp;
    10091036
    10101037                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) )
    … …  
    10311058                global $wpdb, $bp;
    10321059
    1033                 if ( $exclude_fullname )
     1060                if ( !empty( $exclude_fullname ) )
    10341061                        $exclude_sql = $wpdb->prepare( " AND pf.id != 1" );
    10351062
    … …  
    10381065
    10391066        function get_fullname( $user_id = 0 ) {
    1040                 global $bp;
    1041 
    1042                 if ( !$user_id )
     1067
     1068                if ( empty( $user_id ) )
    10431069                        $user_id = bp_displayed_user_id();
    10441070
  • trunk/bp-xprofile/bp-xprofile-cssjs.php

    r5599 r5699  
    11<?php
     2
     3/**
     4 * BuddyPress XProfile CSS and JS
     5 *
     6 * @package BuddyPress
     7 * @subpackage XProfileScripts
     8 */
    29
    310// Exit if accessed directly
  • trunk/bp-xprofile/bp-xprofile-filters.php

    r5131 r5699  
    11<?php
     2
     3/**
     4 * BuddyPress XProfile Filters
     5 *
     6 * Apply WordPress defined filters
     7 *
     8 * @package BuddyPress
     9 * @subpackage XProfileFilters
     10 */
     11
    212// Exit if accessed directly
    313if ( !defined( 'ABSPATH' ) ) exit;
    414
    5 /* Apply WordPress defined filters */
    6 
    7 add_filter( 'bp_get_the_profile_group_name',          'wp_filter_kses',       1 );
    8 add_filter( 'bp_get_the_profile_group_description',   'wp_filter_kses',       1 );
    9 add_filter( 'bp_get_the_profile_field_value',         'xprofile_filter_kses', 1 );
    10 add_filter( 'bp_get_the_profile_field_name',          'wp_filter_kses',       1 );
    11 add_filter( 'bp_get_the_profile_field_edit_value',    'wp_filter_kses',       1 );
    12 add_filter( 'bp_get_the_profile_field_description',   'wp_filter_kses',       1 );
    13 
    14 add_filter( 'bp_get_the_profile_field_value',         'wptexturize'        );
    15 add_filter( 'bp_get_the_profile_field_value',         'convert_smilies', 2 );
    16 add_filter( 'bp_get_the_profile_field_value',         'convert_chars'      );
    17 add_filter( 'bp_get_the_profile_field_value',         'wpautop'            );
    18 add_filter( 'bp_get_the_profile_field_value',         'make_clickable', 8  );
    19 add_filter( 'bp_get_the_profile_field_value',         'force_balance_tags' );
    20 
    21 add_filter( 'bp_get_the_profile_field_edit_value',    'force_balance_tags' );
    22 add_filter( 'bp_get_the_profile_field_edit_value',    'esc_html'           );
    23 
    24 add_filter( 'bp_get_the_profile_group_name',          'stripslashes' );
    25 add_filter( 'bp_get_the_profile_group_description',   'stripslashes' );
    26 add_filter( 'bp_get_the_profile_field_value',         'stripslashes' );
    27 add_filter( 'bp_get_the_profile_field_edit_value',    'stripslashes' );
    28 add_filter( 'bp_get_the_profile_field_name',          'stripslashes' );
    29 add_filter( 'bp_get_the_profile_field_description',   'stripslashes' );
    30 
    31 add_filter( 'xprofile_get_field_data',                'wp_filter_kses', 1 );
    32 add_filter( 'xprofile_field_name_before_save',        'wp_filter_kses', 1 );
    33 add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 );
    34 
    35 add_filter( 'xprofile_get_field_data',                'force_balance_tags' );
    36 add_filter( 'xprofile_field_name_before_save',        'force_balance_tags' );
    37 add_filter( 'xprofile_field_description_before_save', 'force_balance_tags' );
    38 
    39 add_filter( 'xprofile_get_field_data',                'stripslashes' );
    40 
    41 /* Custom BuddyPress filters */
    42 
    43 add_filter( 'bp_get_the_profile_field_value',         'xprofile_filter_format_field_value', 1, 2 );
    44 add_filter( 'bp_get_the_site_member_profile_data',    'xprofile_filter_format_field_value', 1, 2 );
    45 add_filter( 'bp_get_the_profile_field_value',         'xprofile_filter_link_profile_data', 9, 2 );
    46 
    47 add_filter( 'xprofile_data_value_before_save',        'xprofile_sanitize_data_value_before_save', 1, 2 );
     15add_filter( 'bp_get_the_profile_group_name',            'wp_filter_kses',       1 );
     16add_filter( 'bp_get_the_profile_group_description',     'wp_filter_kses',       1 );
     17add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_kses', 1 );
     18add_filter( 'bp_get_the_profile_field_name',            'wp_filter_kses',       1 );
     19add_filter( 'bp_get_the_profile_field_edit_value',      'wp_filter_kses',       1 );
     20add_filter( 'bp_get_the_profile_field_description',     'wp_filter_kses',       1 );
     21
     22add_filter( 'bp_get_the_profile_field_value',           'wptexturize'        );
     23add_filter( 'bp_get_the_profile_field_value',           'convert_smilies', 2 );
     24add_filter( 'bp_get_the_profile_field_value',           'convert_chars'      );
     25add_filter( 'bp_get_the_profile_field_value',           'wpautop'            );
     26add_filter( 'bp_get_the_profile_field_value',           'make_clickable', 8  );
     27add_filter( 'bp_get_the_profile_field_value',           'force_balance_tags' );
     28
     29add_filter( 'bp_get_the_profile_field_edit_value',      'force_balance_tags' );
     30add_filter( 'bp_get_the_profile_field_edit_value',      'esc_html'           );
     31
     32add_filter( 'bp_get_the_profile_group_name',            'stripslashes' );
     33add_filter( 'bp_get_the_profile_group_description',     'stripslashes' );
     34add_filter( 'bp_get_the_profile_field_value',           'stripslashes' );
     35add_filter( 'bp_get_the_profile_field_edit_value',      'stripslashes' );
     36add_filter( 'bp_get_the_profile_field_name',            'stripslashes' );
     37add_filter( 'bp_get_the_profile_field_description',     'stripslashes' );
     38
     39add_filter( 'xprofile_get_field_data',                  'wp_filter_kses', 1 );
     40add_filter( 'xprofile_field_name_before_save',          'wp_filter_kses', 1 );
     41add_filter( 'xprofile_field_description_before_save',   'wp_filter_kses', 1 );
     42
     43add_filter( 'xprofile_get_field_data',                  'force_balance_tags' );
     44add_filter( 'xprofile_field_name_before_save',          'force_balance_tags' );
     45add_filter( 'xprofile_field_description_before_save',   'force_balance_tags' );
     46
     47add_filter( 'xprofile_get_field_data',                  'stripslashes' );
     48
     49add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_format_field_value', 1, 2 );
     50add_filter( 'bp_get_the_site_member_profile_data',      'xprofile_filter_format_field_value', 1, 2 );
     51add_filter( 'bp_get_the_profile_field_value',           'xprofile_filter_link_profile_data', 9, 2 );
     52
     53add_filter( 'xprofile_data_value_before_save',          'xprofile_sanitize_data_value_before_save', 1, 2 );
    4854add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 );
    4955
    … …  
    101107                }
    102108
    103                 if ( $reserialize )
     109                if ( !empty( $reserialize ) )
    104110                        $filtered_field_value = serialize( $filtered_values );
    105111                else
    … …  
    132138
    133139                // If Unix timestamp
    134                 if ( is_numeric( $field_value ) )
     140                if ( is_numeric( $field_value ) ) {
    135141                        $field_value = bp_format_time( $field_value, true, false );
    136142
    137143                // If MySQL timestamp
    138                 else
     144                } else {
    139145                        $field_value = bp_format_time( strtotime( $field_value ), true, false );
     146                }
    140147
    141148        } else {
    … …  
    155162        $values = explode( ',', $field_value );
    156163
    157         if ( $values ) {
     164        if ( !empty( $values ) ) {
    158165                foreach ( (array)$values as $value ) {
    159166                        $value = trim( $value );
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r5329 r5699  
    11<?php
    2 /********************************************************************************
    3  * Business Functions
     2
     3/**
     4 * BuddyPress XProfile Filters
    45 *
    56 * Business functions are where all the magic happens in BuddyPress. They will
    … …  
    78 * hand off to a database class for data access, then return
    89 * true or false on success or failure.
     10 *
     11 * @package BuddyPress
     12 * @subpackage XProfileFilters
    913 */
    1014
    … …  
    2529        extract( $r, EXTR_SKIP );
    2630
    27         if ( !$name )
     31        if ( empty( $name ) )
    2832                return false;
    2933
    … …  
    7983
    8084        // Check we have the minimum details
    81         if ( !$field_group_id )
     85        if ( empty( $field_group_id ) )
    8286                return false;
    8387
    … …  
    8791
    8892        // Instantiate a new field object
    89         if ( $field_id )
     93        if ( !empty( $field_id ) )
    9094                $field = new BP_XProfile_Field( $field_id );
    9195        else
    … …  
    148152 * @param mixed $field The ID of the field, or the $name of the field.
    149153 * @param int $user_id The ID of the user
    150  * @global object $bp Global BuddyPress settings object
    151154 * @uses BP_XProfile_ProfileData::get_value_byid() Fetches the value based on the params passed.
    152155 * @return mixed The profile field data.
    153156 */
    154157function xprofile_get_field_data( $field, $user_id = 0 ) {
    155         global $bp;
    156158
    157159        if ( empty( $user_id ) )
    … …  
    216218        }
    217219
     220        $possible_values = array();
     221
    218222        // Check the value is an acceptable value
    219223        if ( 'checkbox' == $field->type || 'radio' == $field->type || 'selectbox' == $field->type || 'multiselectbox' == $field->type ) {
    … …  
    225229                if ( is_array( $value ) ) {
    226230                        foreach( $value as $i => $single ) {
    227                                 if ( !in_array( $single, (array)$possible_values ) ) {
     231                                if ( !in_array( $single, $possible_values ) ) {
    228232                                        unset( $value[$i] );
    229233                                }
    … …  
    233237                        $value = array_merge( array(), $value );
    234238                } else {
    235                         if ( !in_array( $value, (array)$possible_values ) ) {
     239                        if ( !in_array( $value, $possible_values ) ) {
    236240                                return false;
    237241                        }
    … …  
    301305 */
    302306function xprofile_get_random_profile_data( $user_id, $exclude_fullname = true ) {
    303         $field_data           = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname );
    304 
    305         if ( !$field_data )
     307        $field_data = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname );
     308
     309        if ( empty( $field_data ) )
    306310                return false;
    307311
    308312        $field_data[0]->value = xprofile_format_profile_field( $field_data[0]->type, $field_data[0]->value );
    309313
    310         if ( !$field_data[0]->value || empty( $field_data[0]->value ) )
     314        if ( empty( $field_data[0]->value ) )
    311315                return false;
    312316
    … …  
    352356 */
    353357function xprofile_avatar_upload_dir( $directory = false, $user_id = 0 ) {
    354         global $bp;
    355358
    356359        if ( empty( $user_id ) )
  • trunk/bp-xprofile/bp-xprofile-loader.php

    r5504 r5699  
    11<?php
     2
    23/**
    34 * BuddyPress XProfile Loader
    … …  
    78 *
    89 * @package BuddyPress
    9  * @subpackage XProfile Core
     10 * @subpackage XProfileLoader
    1011 */
    1112
    … …  
    109110                global $bp;
    110111
     112                $sub_nav = array();
     113
    111114                // Add 'Profile' to the main navigation
    112115                $main_nav = array(
  • trunk/bp-xprofile/bp-xprofile-screens.php

    r5418 r5699  
    11<?php
    2 /*******************************************************************************
     2
     3/**
     4 * BuddyPress XProfile Screens
     5 *
    36 * Screen functions are the controllers of BuddyPress. They will execute when
    47 * their specific URL is caught. They will first save or manipulate data using
    58 * business functions, then pass on the user to a template file.
     9 *
     10 * @package BuddyPress
     11 * @subpackage XProfileScreens
    612 */
    713
    … …  
    4652        }
    4753
     54        // No errors
     55        $errors = false;
     56
    4857        // Check to see if any new information has been submitted
    4958        if ( isset( $_POST['field_ids'] ) ) {
    … …  
    7786
    7887                        $is_required[$field_id] = xprofile_check_is_required_field( $field_id );
    79                         if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) )
     88                        if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) {
    8089                                $errors = true;
     90                        }
    8191                }
    8292
    … …  
    8797                // No errors
    8898                } else {
     99
    89100                        // Reset the errors var
    90101                        $errors = false;
    … …  
    108119
    109120                        // Set the feedback messages
    110                         if ( $errors )
     121                        if ( !empty( $errors ) )
    111122                                bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' );
    112123                        else
  • trunk/bp-xprofile/bp-xprofile-template.php

    r5697 r5699  
    11<?php
    2 /***************************************************************************
    3  * XProfile Data Display Template Tags
    4  **/
     2
     3/**
     4 * BuddyPress XProfile Template Tags
     5 *
     6 * @package BuddyPress
     7 * @subpackage XProfileTemplate
     8 */
    59
    610// Exit if accessed directly
    … …  
    2024        var $in_the_loop;
    2125        var $user_id;
    22 
    23         function bp_xprofile_data_template( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
    24                 $this->__construct( $user_id, $profile_group_id, $hide_empty_groups, $fetch_fields, $fetch_field_data, $exclude_groups, $exclude_fields, $hide_empty_fields );
    25         }
    2626
    2727        function __construct( $user_id, $profile_group_id, $hide_empty_groups = false, $fetch_fields = false, $fetch_field_data = false, $exclude_groups = false, $exclude_fields = false, $hide_empty_fields = false ) {
    … …  
    152152
    153153function bp_has_profile( $args = '' ) {
    154         global $bp, $profile_template;
     154        global $profile_template;
    155155
    156156        // Only show empty fields if we're on the Dashboard, or we're on a user's profile edit page,
    … …  
    411411                global $field;
    412412
     413                // Generally a required dropdown field will not get a blank value at
     414                // the top. Set 'null_on_required' to true if you want this blank value
     415                // even on required fields.
    413416                $defaults = array(
    414                         'type'             => false,
    415                         'null_on_required' => false // Generally, a required dropdown field will not
    416                                                     // get a blank value at the top. Set to true if
    417                                                     // you want this blank value even on
    418                                                     // required fields
     417                        'type'                 => false,
     418                        'null_on_required' => false
    419419                );
    420420
    … …  
    433433                switch ( $field->type ) {
    434434                        case 'selectbox':
    435                                 if ( !$field->is_required || $null_on_required )
     435
     436                                if ( !$field->is_required || $null_on_required ) {
    436437                                        $html .= '<option value="">' . /* translators: no option picked in select box */ __( '----', 'buddypress' ) . '</option>';
     438                                }
    437439
    438440                                $original_option_values = '';
    439441                                $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
    440442
    441                                 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) )
     443                                if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) {
    442444                                        $original_option_values = $_POST['field_' . $field->id];
     445                                }
    443446
    444447                                $option_values = (array) $original_option_values;
    445448
    446449                                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
     450
    447451                                        // Check for updated posted values, but errors preventing them from being saved first time
    448452                                        foreach( $option_values as $i => $option_value ) {
    449453                                                if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id] != $option_value ) {
    450                                                         if ( !empty( $_POST['field_' . $field->id] ) )
     454                                                        if ( !empty( $_POST['field_' . $field->id] ) ) {
    451455                                                                $option_values[$i] = $_POST['field_' . $field->id];
     456                                                        }
    452457                                                }
    453458                                        }
     459
    454460                                        $selected = '';
    455461
    … …  
    458464
    459465                                        // First, check to see whether the user-entered value matches
    460                                         if ( in_array( $allowed_options, (array) $option_values ) )
     466                                        if ( in_array( $allowed_options, (array) $option_values ) ) {
    461467                                                $selected = ' selected="selected"';
     468                                        }
    462469
    463470                                        // Then, if the user has not provided a value, check for defaults
    464                                         if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )
     471                                        if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) {
    465472                                                $selected = ' selected="selected"';
     473                                        }
    466474
    467475                                        $html .= apply_filters( 'bp_get_the_profile_field_options_select', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k], $field->id, $selected, $k );
    … …  
    473481                                $original_option_values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field->id ) );
    474482
    475                                 if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) )
     483                                if ( empty( $original_option_values ) && !empty( $_POST['field_' . $field->id] ) ) {
    476484                                        $original_option_values = $_POST['field_' . $field->id];
     485                                }
    477486
    478487                                $option_values = (array) $original_option_values;
    479488
    480489                                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
     490
    481491                                        // Check for updated posted values, but errors preventing them from being saved first time
    482492                                        foreach( $option_values as $i => $option_value ) {
    483493                                                if ( isset( $_POST['field_' . $field->id] ) && $_POST['field_' . $field->id][$i] != $option_value ) {
    484                                                         if ( !empty( $_POST['field_' . $field->id][$i] ) )
     494                                                        if ( !empty( $_POST['field_' . $field->id][$i] ) ) {
    485495                                                                $option_values[] = $_POST['field_' . $field->id][$i];
     496                                                        }
    486497                                                }
    487498                                        }
    … …  
    492503
    493504                                        // First, check to see whether the user-entered value matches
    494                                         if ( in_array( $allowed_options, (array) $option_values ) )
     505                                        if ( in_array( $allowed_options, (array) $option_values ) ) {
    495506                                                $selected = ' selected="selected"';
     507                                        }
    496508
    497509                                        // Then, if the user has not provided a value, check for defaults
    498                                         if ( !is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option )
     510                                        if ( !is_array( $original_option_values ) && empty( $option_values ) && !empty( $options[$k]->is_default_option ) ) {
    499511                                                $selected = ' selected="selected"';
     512                                        }
    500513
    501514                                        $html .= apply_filters( 'bp_get_the_profile_field_options_multiselect', '<option' . $selected . ' value="' . esc_attr( stripslashes( $options[$k]->name ) ) . '">' . esc_attr( stripslashes( $options[$k]->name ) ) . '</option>', $options[$k], $field->id, $selected, $k );
    … …  
    508521
    509522                                for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) {
     523
    510524                                        // Check for updated posted values, but errors preventing them from being saved first time
    511525                                        if ( isset( $_POST['field_' . $field->id] ) && $option_value != $_POST['field_' . $field->id] ) {
    512                                                 if ( !empty( $_POST['field_' . $field->id] ) )
     526                                                if ( !empty( $_POST['field_' . $field->id] ) ) {
    513527                                                        $option_value = $_POST['field_' . $field->id];
     528                                                }
    514529                                        }
    515530
    … …  
    517532                                        // filter, so we'll be sure to get a match
    518533                                        $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    519 
    520                                         $selected = '';
    521                                         if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && $options[$k]->is_default_option ) )
     534                                        $selected        = '';
     535
     536                                        // @todo $value is never created
     537                                        if ( $option_value == $allowed_options || !empty( $value ) && $value == $allowed_options || ( empty( $option_value ) && !empty( $options[$k]->is_default_option ) ) )
    522538                                                $selected = ' checked="checked"';
    523539
    … …  
    549565                                                $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false );
    550566
     567                                                // @todo $value is never created
    551568                                                if ( $option_values[$j] == $allowed_options || @in_array( $allowed_options, $value ) ) {
    552569                                                        $selected = ' checked="checked"';
    … …  
    557574                                        // If the user has not yet supplied a value for this field,
    558575                                        // check to see whether there is a default value available
    559                                         if ( !is_array( $option_values ) && empty( $option_values ) && !$selected && $options[$k]->is_default_option) {
     576                                        if ( !is_array( $option_values ) && empty( $option_values ) && empty( $selected ) && !empty( $options[$k]->is_default_option ) ) {
    560577                                                $selected = ' checked="checked"';
    561578                                        }
    … …  
    574591
    575592                                if ( !empty( $date ) ) {
     593
    576594                                        // If Unix timestamp
    577595                                        if ( is_numeric( $date ) ) {
    … …  
    588606                                }
    589607
    590                                 // Check for updated posted values, but errors preventing them from being saved first time
     608                                // Check for updated posted values, and errors preventing
     609                                // them from being saved first time.
    591610                                if ( !empty( $_POST['field_' . $field->id . '_day'] ) ) {
    592                                         if ( $day != $_POST['field_' . $field->id . '_day'] )
     611                                        if ( $day != $_POST['field_' . $field->id . '_day'] ) {
    593612                                                $day = $_POST['field_' . $field->id . '_day'];
     613                                        }
    594614                                }
    595615
    596616                                if ( !empty( $_POST['field_' . $field->id . '_month'] ) ) {
    597                                         if ( $month != $_POST['field_' . $field->id . '_month'] )
     617                                        if ( $month != $_POST['field_' . $field->id . '_month'] ) {
    598618                                                $month = $_POST['field_' . $field->id . '_month'];
     619                                        }
    599620                                }
    600621
    601622                                if ( !empty( $_POST['field_' . $field->id . '_year'] ) ) {
    602                                         if ( $year != date( "j", $_POST['field_' . $field->id . '_year'] ) )
     623                                        if ( $year != date( "j", $_POST['field_' . $field->id . '_year'] ) ) {
    603624                                                $year = $_POST['field_' . $field->id . '_year'];
    604                                 }
    605 
     625                                        }
     626                                }
     627
     628                                // $type will be passed by calling function when needed
    606629                                switch ( $type ) {
    607630                                        case 'day':
    … …  
    689712}
    690713        function bp_get_profile_field_data( $args = '' ) {
    691                 global $bp;
    692714
    693715                $defaults = array(
    … …  
    765787
    766788function bp_profile_last_updated() {
    767         global $bp;
    768789
    769790        $last_updated = bp_get_profile_last_updated();
    … …  
    776797}
    777798        function bp_get_profile_last_updated() {
    778                 global $bp;
    779799
    780800                $last_updated = bp_get_user_meta( bp_displayed_user_id(), 'profile_last_updated', true );
    … …  
    806826
    807827function bp_get_user_has_avatar() {
    808         global $bp;
    809828
    810829        if ( !bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'no_grav' => true ) ) )
    … …  
    828847        ) );
    829848}
     849
    830850?>
Note: See TracChangeset for help on using the changeset viewer.