/bp-core/bp-core-wpabstraction.php

  1. <?php 
  2. /** 
  3. * WordPress Abstraction. 
  4. * 
  5. * The functions within this file will detect the version of WordPress you are 
  6. * running and will alter the environment so BuddyPress can run regardless. 
  7. * 
  8. * The code below mostly contains function mappings. This file is subject to 
  9. * change at any time. 
  10. * 
  11. * @package BuddyPress 
  12. * @subpackage WPAbstraction 
  13. * @since 1.2.0 
  14. */ 
  15.  
  16. // Exit if accessed directly. 
  17. defined( 'ABSPATH' ) || exit; 
  18.  
  19. /** 
  20. * Parse the WordPress core version number into the major release. 
  21. * 
  22. * @since 1.5.2 
  23. * 
  24. * @global string $wp_version 
  25. * 
  26. * @return string $wp_version 
  27. */ 
  28. function bp_get_major_wp_version() { 
  29. global $wp_version; 
  30.  
  31. return (float) $wp_version; 
  32.  
  33. /** 
  34. * Only add MS-specific abstraction functions if WordPress is not in multisite mode. 
  35. */ 
  36. if ( !is_multisite() ) { 
  37. global $wpdb; 
  38.  
  39. $wpdb->base_prefix = $wpdb->prefix; 
  40. $wpdb->blogid = BP_ROOT_BLOG; 
  41.  
  42. if ( !function_exists( 'get_blog_option' ) ) { 
  43.  
  44. /** 
  45. * Retrieve blog option. 
  46. * 
  47. * @since 1.0.0 
  48. * 
  49. * @see get_blog_option() 
  50. * 
  51. * @param int $blog_id Blog ID to fetch for. Not used. 
  52. * @param string $option_name Option name to fetch. 
  53. * @param bool $default Whether or not default. 
  54. * @return mixed 
  55. */ 
  56. function get_blog_option( $blog_id, $option_name, $default = false ) { 
  57. return get_option( $option_name, $default ); 
  58.  
  59. if ( ! function_exists( 'add_blog_option' ) ) { 
  60.  
  61. /** 
  62. * Add blog option. 
  63. * 
  64. * @since 1.2.0 
  65. * 
  66. * @see add_blog_option() 
  67. * 
  68. * @param int $blog_id Blog ID to add for. Not used. 
  69. * @param string $option_name Option name to add. 
  70. * @param mixed $option_value Option value to add. 
  71. * @return mixed 
  72. */ 
  73. function add_blog_option( $blog_id, $option_name, $option_value ) { 
  74. return add_option( $option_name, $option_value ); 
  75.  
  76. if ( !function_exists( 'update_blog_option' ) ) { 
  77.  
  78. /** 
  79. * Update blog option. 
  80. * 
  81. * @since 1.2.0 
  82. * 
  83. * @see update_blog_option() 
  84. * 
  85. * @param int $blog_id Blog ID to update for. Not used. 
  86. * @param string $option_name Option name to update. 
  87. * @param mixed $value Option value to update. 
  88. * @return mixed 
  89. */ 
  90. function update_blog_option( $blog_id, $option_name, $value ) { 
  91. return update_option( $option_name, $value ); 
  92.  
  93. if ( !function_exists( 'delete_blog_option' ) ) { 
  94.  
  95. /** 
  96. * Delete blog option. 
  97. * 
  98. * @since 1.5.0 
  99. * 
  100. * @see delete_blog_option() 
  101. * 
  102. * @param int $blog_id Blog ID to delete for. Not used. 
  103. * @param string $option_name Option name to delete. 
  104. * @return mixed 
  105. */ 
  106. function delete_blog_option( $blog_id, $option_name ) { 
  107. return delete_option( $option_name ); 
  108.  
  109. if ( !function_exists( 'switch_to_blog' ) ) { 
  110.  
  111. /** 
  112. * Switch to specified blog. 
  113. * 
  114. * @since 1.2.0 
  115. * 
  116. * @see switch_to_blog() 
  117. * 
  118. * @param mixed $new_blog New blog to switch to. Not used. 
  119. * @param null $deprecated Whether or not deprecated. Not used. 
  120. * @return int 
  121. */ 
  122. function switch_to_blog( $new_blog, $deprecated = null ) { 
  123. return bp_get_root_blog_id(); 
  124.  
  125. if ( !function_exists( 'restore_current_blog' ) ) { 
  126.  
  127. /** 
  128. * Restore current blog. 
  129. * 
  130. * @since 1.2.0 
  131. * 
  132. * @see restore_current_blog() 
  133. * 
  134. * @return int 
  135. */ 
  136. function restore_current_blog() { 
  137. return bp_get_root_blog_id(); 
  138.  
  139. if ( !function_exists( 'get_blogs_of_user' ) ) { 
  140.  
  141. /** 
  142. * Retrive blogs associated with user. 
  143. * 
  144. * @since 1.2.0 
  145. * 
  146. * @see get_blogs_of_user() 
  147. * 
  148. * @param int $user_id ID of the user. Not used. 
  149. * @param bool $all Whether or not to return all. Not used. 
  150. * @return false 
  151. */ 
  152. function get_blogs_of_user( $user_id, $all = false ) { 
  153. return false; 
  154.  
  155. if ( !function_exists( 'update_blog_status' ) ) { 
  156.  
  157. /** 
  158. * Whether or not to update blog status. 
  159. * 
  160. * @since 1.2.0 
  161. * 
  162. * @see update_blog_status() 
  163. * 
  164. * @param int $blog_id Blog to update status for. Not used. 
  165. * @param mixed $pref Preference. Not used. 
  166. * @param string $value Value. Not used. 
  167. * @param null $deprecated Whether or not deprecated. Not used. 
  168. * @return true 
  169. */ 
  170. function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { 
  171. return true; 
  172.  
  173. if ( !function_exists( 'is_subdomain_install' ) ) { 
  174.  
  175. /** 
  176. * Whether or not if subdomain install. 
  177. * 
  178. * @since 1.2.5.1 
  179. * 
  180. * @see is_subdomain_install() 
  181. * 
  182. * @return bool 
  183. */ 
  184. function is_subdomain_install() { 
  185. if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) ) 
  186. return true; 
  187.  
  188. return false; 
  189.  
  190. /** 
  191. * Get SQL chunk for filtering spam users from member queries. 
  192. * 
  193. * @internal 
  194. * @todo Why is this function defined in this file? 
  195. * 
  196. * @param string|bool $prefix Global table prefix. 
  197. * @return string SQL chunk. 
  198. */ 
  199. function bp_core_get_status_sql( $prefix = false ) { 
  200. if ( !is_multisite() ) 
  201. return "{$prefix}user_status = 0"; 
  202. else 
  203. return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0"; 
  204.  
  205. /** 
  206. * Multibyte encoding fallback functions. 
  207. * 
  208. * The PHP multibyte encoding extension is not enabled by default. In cases where it is not enabled,  
  209. * these functions provide a fallback. 
  210. * 
  211. * Borrowed from MediaWiki, under the GPLv2. Thanks! 
  212. */ 
  213. if ( !function_exists( 'mb_strlen' ) ) { 
  214.  
  215. /** 
  216. * Fallback implementation of mb_strlen(), hardcoded to UTF-8. 
  217. * 
  218. * @param string $str String to be measured. 
  219. * @param string $enc Optional. Encoding type. Ignored. 
  220. * @return int String length. 
  221. */ 
  222. function mb_strlen( $str, $enc = '' ) { 
  223. $counts = count_chars( $str ); 
  224. $total = 0; 
  225.  
  226. // Count ASCII bytes. 
  227. for( $i = 0; $i < 0x80; $i++ ) { 
  228. $total += $counts[$i]; 
  229.  
  230. // Count multibyte sequence heads. 
  231. for( $i = 0xc0; $i < 0xff; $i++ ) { 
  232. $total += $counts[$i]; 
  233. return $total; 
  234.  
  235. if ( !function_exists( 'mb_strpos' ) ) { 
  236.  
  237. /** 
  238. * Fallback implementation of mb_strpos(), hardcoded to UTF-8. 
  239. * 
  240. * @param string $haystack String to search in. 
  241. * @param string $needle String to search for. 
  242. * @param int $offset Optional. Start position for the search. Default: 0. 
  243. * @param string $encoding Optional. Encoding type. Ignored. 
  244. * @return int|bool Position of needle in haystack if found, else false. 
  245. */ 
  246. function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) { 
  247. $needle = preg_quote( $needle, '/' ); 
  248.  
  249. $ar = array(); 
  250. preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); 
  251.  
  252. if( isset( $ar[0][1] ) ) { 
  253. return $ar[0][1]; 
  254. } else { 
  255. return false; 
  256.  
  257. if ( !function_exists( 'mb_strrpos' ) ) { 
  258.  
  259. /** 
  260. * Fallback implementation of mb_strrpos(), hardcoded to UTF-8. 
  261. * 
  262. * @param string $haystack String to search in. 
  263. * @param string $needle String to search for. 
  264. * @param int $offset Optional. Start position for the search. Default: 0. 
  265. * @param string $encoding Optional. Encoding type. Ignored. 
  266. * @return int Position of last needle in haystack if found, else false. 
  267. */ 
  268. function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) { 
  269. $needle = preg_quote( $needle, '/' ); 
  270.  
  271. $ar = array(); 
  272. preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); 
  273.  
  274. if( isset( $ar[0] ) && count( $ar[0] ) > 0 && 
  275. isset( $ar[0][count( $ar[0] ) - 1][1] ) ) { 
  276. return $ar[0][count( $ar[0] ) - 1][1]; 
  277. } else { 
  278. return false; 
.