Changeset 9471 for trunk/src/bp-xprofile/bp-xprofile-classes.php
- Timestamp:
- 02/10/2015 02:49:16 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-classes.php
r9351 r9471 25 25 26 26 public function populate( $id ) { 27 global $wpdb , $bp;27 global $wpdb; 28 28 29 29 $group = wp_cache_get( 'xprofile_group_' . $this->id, 'bp' ); 30 30 31 31 if ( false === $group ) { 32 $bp = buddypress(); 32 33 $group = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_groups} WHERE id = %d", $id ) ); 33 34 } … … 45 46 46 47 public function save() { 47 global $wpdb , $bp;48 global $wpdb; 48 49 49 50 $this->name = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id ); … … 60 61 */ 61 62 do_action_ref_array( 'xprofile_group_before_save', array( &$this ) ); 63 64 $bp = buddypress(); 62 65 63 66 if ( $this->id ) … … 86 89 87 90 public function delete() { 88 global $wpdb , $bp;91 global $wpdb; 89 92 90 93 if ( empty( $this->can_delete ) ) … … 99 102 */ 100 103 do_action_ref_array( 'xprofile_group_before_delete', array( &$this ) ); 104 105 $bp = buddypress(); 101 106 102 107 // Delete field group … … 163 168 */ 164 169 public static function get( $args = array() ) { 165 global $wpdb , $bp;170 global $wpdb; 166 171 167 172 $defaults = array( … … 197 202 } 198 203 204 $bp = buddypress(); 205 199 206 if ( ! empty( $hide_empty_groups ) ) { 200 207 $group_ids = $wpdb->get_col( "SELECT DISTINCT g.id 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" ); … … 416 423 417 424 public static function update_position( $field_group_id, $position ) { 418 global $wpdb , $bp;425 global $wpdb; 419 426 420 427 if ( !is_numeric( $position ) ) { … … 424 431 // purge profile field group cache 425 432 wp_cache_delete( 'xprofile_groups_inc_empty', 'bp' ); 433 434 $bp = buddypress(); 426 435 427 436 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET group_order = %d WHERE id = %d", $position, $field_group_id ) ); … … 481 490 */ 482 491 public static function fetch_default_visibility_levels() { 483 global $wpdb , $bp;492 global $wpdb; 484 493 485 494 $default_visibility_levels = wp_cache_get( 'xprofile_default_visibility_levels', 'bp' ); 486 495 487 496 if ( false === $default_visibility_levels ) { 497 $bp = buddypress(); 498 488 499 $levels = $wpdb->get_results( "SELECT object_id, meta_key, meta_value FROM {$bp->profile->table_name_meta} WHERE object_type = 'field' AND ( meta_key = 'default_visibility' OR meta_key = 'allow_custom_visibility' )" ); 489 500 … … 658 669 659 670 public function populate( $id, $user_id, $get_data ) { 660 global $wpdb, $userdata , $bp;671 global $wpdb, $userdata; 661 672 662 673 if ( empty( $user_id ) ) { … … 664 675 } 665 676 677 $bp = buddypress(); 666 678 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE id = %d", $id ); 667 679 … … 699 711 700 712 public function delete( $delete_data = false ) { 701 global $wpdb , $bp;713 global $wpdb; 702 714 703 715 // Prevent deletion if no ID is present … … 707 719 return false; 708 720 721 $bp = buddypress(); 722 709 723 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE id = %d OR parent_id = %d", $this->id, $this->id ) ) ) 710 724 return false; … … 718 732 719 733 public function save() { 720 global $wpdb, $bp; 734 global $wpdb; 735 736 $bp = buddypress(); 721 737 722 738 $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id ); … … 857 873 858 874 public function get_children( $for_editing = false ) { 859 global $wpdb , $bp;875 global $wpdb; 860 876 861 877 // This is done here so we don't have problems with sql injection … … 875 891 } 876 892 893 $bp = buddypress(); 877 894 $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 ); 878 895 … … 891 908 892 909 public function delete_children() { 893 global $wpdb, $bp; 894 910 global $wpdb; 911 912 $bp = buddypress(); 895 913 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE parent_id = %d", $this->id ); 896 914 … … 901 919 902 920 public static function get_type( $field_id ) { 903 global $wpdb , $bp;921 global $wpdb; 904 922 905 923 if ( !empty( $field_id ) ) { 924 $bp = buddypress(); 906 925 $sql = $wpdb->prepare( "SELECT type FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ); 907 926 … … 917 936 918 937 public static function delete_for_group( $group_id ) { 919 global $wpdb , $bp;938 global $wpdb; 920 939 921 940 if ( !empty( $group_id ) ) { 941 $bp = buddypress(); 922 942 $sql = $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ); 923 943 … … 933 953 934 954 public static function get_id_from_name( $field_name ) { 935 global $wpdb, $bp; 955 global $wpdb; 956 957 $bp = buddypress(); 936 958 937 959 if ( empty( $bp->profile->table_name_fields ) || !isset( $field_name ) ) … … 942 964 943 965 public static function update_position( $field_id, $position, $field_group_id ) { 944 global $wpdb , $bp;966 global $wpdb; 945 967 946 968 if ( !is_numeric( $position ) || !is_numeric( $field_group_id ) ) 947 969 return false; 970 971 $bp = buddypress(); 948 972 949 973 // Update $field_id with new $position and $field_group_id … … 1221 1245 1222 1246 public function populate( $field_id, $user_id ) { 1223 global $wpdb , $bp;1247 global $wpdb; 1224 1248 1225 1249 $cache_key = "{$user_id}:{$field_id}"; … … 1227 1251 1228 1252 if ( false === $profiledata ) { 1253 $bp = buddypress(); 1254 1229 1255 $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id = %d", $field_id, $user_id ); 1230 1256 $profiledata = $wpdb->get_row( $sql ); … … 1257 1283 */ 1258 1284 public function exists() { 1259 global $wpdb , $bp;1285 global $wpdb; 1260 1286 1261 1287 // Check cache first … … 1266 1292 $retval = true; 1267 1293 } else { 1294 $bp = buddypress(); 1268 1295 $retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $this->user_id, $this->field_id ) ); 1269 1296 } … … 1284 1311 * 1285 1312 * @global object $wpdb 1286 * @global array $bp1287 1313 * @return bool 1288 1314 */ 1289 1315 public function is_valid_field() { 1290 global $wpdb, $bp; 1316 global $wpdb; 1317 1318 $bp = buddypress(); 1291 1319 1292 1320 $retval = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE id = %d", $this->field_id ) ); … … 1304 1332 1305 1333 public function save() { 1306 global $wpdb, $bp; 1334 global $wpdb; 1335 1336 $bp = buddypress(); 1307 1337 1308 1338 $this->user_id = apply_filters( 'xprofile_data_user_id_before_save', $this->user_id, $this->id ); … … 1509 1539 */ 1510 1540 public static function get_fielddataid_byid( $field_id, $user_id ) { 1511 global $wpdb , $bp;1541 global $wpdb; 1512 1542 1513 1543 if ( empty( $field_id ) || empty( $user_id ) ) { 1514 1544 $fielddata_id = 0; 1515 1545 } else { 1546 $bp = buddypress(); 1516 1547 1517 1548 // Check cache first … … 1539 1570 */ 1540 1571 public static function get_value_byid( $field_id, $user_ids = null ) { 1541 global $wpdb , $bp;1572 global $wpdb; 1542 1573 1543 1574 if ( empty( $user_ids ) ) { … … 1562 1593 // Prime caches 1563 1594 if ( ! empty( $uncached_ids ) ) { 1595 $bp = buddypress(); 1564 1596 $uncached_ids_sql = implode( ',', $uncached_ids ); 1565 1597 $queried_data = $wpdb->get_results( $wpdb->prepare( "SELECT id, user_id, field_id, value, last_updated FROM {$bp->profile->table_name_data} WHERE field_id = %d AND user_id IN ({$uncached_ids_sql})", $field_id ) ); … … 1610 1642 1611 1643 public static function get_value_byfieldname( $fields, $user_id = null ) { 1612 global $ bp, $wpdb;1644 global $wpdb; 1613 1645 1614 1646 if ( empty( $fields ) ) 1615 1647 return false; 1648 1649 $bp = buddypress(); 1616 1650 1617 1651 if ( empty( $user_id ) ) … … 1659 1693 1660 1694 public static function delete_for_field( $field_id ) { 1661 global $wpdb, $bp; 1695 global $wpdb; 1696 1697 $bp = buddypress(); 1662 1698 1663 1699 if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE field_id = %d", $field_id ) ) ) … … 1668 1704 1669 1705 public static function get_last_updated( $user_id ) { 1670 global $wpdb, $bp; 1706 global $wpdb; 1707 1708 $bp = buddypress(); 1671 1709 1672 1710 $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 ) ); … … 1676 1714 1677 1715 public static function delete_data_for_user( $user_id ) { 1678 global $wpdb, $bp; 1716 global $wpdb; 1717 1718 $bp = buddypress(); 1679 1719 1680 1720 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d", $user_id ) ); … … 1682 1722 1683 1723 public static function get_random( $user_id, $exclude_fullname ) { 1684 global $wpdb , $bp;1724 global $wpdb; 1685 1725 1686 1726 $exclude_sql = ! empty( $exclude_fullname ) ? ' AND pf.id != 1' : ''; 1727 1728 $bp = buddypress(); 1687 1729 1688 1730 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 ) );
Note: See TracChangeset
for help on using the changeset viewer.