Changeset 2076 for branches/1.1/bp-xprofile/bp-xprofile-classes.php
- Timestamp:
- 11/02/2009 06:56:42 PM (17 years ago)
- File:
-
- 1 edited
-
branches/1.1/bp-xprofile/bp-xprofile-classes.php (modified) (52 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1/bp-xprofile/bp-xprofile-classes.php
r2075 r2076 7 7 var $can_delete; 8 8 var $fields; 9 9 10 10 function bp_xprofile_group( $id = null ) { 11 11 global $bp, $wpdb; … … 15 15 } 16 16 } 17 17 18 18 function populate( $id ) { 19 19 global $wpdb, $bp; 20 20 21 21 $sql = $wpdb->prepare("SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id); 22 22 … … 26 26 $this->description = $group->description; 27 27 $this->can_delete = $group->can_delete; 28 28 29 29 // get the fields for this group. 30 30 $this->fields = $this->get_fields(); … … 35 35 function save() { 36 36 global $wpdb, $bp; 37 37 38 38 $this->name = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id ); 39 39 $this->description = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id ); … … 44 44 $sql = $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s, description = %s WHERE id = %d", $this->name, $this->description, $this->id ); 45 45 } else { 46 $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description ); 47 } 48 46 $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description ); 47 } 48 49 49 if ( !$wpdb->query($sql) ) 50 50 return false; 51 51 52 52 do_action( 'xprofile_group_after_save', $this ); 53 53 54 54 return true; 55 55 } 56 56 57 57 function delete() { 58 58 global $wpdb, $bp; 59 59 60 60 if ( !$this->can_delete ) 61 61 return false; 62 62 63 63 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_groups} WHERE id = %d", $this->id ); 64 64 … … 69 69 if ( BP_XProfile_Field::delete_for_group($this->id) ) { 70 70 // Now delete all the profile data for the groups fields 71 for ( $i = 0; $i < count($this->fields); $i++ ) { 71 for ( $i = 0; $i < count($this->fields); $i++ ) { 72 72 BP_XProfile_ProfileData::delete_for_field($this->fields[$i]->id); 73 73 } 74 74 } 75 75 76 76 return true; 77 77 } 78 78 } 79 79 80 80 function get_fields() { 81 81 global $wpdb, $bp; 82 82 83 83 /* Find the max value for field_order, if it is zero, order by field_id instead -- provides backwards compat ordering */ 84 84 if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT MAX(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $this->id ) ) ) … … 90 90 if ( !$fields = $wpdb->get_results( $wpdb->prepare("SELECT id, type FROM {$bp->profile->table_name_fields} WHERE group_id = %d AND parent_id = 0 {$order_sql}", $this->id ) ) ) 91 91 return false; 92 92 93 93 return $fields; 94 94 } 95 95 96 96 /** Static Functions **/ 97 97 98 98 function get_all( $hide_empty = false ) { 99 99 global $wpdb, $bp; … … 107 107 if ( !$groups_temp = $wpdb->get_results($sql) ) 108 108 return false; 109 109 110 110 for ( $i = 0; $i < count($groups_temp); $i++ ) { 111 111 $group = new BP_XProfile_Group($groups_temp[$i]->id); … … 115 115 return $groups; 116 116 } 117 117 118 118 function admin_validate() { 119 119 global $message; 120 120 121 121 // Validate Form 122 122 if ( empty( $_POST['group_name'] ) ) { … … 127 127 } 128 128 } 129 129 130 130 // ADMIN AREA HTML. TODO: Get this out of here. 131 131 … … 138 138 } else { 139 139 $title = __('Edit Field Group', 'buddypress'); 140 $action = "admin.php?page=bp-profile-setup&mode=edit_group&group_id=" . $this->id; 140 $action = "admin.php?page=bp-profile-setup&mode=edit_group&group_id=" . $this->id; 141 141 } 142 142 ?> 143 143 <div class="wrap"> 144 144 145 145 <h2><?php echo $title; ?></h2> 146 146 <br /> 147 147 148 148 <?php 149 149 if ( $message != '' ) { … … 154 154 </div> 155 155 <?php } ?> 156 156 157 157 <form action="<?php echo attribute_escape( $action ); ?>" method="post"> 158 158 159 159 <div id="titlediv"> 160 160 <label for="group_name"><?php _e( "Field Group Name", 'buddypress') ?></label> … … 163 163 </div> 164 164 </div> 165 165 166 166 <p class="submit" style="text-align: left"> 167 167 <input type="submit" name="saveGroup" value="<?php echo attribute_escape( $title ); ?> »" /> 168 168 </p> 169 169 170 170 </form> 171 171 </div> 172 172 173 173 <?php 174 174 } … … 189 189 var $order_by; 190 190 var $is_default_option; 191 191 192 192 var $data; 193 193 var $message = null; … … 199 199 } 200 200 } 201 201 202 202 function populate( $id, $user_id, $get_data ) { 203 203 global $wpdb, $userdata, $bp; 204 204 205 205 if ( is_null($user_id) ) { 206 206 $user_id = $userdata->ID; 207 207 } 208 208 209 209 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id ); 210 210 211 211 if ( $field = $wpdb->get_row($sql) ) { 212 212 $this->id = $field->id; … … 231 231 function delete() { 232 232 global $wpdb, $bp; 233 233 234 234 if ( !$this->id || 235 235 // Prevent deletion by url when can_delete is false. … … 241 241 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) ) 242 242 return false; 243 243 244 244 // delete the data in the DB for this field 245 245 BP_XProfile_ProfileData::delete_for_field($this->id); 246 246 247 247 return true; 248 248 } 249 249 250 250 function save() { 251 251 global $wpdb, $bp; 252 252 253 253 $error = false; 254 254 255 255 $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id ); 256 256 $this->parent_id = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id ); … … 263 263 264 264 do_action( 'xprofile_field_before_save', $this ); 265 265 266 266 if ( $this->id != null ) 267 267 $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); … … 272 272 // The described situation will return 0 here. 273 273 if ( $wpdb->query($sql) !== null ) { 274 274 275 275 // Only do this if we are editing an existing field 276 276 if ( $this->id != null ) { … … 278 278 // field. They will be re-added if needed. 279 279 // This stops orphan options if the user changes a 280 // field from a radio button field to a text box. 280 // field from a radio button field to a text box. 281 281 $this->delete_children(); 282 282 } 283 283 284 284 // Check to see if this is a field with child options. 285 285 // We need to add the options to the db, if it is. … … 288 288 $parent_id = $this->id; 289 289 } else { 290 $parent_id = $wpdb->insert_id; 290 $parent_id = $wpdb->insert_id; 291 291 } 292 292 293 293 if ( 'radio' == $this->type ) { 294 294 295 295 $options = $_POST['radio_option']; 296 296 $defaults = $_POST['isDefault_radio_option']; 297 297 298 298 } else if ( 'selectbox' == $this->type ) { 299 299 300 300 $options = $_POST['selectbox_option']; 301 301 $defaults = $_POST['isDefault_selectbox_option']; 302 302 303 303 } else if ( 'multiselectbox' == $this->type ) { 304 304 305 305 $options = $_POST['multiselectbox_option']; 306 306 $defaults = $_POST['isDefault_multiselectbox_option']; 307 307 308 308 } else if ( 'checkbox' == $this->type ) { 309 309 310 310 $options = $_POST['checkbox_option']; 311 311 $defaults = $_POST['isDefault_checkbox_option']; 312 312 313 313 } 314 314 315 315 $counter = 1; 316 316 if ( $options ) { … … 326 326 } 327 327 328 if ( '' != $option_value ) { 328 if ( '' != $option_value ) { 329 329 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 ) ) ) 330 330 return false; 331 331 } 332 332 333 333 $counter++; 334 } 334 } 335 335 } 336 336 } … … 338 338 $error = true; 339 339 } 340 340 341 341 if ( !$error ) { 342 342 do_action( 'xprofile_field_after_save', $this ); … … 346 346 } 347 347 } 348 348 349 349 function get_field_data($user_id) { 350 350 return new BP_XProfile_ProfileData($this->id, $user_id); 351 351 } 352 352 353 353 function get_children($for_editing = false) { 354 354 global $wpdb, $bp; 355 355 356 356 // This is done here so we don't have problems with sql injection 357 357 if ( 'asc' == $this->order_by && !$for_editing ) { … … 362 362 $sort_sql = 'ORDER BY option_order ASC'; 363 363 } 364 364 365 365 //This eliminates a problem with getting all fields when there is no id for the object 366 366 if ( !$this->id ) { … … 369 369 $parent_id = $this->id; 370 370 } 371 371 372 372 $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 ); 373 373 374 374 if ( !$children = $wpdb->get_results($sql) ) 375 375 return false; 376 376 377 377 return $children; 378 } 379 378 } 379 380 380 function delete_children() { 381 381 global $wpdb, $bp; … … 385 385 $wpdb->query($sql); 386 386 } 387 387 388 388 // Static Functions 389 389 390 390 function get_type( $field_id ) { 391 391 global $wpdb, $bp; … … 396 396 if ( !$field_type = $wpdb->get_var($sql) ) 397 397 return false; 398 398 399 399 return $field_type; 400 400 } 401 401 402 402 return false; 403 403 } 404 404 405 405 function delete_for_group( $group_id ) { 406 406 global $wpdb, $bp; … … 412 412 return false; 413 413 } 414 414 415 415 return true; 416 416 } 417 417 418 418 return false; 419 419 } 420 420 421 421 function get_id_from_name( $field_name ) { 422 422 global $wpdb, $bp; 423 423 424 424 if ( !$bp->profile->table_name_fields || !$field_name ) 425 425 return false; 426 426 427 427 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) ); 428 428 } 429 429 430 430 function update_position( $field_id, $position ) { 431 431 global $wpdb, $bp; 432 432 433 433 if ( !is_numeric( $position ) ) 434 434 return false; 435 435 436 436 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d WHERE id = %d", $position, $field_id ) ); 437 437 } 438 438 439 439 // ADMIN AREA HTML. TODO: Get this out of here. 440 440 441 441 function render_admin_form_children() { 442 442 //This function populates the items for radio buttons checkboxes and drop down boxes 443 $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' ); 444 445 foreach ($input_types as $type) { 443 $input_types = array( 'checkbox', 'selectbox', 'multiselectbox', 'radio' ); 444 445 foreach ($input_types as $type) { 446 446 $default_name = ''; 447 447 448 448 if ( 'multiselectbox' == $type || 'checkbox' == $type ) { 449 449 $default_input = 'checkbox'; … … 455 455 <h4><?php _e('Please enter options for this Field:', 'buddypress') ?></h4> 456 456 <p><?php _e( 'Order By:', 'buddypress' ) ?> 457 457 458 458 <select name="sort_order_<?php echo $type ?>" id="sort_order_<?php echo $type ?>" > 459 459 <option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ) ?></option> … … 461 461 <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ) ?></option> 462 462 </select> 463 463 464 464 <?php 465 465 if ( !$options = $this->get_children(true) ) { … … 481 481 482 482 if ( !empty($options) ) { 483 for ( $i = 0; $i < count($options); $i++ ) { 483 for ( $i = 0; $i < count($options); $i++ ) { 484 484 $j = $i + 1; 485 485 486 486 if ( 'multiselectbox' == $type || 'checkbox' == $type ) 487 487 $default_name = '[' . $j . ']'; 488 488 ?> 489 <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>: 489 <p><?php _e('Option', 'buddypress') ?> <?php echo $j ?>: 490 490 <input type="text" name="<?php echo $type ?>_option[<?php echo $j ?>]" id="<?php echo $type ?>_option<?php echo $j ?>" value="<?php echo attribute_escape( $options[$i]->name ) ?>" /> 491 <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' ) ?> 491 <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' ) ?> 492 492 <?php if ( $j != 1 && 493 493 $options[$i]->id != -1 ) : ?><a href="admin.php?page=bp-profile-setup&mode=delete_option&option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id ?>">[x]</a><?php endif ?></p> … … 495 495 <?php } // end for ?> 496 496 <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="<?php echo $j + 1 ?>" /> 497 498 <?php 499 } else { 497 498 <?php 499 } else { 500 500 if ( 'multiselectbox' == $type || 'checkbox' == $type ) 501 501 $default_name = '[1]'; 502 502 ?> 503 503 504 504 <p><?php _e('Option', 'buddypress') ?> 1: <input type="text" name="<?php echo $type ?>_option[1]" id="<?php echo $type ?>_option1" /> 505 505 <input type="<?php echo $default_input ?>" name="isDefault_<?php echo $type ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type ?>_option" value="1" /> <?php _e( 'Default Value', 'buddypress' ) ?> 506 506 <input type="hidden" name="<?php echo $type ?>_option_number" id="<?php echo $type ?>_option_number" value="2" /> 507 507 508 508 <?php } // end if ?> 509 <div id="<?php echo $type ?>_more"></div> 509 <div id="<?php echo $type ?>_more"></div> 510 510 <p><a href="javascript:add_option('<?php echo $type ?>')"><?php _e('Add Another Option', 'buddypress') ?></a></p> 511 511 </div> 512 512 513 <?php } 514 } 515 513 <?php } 514 } 515 516 516 function render_admin_form( $message = '' ) { 517 517 if ( !$this->id ) { … … 526 526 } else { 527 527 $title = __('Edit Field', 'buddypress'); 528 $action = "admin.php?page=bp-profile-setup&mode=edit_field&group_id=" . $this->group_id . "&field_id=" . $this->id; 528 $action = "admin.php?page=bp-profile-setup&mode=edit_field&group_id=" . $this->group_id . "&field_id=" . $this->id; 529 529 } 530 530 ?> 531 531 532 532 <div class="wrap"> 533 533 534 534 <h2><?php echo $title; ?></h2> 535 535 <br /> 536 536 537 537 <?php 538 538 if ( $message != '' ) { … … 542 542 </div> 543 543 <?php } ?> 544 544 545 545 <form action="<?php echo $action ?>" method="post"> 546 <div id="poststuff"> 546 <div id="poststuff"> 547 547 <div id="titlediv"> 548 548 <h3><label for="title"><?php _e("Field Title", 'buddypress') ?> *</label></h3> … … 551 551 </div> 552 552 </div> 553 553 554 554 <div id="titlediv" class="inside"> 555 555 <h3><label for="description"><?php _e("Field Description", 'buddypress') ?></label></h3> … … 558 558 </div> 559 559 </div> 560 560 561 561 <div id="titlediv"> 562 562 <h3><label for="required"><?php _e("Is This Field Required?", 'buddypress') ?> *</label></h3> … … 580 580 </div> 581 581 582 <?php $this->render_admin_form_children() ?> 583 582 <?php $this->render_admin_form_children() ?> 583 584 584 <p class="submit"> 585 585 <input type="submit" value="<?php _e("Save", 'buddypress') ?> »" name="saveField" id="saveField" style="font-weight: bold" /> 586 586 <?php _e('or', 'buddypress') ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ) ?></a> 587 587 </p> 588 588 589 589 <div class="clear"></div> 590 590 591 591 <?php if ( function_exists('wp_nonce_field') ) 592 592 wp_nonce_field('xprofile_delete_option'); 593 593 ?> 594 595 </form> 594 595 </form> 596 596 </div> 597 597 598 598 <?php 599 599 } 600 600 601 601 function admin_validate() { 602 602 global $message; 603 603 604 604 // Validate Form 605 605 if ( '' == $_POST['title'] || '' == $_POST['required'] || '' == $_POST['fieldtype'] ) { … … 607 607 return false; 608 608 } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'radio' && empty($_POST['radio_option'][1]) ) { 609 $message = __('Radio button field types require at least one option. Please add options below.', 'buddypress'); 609 $message = __('Radio button field types require at least one option. Please add options below.', 'buddypress'); 610 610 return false; 611 611 } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'selectbox' && empty($_POST['selectbox_option'][1]) ) { 612 $message = __('Select box field types require at least one option. Please add options below.', 'buddypress'); 613 return false; 612 $message = __('Select box field types require at least one option. Please add options below.', 'buddypress'); 613 return false; 614 614 } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'multiselectbox' && empty($_POST['multiselectbox_option'][1]) ) { 615 $message = __('Select box field types require at least one option. Please add options below.', 'buddypress'); 616 return false; 615 $message = __('Select box field types require at least one option. Please add options below.', 'buddypress'); 616 return false; 617 617 } else if ( empty($_POST['field_file']) && $_POST['fieldtype'] == 'checkbox' && empty($_POST['checkbox_option'][1]) ) { 618 $message = __('Checkbox field types require at least one option. Please add options below.', 'buddypress'); 619 return false; 618 $message = __('Checkbox field types require at least one option. Please add options below.', 'buddypress'); 619 return false; 620 620 } else { 621 621 return true; … … 640 640 function populate( $field_id, $user_id ) { 641 641 global $wpdb, $bp; 642 642 643 643 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ); 644 644 645 645 if ( $profiledata = $wpdb->get_row($sql) ) { 646 646 647 647 $this->id = $profiledata->id; 648 648 $this->user_id = $profiledata->user_id; … … 652 652 } 653 653 } 654 654 655 655 function exists() { 656 656 global $wpdb, $bp; 657 657 658 658 // check to see if there is data already for the user. 659 659 $sql = $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id ); 660 660 661 if ( !$wpdb->get_row($sql) ) 662 return false; 663 664 return true; 665 } 666 661 if ( !$wpdb->get_row($sql) ) 662 return false; 663 664 return true; 665 } 666 667 667 function is_valid_field() { 668 668 global $wpdb, $bp; 669 669 670 670 // check to see if this data is actually for a valid field. 671 671 $sql = $wpdb->prepare("SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id ); 672 672 673 if ( !$wpdb->get_row($sql) ) 674 return false; 675 673 if ( !$wpdb->get_row($sql) ) 674 return false; 675 676 676 return true; 677 677 } … … 684 684 $this->value = apply_filters( 'xprofile_data_value_before_save', $this->value, $this->id ); 685 685 $this->last_updated = apply_filters( 'xprofile_data_last_updated_before_save', date( 'Y-m-d H:i:s' ), $this->id ); 686 686 687 687 do_action( 'xprofile_data_before_save', $this ); 688 688 … … 698 698 699 699 if ( !$result ) 700 return false; 700 return false; 701 701 702 702 do_action( 'xprofile_data_after_save', $this ); 703 703 704 704 return true; 705 705 } 706 706 707 707 return false; 708 708 } … … 710 710 function delete() { 711 711 global $wpdb, $bp; 712 712 713 713 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $this->field_id, $this->user_id ) ) ) 714 714 return false; 715 715 716 716 return true; 717 717 } 718 718 719 719 /** Static Functions **/ 720 720 721 721 function get_value_byid( $field_id, $user_id = null ) { 722 722 global $wpdb, $bp; … … 724 724 if ( !$user_id ) 725 725 $user_id = $bp->displayed_user->id; 726 726 727 727 if ( !$bp->profile ) 728 728 xprofile_setup_globals(); … … 736 736 } 737 737 } 738 738 739 739 function get_value_byfieldname( $fields, $user_id = null ) { 740 740 global $bp, $wpdb; … … 745 745 if ( !$user_id ) 746 746 $user_id = $bp->displayed_user->id; 747 747 748 748 if ( !$bp->profile ) 749 749 xprofile_setup_globals(); 750 750 751 751 $field_sql = ''; 752 752 … … 755 755 if ( $i == 0 ) 756 756 $field_sql .= $wpdb->prepare( "AND ( f.name = %s ", $fields[$i] ); 757 else 757 else 758 758 $field_sql .= $wpdb->prepare( "OR f.name = %s ", $fields[$i] ); 759 759 } 760 760 761 761 $field_sql .= ')'; 762 762 } else { … … 768 768 if ( !$values = $wpdb->get_results($sql) ) 769 769 return false; 770 770 771 771 $new_values = array(); 772 772 773 773 if ( is_array($fields) ) { 774 774 for ( $i = 0; $i < count($values); $i++ ) { … … 784 784 $new_values = $values[0]->value; 785 785 } 786 786 787 787 return $new_values; 788 788 } 789 789 790 790 function delete_for_field( $field_id ) { 791 791 global $wpdb, $userdata, $bp; … … 793 793 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) ) 794 794 return false; 795 795 796 796 return true; 797 797 } 798 798 799 799 function get_last_updated( $user_id ) { 800 800 global $wpdb, $bp; 801 801 802 802 $last_updated = $wpdb->get_var( $wpdb->prepare( "SELECT last_updated FROM {$bp->profile->table_name_data} WHERE user_id = %d ORDER BY last_updated LIMIT 1", $user_id ) ); 803 803 804 804 return $last_updated; 805 805 } 806 806 807 807 function delete_data_for_user( $user_id ) { 808 808 global $wpdb, $bp; 809 810 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) ); 811 } 812 809 810 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) ); 811 } 812 813 813 function get_random( $user_id, $exclude_fullname ) { 814 814 global $wpdb, $bp; 815 815 816 816 if ( $exclude_fullname ) 817 817 $exclude_sql = $wpdb->prepare( " AND pf.id != 1" ); 818 819 return $wpdb->get_results( $wpdb->prepare( "SELECT pf.type, pf.name, pd.value FROM {$bp->profile->table_name_data} pd INNER JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id AND pd.user_id = %d {$exclude_sql} ORDER BY RAND() LIMIT 1", $user_id ) ); 820 } 821 818 819 return $wpdb->get_results( $wpdb->prepare( "SELECT pf.type, pf.name, pd.value FROM {$bp->profile->table_name_data} pd INNER JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id AND pd.user_id = %d {$exclude_sql} ORDER BY RAND() LIMIT 1", $user_id ) ); 820 } 821 822 822 function get_fullname( $user_id = false ) { 823 823 global $bp; … … 828 828 $data = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id ); 829 829 830 return $data[BP_XPROFILE_FULLNAME_FIELD_NAME]; 830 return $data[BP_XPROFILE_FULLNAME_FIELD_NAME]; 831 831 } 832 832 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)