/bp-xprofile/bp-xprofile-filters.php

  1. <?php 
  2. /** 
  3. * BuddyPress XProfile Filters. 
  4. * 
  5. * Apply WordPress defined filters. 
  6. * 
  7. * @package BuddyPress 
  8. * @subpackage XProfileFilters 
  9. * @since 1.0.0 
  10. */ 
  11.  
  12. // Exit if accessed directly. 
  13. defined( 'ABSPATH' ) || exit; 
  14.  
  15. add_filter( 'bp_get_the_profile_group_name', 'wp_filter_kses', 1 ); 
  16. add_filter( 'bp_get_the_profile_group_description', 'wp_filter_kses', 1 ); 
  17. add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_kses', 1 ); 
  18. add_filter( 'bp_get_the_profile_field_name', 'wp_filter_kses', 1 ); 
  19. add_filter( 'bp_get_the_profile_field_edit_value', 'wp_filter_kses', 1 ); 
  20. add_filter( 'bp_get_the_profile_field_description', 'wp_filter_kses', 1 ); 
  21.  
  22. add_filter( 'bp_get_the_profile_field_value', 'wptexturize' ); 
  23. add_filter( 'bp_get_the_profile_field_value', 'convert_chars' ); 
  24. add_filter( 'bp_get_the_profile_field_value', 'wpautop' ); 
  25. add_filter( 'bp_get_the_profile_field_value', 'force_balance_tags' ); 
  26. add_filter( 'bp_get_the_profile_field_value', 'make_clickable' ); 
  27. add_filter( 'bp_get_the_profile_field_value', 'bp_xprofile_escape_field_data', 8, 3 ); 
  28. add_filter( 'bp_get_the_profile_field_value', 'convert_smilies', 9 ); 
  29. add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 ); 
  30. add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value_by_type', 8, 3 ); 
  31. add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 3 ); 
  32.  
  33. add_filter( 'bp_get_the_profile_field_edit_value', 'force_balance_tags' ); 
  34. add_filter( 'bp_get_the_profile_field_edit_value', 'bp_xprofile_escape_field_data', 10, 3 ); 
  35.  
  36. add_filter( 'bp_get_the_profile_group_name', 'stripslashes' ); 
  37. add_filter( 'bp_get_the_profile_group_description', 'stripslashes' ); 
  38. add_filter( 'bp_get_the_profile_field_value', 'stripslashes' ); 
  39. add_filter( 'bp_get_the_profile_field_edit_value', 'stripslashes' ); 
  40. add_filter( 'bp_get_the_profile_field_name', 'stripslashes' ); 
  41. add_filter( 'bp_get_the_profile_field_description', 'stripslashes' ); 
  42.  
  43. add_filter( 'xprofile_get_field_data', 'xprofile_filter_kses', 1 ); 
  44. add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 ); 
  45. add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 ); 
  46.  
  47. add_filter( 'xprofile_get_field_data', 'force_balance_tags' ); 
  48. add_filter( 'xprofile_field_name_before_save', 'force_balance_tags' ); 
  49. add_filter( 'xprofile_field_description_before_save', 'force_balance_tags' ); 
  50.  
  51. add_filter( 'xprofile_get_field_data', 'stripslashes' ); 
  52. add_filter( 'xprofile_get_field_data', 'xprofile_filter_format_field_value_by_field_id', 5, 2 ); 
  53.  
  54. add_filter( 'bp_xprofile_set_field_data_pre_validate', 'xprofile_filter_pre_validate_value_by_field_type', 10, 3 ); 
  55. add_filter( 'xprofile_data_value_before_save', 'xprofile_sanitize_data_value_before_save', 1, 4 ); 
  56. add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 ); 
  57.  
  58. // Save field groups. 
  59. add_filter( 'xprofile_group_name_before_save', 'wp_filter_kses' ); 
  60. add_filter( 'xprofile_group_description_before_save', 'wp_filter_kses' ); 
  61.  
  62. add_filter( 'xprofile_group_name_before_save', 'stripslashes' ); 
  63. add_filter( 'xprofile_group_description_before_save', 'stripslashes' ); 
  64.  
  65. // Save fields. 
  66. add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses' ); 
  67. add_filter( 'xprofile_field_type_before_save', 'wp_filter_kses' ); 
  68. add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses' ); 
  69. add_filter( 'xprofile_field_order_by_before_save', 'wp_filter_kses' ); 
  70.  
  71. add_filter( 'xprofile_field_is_required_before_save', 'absint' ); 
  72. add_filter( 'xprofile_field_field_order_before_save', 'absint' ); 
  73. add_filter( 'xprofile_field_option_order_before_save', 'absint' ); 
  74. add_filter( 'xprofile_field_can_delete_before_save', 'absint' ); 
  75.  
  76. // Save field options. 
  77. add_filter( 'xprofile_field_options_before_save', 'bp_xprofile_sanitize_field_options' ); 
  78. add_filter( 'xprofile_field_default_before_save', 'bp_xprofile_sanitize_field_default' ); 
  79.  
  80. /** 
  81. * Sanitize each field option name for saving to the database. 
  82. * 
  83. * @since 2.3.0 
  84. * 
  85. * @param mixed $field_options Options to sanitize. 
  86. * @return mixed 
  87. */ 
  88. function bp_xprofile_sanitize_field_options( $field_options = '' ) { 
  89. if ( is_array( $field_options ) ) { 
  90. return array_map( 'sanitize_text_field', $field_options ); 
  91. } else { 
  92. return sanitize_text_field( $field_options ); 
  93.  
  94. /** 
  95. * Sanitize each field option default for saving to the database. 
  96. * 
  97. * @since 2.3.0 
  98. * 
  99. * @param mixed $field_default Field defaults to sanitize. 
  100. * @return mixed 
  101. */ 
  102. function bp_xprofile_sanitize_field_default( $field_default = '' ) { 
  103. if ( is_array( $field_default ) ) { 
  104. return array_map( 'intval', $field_default ); 
  105. } else { 
  106. return intval( $field_default ); 
  107.  
  108. /** 
  109. * Run profile field values through kses with filterable allowed tags. 
  110. * 
  111. * @since 1.5.0 
  112. * 
  113. * @param string $content Content to filter. 
  114. * @param object|null $data_obj The BP_XProfile_ProfileData object. 
  115. * @return string $content 
  116. */ 
  117. function xprofile_filter_kses( $content, $data_obj = null ) { 
  118. global $allowedtags; 
  119.  
  120. $xprofile_allowedtags = $allowedtags; 
  121. $xprofile_allowedtags['a']['rel'] = array(); 
  122.  
  123. // If the field supports rich text, we must allow tags that appear in wp_editor(). 
  124. if ( $data_obj instanceof BP_XProfile_ProfileData && bp_xprofile_is_richtext_enabled_for_field( $data_obj->field_id ) ) { 
  125. $richtext_tags = array( 
  126. 'img' => array( 'id' => 1, 'class' => 1, 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ),  
  127. 'ul' => array( 'id' => 1, 'class' => 1 ),  
  128. 'ol' => array( 'id' => 1, 'class' => 1 ),  
  129. 'li' => array( 'id' => 1, 'class' => 1 ),  
  130. 'span' => array( 'style' => 1 ),  
  131. 'p' => array( 'style' => 1 ),  
  132. ); 
  133.  
  134. $xprofile_allowedtags = array_merge( $allowedtags, $richtext_tags ); 
  135.  
  136. /** 
  137. * Filters the allowed tags for use within xprofile_filter_kses(). 
  138. * 
  139. * @since 1.5.0 
  140. * 
  141. * @param array $xprofile_allowedtags Array of allowed tags for profile field values. 
  142. * @param BP_XProfile_ProfileData $data_obj The BP_XProfile_ProfileData object. 
  143. */ 
  144. $xprofile_allowedtags = apply_filters( 'xprofile_allowed_tags', $xprofile_allowedtags, $data_obj ); 
  145. return wp_kses( $content, $xprofile_allowedtags ); 
  146.  
  147. /** 
  148. * Safely runs profile field data through kses and force_balance_tags. 
  149. * 
  150. * @since 1.2.6 
  151. * 
  152. * @param string $field_value Field value being santized. 
  153. * @param int $field_id Field ID being sanitized. 
  154. * @param bool $reserialize Whether to reserialize arrays before returning. Defaults to true. 
  155. * @param object|null $data_obj The BP_XProfile_ProfileData object. 
  156. * @return string 
  157. */ 
  158. function xprofile_sanitize_data_value_before_save( $field_value, $field_id = 0, $reserialize = true, $data_obj = null ) { 
  159.  
  160. // Return if empty. 
  161. if ( empty( $field_value ) ) { 
  162. return $field_value; 
  163.  
  164. // Value might be serialized. 
  165. $field_value = maybe_unserialize( $field_value ); 
  166.  
  167. // Filter single value. 
  168. if ( !is_array( $field_value ) ) { 
  169. $kses_field_value = xprofile_filter_kses( $field_value, $data_obj ); 
  170. $filtered_field_value = wp_rel_nofollow( force_balance_tags( $kses_field_value ) ); 
  171.  
  172. /** 
  173. * Filters the kses-filtered data before saving to database. 
  174. * 
  175. * @since 1.5.0 
  176. * 
  177. * @param string $filtered_field_value The filtered value. 
  178. * @param string $field_value The original value before filtering. 
  179. * @param BP_XProfile_ProfileData $data_obj The BP_XProfile_ProfileData object. 
  180. */ 
  181. $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj ); 
  182.  
  183. // Filter each array item independently. 
  184. } else { 
  185. $filtered_values = array(); 
  186. foreach ( (array) $field_value as $value ) { 
  187. $kses_field_value = xprofile_filter_kses( $value, $data_obj ); 
  188. $filtered_value = wp_rel_nofollow( force_balance_tags( $kses_field_value ) ); 
  189.  
  190. /** This filter is documented in bp-xprofile/bp-xprofile-filters.php */ 
  191. $filtered_values[] = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_value, $value, $data_obj ); 
  192.  
  193.  
  194. if ( !empty( $reserialize ) ) { 
  195. $filtered_field_value = serialize( $filtered_values ); 
  196. } else { 
  197. $filtered_field_value = $filtered_values; 
  198.  
  199. return $filtered_field_value; 
  200.  
  201. /** 
  202. * Runs stripslashes on XProfile fields. 
  203. * 
  204. * @since 1.0.0 
  205. * 
  206. * @param string $field_value XProfile field_value to be filtered. 
  207. * @param string $field_type XProfile field_type to be filtered. 
  208. * @return string $field_value Filtered XProfile field_value. False on failure. 
  209. */ 
  210. function xprofile_filter_format_field_value( $field_value, $field_type = '' ) { 
  211.  
  212. // Valid field values of 0 or '0' get caught by empty(), so we have an extra check for these. See #BP5731. 
  213. if ( ! isset( $field_value ) || empty( $field_value ) && ( '0' !== $field_value ) ) { 
  214. return false; 
  215.  
  216. if ( 'datebox' !== $field_type ) { 
  217. $field_value = str_replace( ']]>', ']]>', $field_value ); 
  218.  
  219. return stripslashes( $field_value ); 
  220.  
  221. /** 
  222. * Apply display_filter() filters as defined by BP_XProfile_Field_Type classes, when inside a bp_has_profile() loop. 
  223. * 
  224. * @since 2.1.0 
  225. * @since 2.4.0 Added `$field_id` parameter. 
  226. * 
  227. * @param mixed $field_value Field value. 
  228. * @param string $field_type Field type. 
  229. * @param string|int $field_id Optional. ID of the field. 
  230. * @return mixed 
  231. */ 
  232. function xprofile_filter_format_field_value_by_type( $field_value, $field_type = '', $field_id = '' ) { 
  233. foreach ( bp_xprofile_get_field_types() as $type => $class ) { 
  234. if ( $type !== $field_type ) { 
  235. continue; 
  236.  
  237. if ( method_exists( $class, 'display_filter' ) ) { 
  238. $field_value = call_user_func( array( $class, 'display_filter' ), $field_value, $field_id ); 
  239.  
  240. return $field_value; 
  241.  
  242. /** 
  243. * Apply display_filter() filters as defined by the BP_XProfile_Field_Type classes, when fetched 
  244. * by xprofile_get_field_data(). 
  245. * 
  246. * @since 2.1.0 
  247. * 
  248. * @param mixed $field_value Field value. 
  249. * @param int $field_id Field type. 
  250. * @return string 
  251. */ 
  252. function xprofile_filter_format_field_value_by_field_id( $field_value, $field_id ) { 
  253. $field = xprofile_get_field( $field_id ); 
  254. return xprofile_filter_format_field_value_by_type( $field_value, $field->type, $field_id ); 
  255.  
  256. /** 
  257. * Apply pre_validate_filter() filters as defined by the BP_XProfile_Field_Type classes before validating. 
  258. * 
  259. * @since 2.1.0 
  260. * 
  261. * @param mixed $value Value passed to the bp_xprofile_set_field_data_pre_validate filter. 
  262. * @param BP_XProfile_Field $field Field object. 
  263. * @param BP_XProfile_Field_Type $field_type_obj Field type object. 
  264. * @return mixed 
  265. */ 
  266. function xprofile_filter_pre_validate_value_by_field_type( $value, $field, $field_type_obj ) { 
  267. if ( method_exists( $field_type_obj, 'pre_validate_filter' ) ) { 
  268. $value = call_user_func( array( $field_type_obj, 'pre_validate_filter' ), $value ); 
  269.  
  270. return $value; 
  271.  
  272. /** 
  273. * Escape field value for display. 
  274. * 
  275. * Most field values are simply run through esc_html(). Those that support rich text (by default, `textarea` only) 
  276. * are sanitized using kses, which allows a whitelist of HTML tags. 
  277. * 
  278. * @since 2.4.0 
  279. * 
  280. * @param string $value Field value. 
  281. * @param string $field_type Field type. 
  282. * @param int $field_id Field ID. 
  283. * @return string 
  284. */ 
  285. function bp_xprofile_escape_field_data( $value, $field_type, $field_id ) { 
  286. if ( bp_xprofile_is_richtext_enabled_for_field( $field_id ) ) { 
  287. // The xprofile_filter_kses() expects a BP_XProfile_ProfileData object. 
  288. $data_obj = null; 
  289. if ( bp_is_user() ) { 
  290. $data_obj = new BP_XProfile_ProfileData( $field_id, bp_displayed_user_id() ); 
  291.  
  292. $value = xprofile_filter_kses( $value, $data_obj ); 
  293. } else { 
  294. $value = esc_html( $value ); 
  295.  
  296. return $value; 
  297.  
  298. /** 
  299. * Filter an Extended Profile field value, and attempt to make clickable links 
  300. * to members search results out of them. 
  301. * 
  302. * - Not run on datebox field types. 
  303. * - Not run on values without commas with less than 5 words. 
  304. * - URL's are made clickable. 
  305. * 
  306. * To disable globally: 
  307. * remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 3 ); 
  308. * 
  309. * To disable for a single field, use the 'Autolink' settings in Dashboard > Users > Profile Fields. 
  310. * 
  311. * @since 1.1.0 
  312. * 
  313. * @param string $field_value Profile field data value. 
  314. * @param string $field_type Profile field type. 
  315. * @return string 
  316. */ 
  317. function xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) { 
  318. global $field; 
  319.  
  320. if ( ! $field->get_do_autolink() ) { 
  321. return $field_value; 
  322.  
  323. if ( 'datebox' === $field_type ) { 
  324. return $field_value; 
  325.  
  326. if ( strpos( $field_value, ', ' ) === false && strpos( $field_value, ';' ) === false && ( count( explode( ' ', $field_value ) ) > 5 ) ) { 
  327. return $field_value; 
  328.  
  329. if ( strpos( $field_value, ', ' ) !== false ) { 
  330. $list_type = 'comma'; 
  331. $values = explode( ', ', $field_value ); // Comma-separated lists. 
  332. } else { 
  333. $list_type = 'semicolon'; 
  334. $values = explode( ';', $field_value ); // Semicolon-separated lists. 
  335.  
  336. if ( ! empty( $values ) ) { 
  337. foreach ( (array) $values as $value ) { 
  338. $value = trim( $value ); 
  339.  
  340. // If the value is a URL, skip it and just make it clickable. 
  341. if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) { 
  342. $new_values[] = make_clickable( $value ); 
  343.  
  344. // Is not clickable. 
  345. } else { 
  346.  
  347. // More than 5 spaces. 
  348. if ( count( explode( ' ', $value ) ) > 5 ) { 
  349. $new_values[] = $value; 
  350.  
  351. // Less than 5 spaces. 
  352. } else { 
  353. $query_arg = bp_core_get_component_search_query_arg( 'members' ); 
  354. $search_url = add_query_arg( array( $query_arg => urlencode( $value ) ), bp_get_members_directory_permalink() ); 
  355. $new_values[] = '<a href="' . esc_url( $search_url ) . '" rel="nofollow">' . $value . '</a>'; 
  356.  
  357. if ( 'comma' === $list_type ) { 
  358. $values = implode( ', ', $new_values ); 
  359. } else { 
  360. $values = implode( '; ', $new_values ); 
  361.  
  362. return $values; 
  363.  
  364. /** 
  365. * Ensures that BP data appears in comments array. 
  366. * 
  367. * This filter loops through the comments return by a normal WordPress request 
  368. * and swaps out user data with BP xprofile data, where available. 
  369. * 
  370. * @since 1.2.0 
  371. * 
  372. * @param array $comments Comments to filter in. 
  373. * @param int $post_id Post ID the comments are for. 
  374. * @return array $comments 
  375. */ 
  376. function xprofile_filter_comments( $comments, $post_id = 0 ) { 
  377.  
  378. // Locate comment authors with WP accounts. 
  379. foreach( (array) $comments as $comment ) { 
  380. if ( $comment->user_id ) { 
  381. $user_ids[] = $comment->user_id; 
  382.  
  383. // If none are found, just return the comments array. 
  384. if ( empty( $user_ids ) ) { 
  385. return $comments; 
  386.  
  387. // Pull up the xprofile fullname of each commenter. 
  388. if ( $fullnames = bp_core_get_user_displaynames( $user_ids ) ) { 
  389. foreach( (array) $fullnames as $user_id => $user_fullname ) { 
  390. $users[ $user_id ] = trim( stripslashes( $user_fullname ) ); 
  391.  
  392. // Loop through and match xprofile fullname with commenters. 
  393. foreach( (array) $comments as $i => $comment ) { 
  394. if ( ! empty( $comment->user_id ) ) { 
  395. if ( ! empty( $users[ $comment->user_id ] ) ) { 
  396. $comments[ $i ]->comment_author = $users[ $comment->user_id ]; 
  397.  
  398. return $comments; 
  399. add_filter( 'comments_array', 'xprofile_filter_comments', 10, 2 ); 
  400.  
  401. /** 
  402. * Filter BP_User_Query::populate_extras to override each queries users fullname. 
  403. * 
  404. * @since 1.7.0 
  405. * 
  406. * @param BP_User_Query $user_query User query to filter. 
  407. * @param string $user_ids_sql SQL statement to use. 
  408. */ 
  409. function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql = '' ) { 
  410.  
  411. if ( ! bp_is_active( 'xprofile' ) ) { 
  412. return; 
  413.  
  414. $user_id_names = bp_core_get_user_displaynames( $user_query->user_ids ); 
  415.  
  416. // Loop through names and override each user's fullname. 
  417. foreach ( $user_id_names as $user_id => $user_fullname ) { 
  418. if ( isset( $user_query->results[ $user_id ] ) ) { 
  419. $user_query->results[ $user_id ]->fullname = $user_fullname; 
  420. add_filter( 'bp_user_query_populate_extras', 'bp_xprofile_filter_user_query_populate_extras', 2, 2 ); 
  421.  
  422. /** 
  423. * Parse 'xprofile_query' argument passed to BP_User_Query. 
  424. * 
  425. * @since 2.2.0 
  426. * 
  427. * @param BP_User_Query $q User query object. 
  428. */ 
  429. function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query $q ) { 
  430.  
  431. // Bail if no `xprofile_query` clause. 
  432. if ( empty( $q->query_vars['xprofile_query'] ) ) { 
  433. return; 
  434.  
  435. $xprofile_query = new BP_XProfile_Query( $q->query_vars['xprofile_query'] ); 
  436. $sql = $xprofile_query->get_sql( 'u', $q->uid_name ); 
  437.  
  438. if ( ! empty( $sql['join'] ) ) { 
  439. $q->uid_clauses['select'] .= $sql['join']; 
  440. $q->uid_clauses['where'] .= $sql['where']; 
  441. add_action( 'bp_pre_user_query', 'bp_xprofile_add_xprofile_query_to_user_query' ); 
  442.  
  443. /** 
  444. * Filter meta queries to modify for the xprofile data schema. 
  445. * 
  446. * @since 2.0.0 
  447. * 
  448. * @access private Do not use. 
  449. * 
  450. * @param string $q SQL query. 
  451. * @return string 
  452. */ 
  453. function bp_xprofile_filter_meta_query( $q ) { 
  454. global $wpdb; 
  455.  
  456. $raw_q = $q; 
  457.  
  458. /** 
  459. * Replace quoted content with __QUOTE__ to avoid false positives. 
  460. * This regular expression will match nested quotes. 
  461. */ 
  462. $quoted_regex = "/'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'/s"; 
  463. preg_match_all( $quoted_regex, $q, $quoted_matches ); 
  464. $q = preg_replace( $quoted_regex, '__QUOTE__', $q ); 
  465.  
  466. // Get the first word of the command. 
  467. preg_match( '/^(\S+)/', $q, $first_word_matches ); 
  468.  
  469. if ( empty( $first_word_matches[0] ) ) { 
  470. return $raw_q; 
  471.  
  472. // Get the field type. 
  473. preg_match( '/xprofile_(group|field|data)_id/', $q, $matches ); 
  474.  
  475. if ( empty( $matches[0] ) || empty( $matches[1] ) ) { 
  476. return $raw_q; 
  477.  
  478. switch ( $first_word_matches[0] ) { 
  479.  
  480. /** 
  481. * SELECT: 
  482. * - replace 'xprofile_{fieldtype}_id' with 'object_id' 
  483. * - ensure that 'object_id' is aliased to 'xprofile_{fieldtype}_id',  
  484. * because update_meta_cache() needs the column name to parse 
  485. * the query results 
  486. * - append the 'object type' WHERE clause 
  487. */ 
  488. case 'SELECT' : 
  489. $q = str_replace( 
  490. array( 
  491. $matches[0],  
  492. 'SELECT object_id',  
  493. 'WHERE ',  
  494. ),  
  495. array( 
  496. 'object_id',  
  497. 'SELECT object_id AS ' . $matches[0],  
  498. $wpdb->prepare( 'WHERE object_type = %s AND ', $matches[1] ),  
  499. ),  
  500. $q 
  501. ); 
  502. break; 
  503.  
  504. /** 
  505. * UPDATE and DELETE: 
  506. * - replace 'xprofile_{fieldtype}_id' with 'object_id' 
  507. * - append the 'object type' WHERE clause 
  508. */ 
  509. case 'UPDATE' : 
  510. case 'DELETE' : 
  511. $q = str_replace( 
  512. array( 
  513. $matches[0],  
  514. 'WHERE ',  
  515. ),  
  516. array( 
  517. 'object_id',  
  518. $wpdb->prepare( 'WHERE object_type = %s AND ', $matches[1] ),  
  519. ),  
  520. $q 
  521. ); 
  522. break; 
  523.  
  524. /** 
  525. * UPDATE and DELETE: 
  526. * - replace 'xprofile_{fieldtype}_id' with 'object_id' 
  527. * - ensure that the object_type field gets filled in 
  528. */ 
  529. case 'INSERT' : 
  530. $q = str_replace( 
  531. array( 
  532. '`' . $matches[0] . '`',  
  533. 'VALUES (',  
  534. ),  
  535. array( 
  536. '`object_type`, `object_id`',  
  537. $wpdb->prepare( "VALUES (%s, ", $matches[1] ),  
  538. ),  
  539. $q 
  540. ); 
  541. break; 
  542.  
  543. // Put quoted content back into the string. 
  544. if ( ! empty( $quoted_matches[0] ) ) { 
  545. for ( $i = 0; $i < count( $quoted_matches[0] ); $i++ ) { 
  546. $quote_pos = strpos( $q, '__QUOTE__' ); 
  547. $q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 ); 
  548.  
  549. return $q; 
.