Changeset 2077 for trunk/bp-xprofile.php
- Timestamp:
- 11/02/2009 07:54:21 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-xprofile.php (modified) (78 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile.php
r2059 r2077 15 15 /* Include deprecated functions if settings allow */ 16 16 if ( !defined( 'BP_IGNORE_DEPRECATED' ) ) 17 require ( BP_PLUGIN_DIR . '/bp-xprofile/deprecated/bp-xprofile-deprecated.php' ); 17 require ( BP_PLUGIN_DIR . '/bp-xprofile/deprecated/bp-xprofile-deprecated.php' ); 18 18 19 19 /* Assign the base group and fullname field names to constants to use in SQL statements */ … … 25 25 * 26 26 * Set up the database tables needed for the xprofile component. 27 * 27 * 28 28 * @package BuddyPress XProfile 29 29 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 36 36 if ( !empty($wpdb->charset) ) 37 37 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; 38 38 39 39 if ( '' == get_site_option( 'bp-xprofile-base-group-name' ) ) 40 40 update_site_option( 'bp-xprofile-base-group-name', 'Base' ); 41 41 42 42 if ( '' == get_site_option( 'bp-xprofile-fullname-field-name' ) ) 43 update_site_option( 'bp-xprofile-fullname-field-name', 'Name' ); 44 43 update_site_option( 'bp-xprofile-fullname-field-name', 'Name' ); 44 45 45 $sql[] = "CREATE TABLE {$bp->profile->table_name_groups} ( 46 46 id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 50 50 KEY can_delete (can_delete) 51 51 ) {$charset_collate};"; 52 52 53 53 $sql[] = "CREATE TABLE {$bp->profile->table_name_fields} ( 54 54 id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 70 70 KEY is_required (is_required) 71 71 ) {$charset_collate};"; 72 72 73 73 $sql[] = "CREATE TABLE {$bp->profile->table_name_data} ( 74 74 id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY, … … 80 80 KEY user_id (user_id) 81 81 ) {$charset_collate};"; 82 82 83 83 if ( '' == get_site_option( 'bp-xprofile-db-version' ) ) { 84 84 $sql[] = "INSERT INTO {$bp->profile->table_name_groups} VALUES ( 1, '" . get_site_option( 'bp-xprofile-base-group-name' ) . "', '', 0 );"; 85 86 $sql[] = "INSERT INTO {$bp->profile->table_name_fields} ( 85 86 $sql[] = "INSERT INTO {$bp->profile->table_name_fields} ( 87 87 id, group_id, parent_id, type, name, is_required, can_delete 88 88 ) VALUES ( … … 90 90 );"; 91 91 } 92 92 93 93 require_once( ABSPATH . 'wp-admin/upgrade-functions.php' ); 94 94 dbDelta($sql); 95 95 96 96 if ( function_exists('bp_wire_install') ) 97 97 xprofile_wire_install(); 98 98 99 99 update_site_option( 'bp-xprofile-db-version', BP_XPROFILE_DB_VERSION ); 100 100 } … … 124 124 * 125 125 * Add the profile globals to the $bp global for use across the installation 126 * 126 * 127 127 * @package BuddyPress XProfile 128 128 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 132 132 function xprofile_setup_globals() { 133 133 global $bp, $wpdb; 134 134 135 135 /* For internal identification */ 136 136 $bp->profile->id = 'profile'; 137 137 138 138 $bp->profile->table_name_groups = $wpdb->base_prefix . 'bp_xprofile_groups'; 139 139 $bp->profile->table_name_fields = $wpdb->base_prefix . 'bp_xprofile_fields'; … … 145 145 /* Register this in the active components array */ 146 146 $bp->active_components[$bp->profile->slug] = $bp->profile->id; 147 147 148 148 /* Set the support field type ids */ 149 149 $bp->profile->field_types = apply_filters( 'xprofile_field_types', array( 'textbox', 'textarea', 'radio', 'checkbox', 'selectbox', 'multiselectbox', 'datebox' ) ); … … 151 151 if ( function_exists( 'bp_wire_install' ) ) 152 152 $bp->profile->table_name_wire = $wpdb->base_prefix . 'bp_xprofile_wire'; 153 153 154 154 do_action( 'xprofile_setup_globals' ); 155 155 } … … 162 162 * Creates the administration interface menus and checks to see if the DB 163 163 * tables are set up. 164 * 164 * 165 165 * @package BuddyPress XProfile 166 166 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 171 171 * @uses add_submenu_page() Adds a submenu tab to a top level tab in the admin area 172 172 * @uses xprofile_install() Runs the DB table installation function 173 * @return 173 * @return 174 174 */ 175 175 function xprofile_add_admin_menu() { 176 176 global $wpdb, $bp; 177 177 178 178 if ( !is_site_admin() ) 179 179 return false; 180 180 181 181 /* Add the administration tab under the "Site Admin" tab for site administrators */ 182 182 add_submenu_page( 'bp-general-settings', __("Profile Field Setup", 'buddypress'), __("Profile Field Setup", 'buddypress'), 'manage-options', 'bp-profile-setup', "xprofile_admin" ); … … 192 192 * 193 193 * Sets up the navigation items for the xprofile component 194 * 194 * 195 195 * @package BuddyPress XProfile 196 196 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 203 203 function xprofile_setup_nav() { 204 204 global $bp; 205 205 206 206 /* Add 'Profile' to the main navigation */ 207 207 bp_core_new_nav_item( array( 'name' => __( 'Profile', 'buddypress' ), 'slug' => $bp->profile->slug, 'position' => 20, 'screen_function' => 'xprofile_screen_display_profile', 'default_subnav_slug' => 'public', 'item_css_id' => $bp->profile->id ) ); 208 208 209 209 $profile_link = $bp->loggedin_user->domain . $bp->profile->slug . '/'; 210 210 211 211 /* Add the subnav items to the profile */ 212 212 bp_core_new_subnav_item( array( 'name' => __( 'Public', 'buddypress' ), 'slug' => 'public', 'parent_url' => $profile_link, 'parent_slug' => $bp->profile->slug, 'screen_function' => 'xprofile_screen_display_profile', 'position' => 10 ) ); … … 219 219 } else { 220 220 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) ); 221 $bp->bp_options_title = $bp->displayed_user->fullname; 221 $bp->bp_options_title = $bp->displayed_user->fullname; 222 222 } 223 223 } 224 224 225 225 do_action( 'xprofile_setup_nav' ); 226 226 } … … 233 233 * 234 234 * Adds an admin bar menu to any profile page providing site admin options for that user. 235 * 235 * 236 236 * @package BuddyPress XProfile 237 237 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 239 239 function xprofile_setup_adminbar_menu() { 240 240 global $bp; 241 241 242 242 if ( !$bp->displayed_user->id ) 243 243 return false; 244 244 245 245 /* Don't show this menu to non site admins or if you're viewing your own profile */ 246 246 if ( !is_site_admin() || bp_is_home() ) … … 249 249 <li id="bp-adminbar-adminoptions-menu"> 250 250 <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a> 251 251 252 252 <ul> 253 253 <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/edit/"><?php printf( __( "Edit %s's Profile", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li> 254 254 <li><a href="<?php echo $bp->displayed_user->domain . $bp->profile->slug ?>/change-avatar/"><?php printf( __( "Edit %s's Avatar", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li> 255 255 256 256 <?php if ( !bp_core_is_user_spammer( $bp->displayed_user->id ) ) : ?> 257 257 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/mark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Mark as Spammer", 'buddypress' ) ?></a></li> … … 259 259 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/unmark-spammer/', 'mark-unmark-spammer' ) ?>" class="confirm"><?php _e( "Not a Spammer", 'buddypress' ) ?></a></li> 260 260 <?php endif; ?> 261 261 262 262 <li><a href="<?php echo wp_nonce_url( $bp->displayed_user->domain . 'admin/delete-user/', 'delete-user' ) ?>" class="confirm"><?php printf( __( "Delete %s", 'buddypress' ), attribute_escape( $bp->displayed_user->fullname ) ) ?></a></li> 263 263 264 264 <?php do_action( 'xprofile_adminbar_menu_items' ) ?> 265 265 </ul> … … 281 281 * 282 282 * Handles the display of the profile page by loading the correct template file. 283 * 283 * 284 284 * @package BuddyPress Xprofile 285 285 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename) … … 292 292 if ( isset($_GET['new']) ) 293 293 bp_core_delete_notifications_for_user_by_item_id( $bp->loggedin_user->id, $bp->displayed_user->id, 'friends', 'friendship_accepted' ); 294 294 295 295 do_action( 'xprofile_screen_display_profile', $_GET['new'] ); 296 296 bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'profile/index' ) ); … … 302 302 * Handles the display of the profile edit page by loading the correct template file. 303 303 * Also checks to make sure this can only be accessed for the logged in users profile. 304 * 304 * 305 305 * @package BuddyPress Xprofile 306 306 * @uses bp_is_home() Checks to make sure the current user being viewed equals the logged in user … … 309 309 function xprofile_screen_edit_profile() { 310 310 global $bp; 311 311 312 312 if ( !bp_is_home() && !is_site_admin() ) 313 313 return false; 314 314 315 315 /* Check to see if any new information has been submitted */ 316 316 if ( isset($_POST['field_ids']) ) { 317 317 318 318 /* Check the nonce */ 319 319 check_admin_referer( 'bp_xprofile_edit' ); 320 320 321 321 /* Check we have field ID's */ 322 322 if ( empty( $_POST['field_ids'] ) ) 323 323 bp_core_redirect( $bp->displayed_user->domain . BP_XPROFILE_SLUG . '/edit/group/' . $bp->action_variables[1] . '/' ); 324 324 325 325 /* Explode the posted field IDs into an array so we know which fields have been submitted */ 326 326 $posted_field_ids = explode( ',', $_POST['field_ids'] ); 327 327 328 328 /* Loop through the posted fields formatting any datebox values then validate the field */ 329 foreach ( $posted_field_ids as $field_id ) { 330 329 foreach ( $posted_field_ids as $field_id ) { 331 330 if ( !isset( $_POST['field_' . $field_id] ) ) { 332 331 333 332 if ( is_numeric( $_POST['field_' . $field_id . '_day'] ) ) { 334 333 /* Concatenate the values. */ 335 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . 334 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . 336 335 $_POST['field_' . $field_id . '_month'] . ' ' . 337 336 $_POST['field_' . $field_id . '_year']; … … 348 347 349 348 if ( $errors ) 350 bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' ); 351 else { 349 bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' ); 350 else { 352 351 /* Reset the errors var */ 353 352 $errors = false; 354 353 355 354 /* Now we've checked for required fields, lets save the values. */ 356 foreach ( $posted_field_ids as $field_id ) { 355 foreach ( $posted_field_ids as $field_id ) { 357 356 if ( !xprofile_set_field_data( $field_id, $bp->displayed_user->id, $_POST['field_' . $field_id] ) ) 358 357 $errors = true; … … 360 359 do_action( 'xprofile_profile_field_data_updated', $field_id, $_POST['field_' . $field_id] ); 361 360 } 362 361 363 362 do_action( 'xprofile_updated_profile', $posted_field_ids, $errors ); 364 363 365 364 /* Set the feedback messages */ 366 365 if ( $errors ) 367 366 bp_core_add_message( __( 'There was a problem updating some of your profile information, please try again.', 'buddypress' ), 'error' ); 368 else 367 else 369 368 bp_core_add_message( __( 'Changes saved.', 'buddypress' ) ); 370 369 … … 375 374 376 375 do_action( 'xprofile_screen_edit_profile' ); 377 bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'profile/edit' ) ); 376 bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'profile/edit' ) ); 378 377 } 379 378 … … 382 381 * 383 382 * Handles the uploading and cropping of a user avatar. Displays the change avatar page. 384 * 383 * 385 384 * @package BuddyPress Xprofile 386 385 * @uses bp_is_home() Checks to make sure the current user being viewed equals the logged in user … … 389 388 function xprofile_screen_change_avatar() { 390 389 global $bp; 391 390 392 391 if ( !bp_is_home() && !is_site_admin() ) 393 392 return false; 394 393 395 394 $bp->avatar_admin->step = 'upload-image'; 396 395 397 396 if ( !empty( $_FILES ) ) { 398 397 399 398 /* Check the nonce */ 400 399 check_admin_referer( 'bp_avatar_upload' ); 401 400 402 /* Pass the file to the avatar upload handler */ 403 if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) { 401 /* Pass the file to the avatar upload handler */ 402 if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) { 404 403 $bp->avatar_admin->step = 'crop-image'; 405 404 … … 408 407 } 409 408 } 410 409 411 410 /* If the image cropping is done, crop the image and save a full/thumb version */ 412 411 if ( isset( $_POST['avatar-crop-submit'] ) ) { 413 412 414 413 /* Check the nonce */ 415 414 check_admin_referer( 'bp_avatar_cropstore' ); … … 424 423 425 424 do_action( 'xprofile_screen_change_avatar' ); 426 425 427 426 bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'profile/change-avatar' ) ); 428 427 } … … 434 433 * Settings are hooked into the function: bp_core_screen_notification_settings_content() 435 434 * in bp-core/bp-core-settings.php 436 * 435 * 437 436 * @package BuddyPress Xprofile 438 437 * @global $current_user WordPress global variable containing current logged in user information 439 438 */ 440 function xprofile_screen_notification_settings() { 439 function xprofile_screen_notification_settings() { 441 440 global $current_user; ?> 442 441 <?php if ( function_exists('bp_wire_install') ) { ?> … … 455 454 <td class="no"><input type="radio" name="notifications[notification_profile_wire_post]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_profile_wire_post' ) ) { ?>checked="checked" <?php } ?>/></td> 456 455 </tr> 457 456 458 457 <?php do_action( 'xprofile_screen_notification_settings' ) ?> 459 458 </table> 460 459 <?php } ?> 461 <?php 460 <?php 462 461 } 463 462 add_action( 'bp_notification_settings', 'xprofile_screen_notification_settings', 1 ); … … 479 478 * 480 479 * The function will delete the active avatar for a user. 481 * 480 * 482 481 * @package BuddyPress Xprofile 483 482 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 491 490 if ( $bp->profile->slug != $bp->current_component || 'change-avatar' != $bp->current_action || 'delete-avatar' != $bp->action_variables[0] ) 492 491 return false; 493 492 494 493 /* Check the nonce */ 495 494 check_admin_referer( 'bp_delete_avatar_link' ); 496 495 497 496 if ( !bp_is_home() && !is_site_admin() ) 498 497 return false; 499 498 500 499 if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->displayed_user->id ) ) ) 501 500 bp_core_add_message( __( 'Your avatar was deleted successfully!', 'buddypress' ) ); … … 503 502 bp_core_add_message( __( 'There was a problem deleting that avatar, please try again.', 'buddypress' ), 'error' ); 504 503 505 bp_core_redirect( wp_get_referer() ); 504 bp_core_redirect( wp_get_referer() ); 506 505 } 507 506 add_action( 'wp', 'xprofile_action_delete_avatar', 3 ); … … 510 509 * xprofile_action_new_wire_post() 511 510 * 512 * Posts a new wire post to the users profile wire. 513 * 511 * Posts a new wire post to the users profile wire. 512 * 514 513 * @package BuddyPress XProfile 515 514 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 523 522 if ( $bp->current_component != $bp->wire->slug ) 524 523 return false; 525 524 526 525 if ( 'post' != $bp->current_action ) 527 526 return false; 528 527 529 528 /* Check the nonce */ 530 if ( !check_admin_referer( 'bp_wire_post' ) ) 531 return false; 532 529 if ( !check_admin_referer( 'bp_wire_post' ) ) 530 return false; 531 533 532 if ( !$wire_post = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) { 534 533 bp_core_add_message( __( 'Wire message could not be posted. Please try again.', 'buddypress' ), 'error' ); 535 534 } else { 536 535 bp_core_add_message( __( 'Wire message successfully posted.', 'buddypress' ) ); 537 536 538 537 /* Record the notification for the reciever if it's not on their own wire */ 539 538 if ( !bp_is_home() ) 540 bp_core_add_notification( $bp->loggedin_user->id, $bp->displayed_user->id, $bp->profile->id, 'new_wire_post' ); 541 539 bp_core_add_notification( $bp->loggedin_user->id, $bp->displayed_user->id, $bp->profile->id, 'new_wire_post' ); 540 542 541 /* Record this on the poster's activity screen */ 543 542 if ( ( $wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) { 544 543 $from_user_link = bp_core_get_userlink($wire_post->user_id); 545 $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>'; 546 $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true ); 544 $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>'; 545 $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true ); 547 546 } else if ( ( $wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) { 548 547 $from_user_link = bp_core_get_userlink($wire_post->user_id); 549 548 $to_user_link = bp_core_get_userlink( $wire_post->item_id, false, false, true, true ); 550 $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>'; 549 $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>'; 551 550 $primary_link = bp_core_get_userlink( $wire_post->item_id, false, true ); 552 } 553 551 } 552 554 553 $content .= '<blockquote>' . bp_create_excerpt($wire_post->content) . '</blockquote>'; 555 554 … … 563 562 ) ); 564 563 565 do_action( 'xprofile_new_wire_post', &$wire_post ); 564 do_action( 'xprofile_new_wire_post', &$wire_post ); 566 565 } 567 566 … … 577 576 * xprofile_action_delete_wire_post() 578 577 * 579 * Deletes a wire post from the users profile wire. 580 * 578 * Deletes a wire post from the users profile wire. 579 * 581 580 * @package BuddyPress XProfile 582 581 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() … … 588 587 function xprofile_action_delete_wire_post() { 589 588 global $bp; 590 589 591 590 if ( $bp->current_component != $bp->wire->slug ) 592 591 return false; 593 592 594 593 if ( $bp->current_action != 'delete' ) 595 594 return false; 596 595 597 596 if ( !check_admin_referer( 'bp_wire_delete_link' ) ) 598 597 return false; 599 598 600 599 $wire_post_id = $bp->action_variables[0]; 601 600 … … 605 604 /* Delete the post from activity streams */ 606 605 xprofile_delete_activity( array( 'item_id' => $wire_post_id, 'component_action' => 'new_wire_post' ) ); 607 608 do_action( 'xprofile_delete_wire_post', $wire_post_id ); 606 607 do_action( 'xprofile_delete_wire_post', $wire_post_id ); 609 608 } else { 610 609 bp_core_add_message( __('Wire post could not be deleted, please try again.', 'buddypress'), 'error' ); 611 610 } 612 611 613 612 if ( !strpos( wp_get_referer(), $bp->wire->slug ) ) { 614 613 bp_core_redirect( $bp->displayed_user->domain ); … … 629 628 function xprofile_register_activity_actions() { 630 629 global $bp; 631 630 632 631 if ( !function_exists( 'bp_activity_set_action' ) ) 633 632 return false; … … 647 646 * Records activity for the logged in user within the profile component so that 648 647 * it will show in the users activity stream (if installed) 649 * 648 * 650 649 * @package BuddyPress XProfile 651 650 * @param $args Array containing all variables used after extract() call … … 655 654 function xprofile_record_activity( $args = true ) { 656 655 global $bp; 657 656 658 657 if ( !function_exists( 'bp_activity_add' ) ) 659 658 return false; … … 672 671 673 672 $r = wp_parse_args( $args, $defaults ); 674 extract( $r, EXTR_SKIP ); 675 673 extract( $r, EXTR_SKIP ); 674 676 675 return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) ); 677 676 } … … 682 681 * Deletes activity for a user within the profile component so that 683 682 * it will be removed from the users activity stream and sitewide stream (if installed) 684 * 683 * 685 684 * @package BuddyPress XProfile 686 685 * @param $args Array containing all variables used after extract() call … … 690 689 function xprofile_delete_activity( $args = '' ) { 691 690 global $bp; 692 691 693 692 if ( function_exists('bp_activity_delete_by_item_id') ) { 694 693 extract($args); … … 699 698 function xprofile_register_activity_action( $key, $value ) { 700 699 global $bp; 701 700 702 701 if ( !function_exists( 'bp_activity_set_action' ) ) 703 702 return false; 704 703 705 704 return apply_filters( 'xprofile_register_activity_action', bp_activity_set_action( $bp->profile->id, $key, $value ), $key, $value ); 706 705 } … … 710 709 * 711 710 * Format notifications into something that can be read and displayed 712 * 711 * 713 712 * @package BuddyPress Xprofile 714 713 * @param $item_id The ID of the specific item for which the activity is recorded (could be a wire post id, user id etc) … … 724 723 if ( 'new_wire_post' == $action ) { 725 724 if ( (int)$total_items > 1 ) { 726 return apply_filters( 'bp_xprofile_multiple_new_wire_post_notification', '<a href="' . $bp->loggedin_user->domain . $bp->wire->slug . '" title="' . __( 'Wire', 'buddypress' ) . '">' . sprintf( __( 'You have %d new posts on your wire', 'buddypress' ), (int)$total_items ) . '</a>', $total_items ); 725 return apply_filters( 'bp_xprofile_multiple_new_wire_post_notification', '<a href="' . $bp->loggedin_user->domain . $bp->wire->slug . '" title="' . __( 'Wire', 'buddypress' ) . '">' . sprintf( __( 'You have %d new posts on your wire', 'buddypress' ), (int)$total_items ) . '</a>', $total_items ); 727 726 } else { 728 727 $user_fullname = bp_core_get_user_displayname( $item_id ); … … 730 729 } 731 730 } 732 731 733 732 do_action( 'xprofile_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 734 733 735 734 return false; 736 735 } … … 758 757 759 758 $r = wp_parse_args( $args, $defaults ); 760 extract( $r, EXTR_SKIP ); 759 extract( $r, EXTR_SKIP ); 761 760 762 761 if ( !$name ) 763 762 return false; 764 763 765 764 $field_group = new BP_XProfile_Group( $field_group_id ); 766 765 $field_group->name = $name; 767 766 $field_group->description = $description; 768 767 $field_group->can_delete = $can_delete; 769 768 770 769 return $field_group->save(); 771 770 } … … 785 784 function xprofile_insert_field( $args = '' ) { 786 785 global $bp; 787 786 788 787 extract( $args ); 789 788 790 789 /** 791 790 * Possible parameters (pass as assoc array): … … 803 802 * 'option_order' 804 803 */ 805 804 806 805 /* Check we have the minimum details */ 807 806 if ( !$field_group_id ) 808 807 return false; 809 808 810 809 /* Check this is a valid field type */ 811 810 if ( !in_array( $type, (array) $bp->profile->field_types ) ) 812 811 return false; 813 812 814 813 /* Instantiate a new field object */ 815 814 if ( $field_id ) … … 819 818 820 819 $field->group_id = $field_group_id; 821 820 822 821 if ( !empty( $parent_id ) ) 823 822 $field->parent_id = $parent_id; 824 823 825 824 if ( !empty( $type ) ) 826 825 $field->type = $type; 827 826 828 827 if ( !empty( $name ) ) 829 828 $field->name = $name; … … 831 830 if ( !empty( $description ) ) 832 831 $field->description = $description; 833 832 834 833 if ( !empty( $is_required ) ) 835 834 $field->is_required = $is_required; 836 835 837 836 if ( !empty( $can_delete ) ) 838 837 $field->can_delete = $can_delete; 839 838 840 839 if ( !empty( $field_order ) ) 841 840 $field->field_order = $field_order; 842 841 843 842 if ( !empty( $order_by ) ) 844 843 $field->order_by = $order_by; 845 844 846 845 if ( !empty( $is_default_option ) ) 847 846 $field->is_default_option = $is_default_option; 848 847 849 848 if ( !empty( $option_order ) ) 850 849 $field->option_order = $option_order; 851 850 852 851 if ( !$field->save() ) 853 852 return false; … … 872 871 * 873 872 * Fetches profile data for a specific field for the user. 874 * 873 * 875 874 * @package BuddyPress Core 876 875 * @param $field The ID of the field, or the $name of the field. … … 882 881 function xprofile_get_field_data( $field, $user_id = null ) { 883 882 global $bp; 884 883 885 884 if ( !$user_id ) 886 885 $user_id = $bp->displayed_user->id; 887 886 888 887 if ( !$user_id ) 889 888 return false; … … 904 903 * 905 904 * A simple function to set profile data for a specific field for a specific user. 906 * 905 * 907 906 * @package BuddyPress Core 908 907 * @param $field The ID of the field, or the $name of the field. … … 918 917 else 919 918 $field_id = xprofile_get_field_id_from_name( $field ); 920 919 921 920 if ( !$field_id ) 922 921 return false; 923 922 924 923 $field = new BP_XProfile_ProfileData(); 925 924 $field->field_id = $field_id; 926 925 $field->user_id = $user_id; 927 926 $field->value = maybe_serialize( $value ); 928 927 929 928 return $field->save(); 930 929 } … … 935 934 else 936 935 $field_id = xprofile_get_field_id_from_name( $field ); 937 936 938 937 if ( !$field_id ) 939 938 return false; 940 939 941 940 $field = new BP_XProfile_ProfileData( $field_id ); 942 941 return $field->delete(); … … 945 944 function xprofile_check_is_required_field( $field_id ) { 946 945 $field = new BP_Xprofile_Field( $field_id ); 947 946 948 947 if ( (int)$field->is_required ) 949 948 return true; 950 949 951 950 return false; 952 951 } … … 956 955 * 957 956 * Returns the ID for the field based on the field name. 958 * 957 * 959 958 * @package BuddyPress Core 960 959 * @param $field_name The name of the field to get the ID for. … … 969 968 * 970 969 * Fetches a random piece of profile data for the user. 971 * 970 * 972 971 * @package BuddyPress Core 973 972 * @param $user_id User ID of the user to get random data for … … 982 981 $field_data = BP_XProfile_ProfileData::get_random( $user_id, $exclude_fullname ); 983 982 $field_data[0]->value = xprofile_format_profile_field( $field_data[0]->type, $field_data[0]->value ); 984 983 985 984 if ( !$field_data[0]->value || empty( $field_data[0]->value ) ) 986 985 return false; 987 986 988 987 return apply_filters( 'xprofile_get_random_profile_data', $field_data ); 989 988 } … … 993 992 * 994 993 * Formats a profile field according to its type. [ TODO: Should really be moved to filters ] 995 * 994 * 996 995 * @package BuddyPress Core 997 996 * @param $field_type The type of field: datebox, selectbox, textbox etc … … 1003 1002 if ( !isset($field_value) || empty( $field_value ) ) 1004 1003 return false; 1005 1004 1006 1005 $field_value = bp_unserialize_profile_field( $field_value ); 1007 1006 1008 1007 if ( 'datebox' == $field_type ) { 1009 1008 $field_value = bp_format_time( $field_value, true ); … … 1013 1012 $field_value = str_replace(']]>', ']]>', $content); 1014 1013 } 1015 1014 1016 1015 return stripslashes( stripslashes( $field_value ) ); 1017 1016 } … … 1025 1024 * 1026 1025 * Setup the avatar upload directory for a user. 1027 * 1026 * 1028 1027 * @package BuddyPress Core 1029 1028 * @param $directory The root directory name … … 1036 1035 if ( !$user_id ) 1037 1036 $user_id = $bp->displayed_user->id; 1038 1037 1039 1038 if ( !$directory ) 1040 1039 $directory = 'avatars'; … … 1045 1044 1046 1045 $newbdir = $newdir; 1047 1046 1048 1047 if ( !file_exists( $newdir ) ) 1049 1048 @wp_mkdir_p( $newdir ); … … 1060 1059 * 1061 1060 * Syncs Xprofile data to the standard built in WordPress profile data. 1062 * 1061 * 1063 1062 * @package BuddyPress Core 1064 1063 */ 1065 1064 function xprofile_sync_wp_profile() { 1066 1065 global $bp, $wpdb; 1067 1066 1068 1067 if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) 1069 1068 return true; 1070 1069 1071 1070 $fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id ); 1072 1071 $space = strpos( $fullname, ' ' ); 1073 1072 1074 1073 if ( false === $space ) { 1075 1074 $firstname = $fullname; … … 1077 1076 } else { 1078 1077 $firstname = substr( $fullname, 0, $space ); 1079 $lastname = trim( substr( $fullname, $space, strlen($fullname) ) ); 1080 } 1081 1078 $lastname = trim( substr( $fullname, $space, strlen($fullname) ) ); 1079 } 1080 1082 1081 update_usermeta( $bp->loggedin_user->id, 'nickname', $fullname ); 1083 1082 update_usermeta( $bp->loggedin_user->id, 'first_name', $firstname ); … … 1095 1094 * Removes notifications from the notification menu when a user clicks on them and 1096 1095 * is taken to a specific screen. 1097 * 1096 * 1098 1097 * @package BuddyPress Core 1099 1098 */ 1100 1099 function xprofile_remove_screen_notifications() { 1101 1100 global $bp; 1102 1101 1103 1102 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->profile->id, 'new_wire_post' ); 1104 1103 } … … 1111 1110 * profile data from each table. Also we need to clean anything up in the usermeta table 1112 1111 * that this component uses. 1113 * 1112 * 1114 1113 * @package BuddyPress XProfile 1115 1114 * @param $user_id The ID of the deleted user … … 1120 1119 function xprofile_remove_data( $user_id ) { 1121 1120 BP_XProfile_ProfileData::delete_data_for_user( $user_id ); 1122 1121 1123 1122 // delete any avatar files. 1124 1123 @unlink( get_usermeta( $user_id, 'bp_core_avatar_v1_path' ) ); 1125 1124 @unlink( get_usermeta( $user_id, 'bp_core_avatar_v2_path' ) ); 1126 1125 1127 1126 // unset the usermeta for avatars from the usermeta table. 1128 1127 delete_usermeta( $user_id, 'bp_core_avatar_v1' ); … … 1144 1143 1145 1144 function xprofile_clear_profile_data_object_cache( $group_id ) { 1146 global $bp; 1145 global $bp; 1147 1146 wp_cache_delete( 'xprofile_fields_' . $group_id . '_' . $bp->loggedin_user->id, 'bp' ); 1148 1147 wp_cache_delete( 'bp_user_fullname_' . $bp->loggedin_user->id, 'bp' );
Note: See TracChangeset
for help on using the changeset viewer.