[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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 double $wp_version 27 */ 28 function bp_get_major_wp_version() { 29 global $wp_version; 30 31 return (float) $wp_version; 32 } 33 34 /* 35 * Only add MS-specific abstraction functions if WordPress is not in multisite mode. 36 */ 37 if ( !is_multisite() ) { 38 global $wpdb; 39 40 $wpdb->base_prefix = $wpdb->prefix; 41 $wpdb->blogid = BP_ROOT_BLOG; 42 43 if ( !function_exists( 'get_blog_option' ) ) { 44 45 /** 46 * Retrieve blog option. 47 * 48 * @since 1.0.0 49 * 50 * @see get_blog_option() 51 * 52 * @param int $blog_id Blog ID to fetch for. Not used. 53 * @param string $option_name Option name to fetch. 54 * @param bool $default Whether or not default. 55 * @return mixed 56 */ 57 function get_blog_option( $blog_id, $option_name, $default = false ) { 58 return get_option( $option_name, $default ); 59 } 60 } 61 62 if ( ! function_exists( 'add_blog_option' ) ) { 63 64 /** 65 * Add blog option. 66 * 67 * @since 1.2.0 68 * 69 * @see add_blog_option() 70 * 71 * @param int $blog_id Blog ID to add for. Not used. 72 * @param string $option_name Option name to add. 73 * @param mixed $option_value Option value to add. 74 * @return mixed 75 */ 76 function add_blog_option( $blog_id, $option_name, $option_value ) { 77 return add_option( $option_name, $option_value ); 78 } 79 } 80 81 if ( !function_exists( 'update_blog_option' ) ) { 82 83 /** 84 * Update blog option. 85 * 86 * @since 1.2.0 87 * 88 * @see update_blog_option() 89 * 90 * @param int $blog_id Blog ID to update for. Not used. 91 * @param string $option_name Option name to update. 92 * @param mixed $value Option value to update. 93 * @return mixed 94 */ 95 function update_blog_option( $blog_id, $option_name, $value ) { 96 return update_option( $option_name, $value ); 97 } 98 } 99 100 if ( !function_exists( 'delete_blog_option' ) ) { 101 102 /** 103 * Delete blog option. 104 * 105 * @since 1.5.0 106 * 107 * @see delete_blog_option() 108 * 109 * @param int $blog_id Blog ID to delete for. Not used. 110 * @param string $option_name Option name to delete. 111 * @return mixed 112 */ 113 function delete_blog_option( $blog_id, $option_name ) { 114 return delete_option( $option_name ); 115 } 116 } 117 118 if ( !function_exists( 'switch_to_blog' ) ) { 119 120 /** 121 * Switch to specified blog. 122 * 123 * @since 1.2.0 124 * 125 * @see switch_to_blog() 126 * 127 * @param mixed $new_blog New blog to switch to. Not used. 128 * @param null $deprecated Whether or not deprecated. Not used. 129 * @return int 130 */ 131 function switch_to_blog( $new_blog, $deprecated = null ) { 132 return bp_get_root_blog_id(); 133 } 134 } 135 136 if ( !function_exists( 'restore_current_blog' ) ) { 137 138 /** 139 * Restore current blog. 140 * 141 * @since 1.2.0 142 * 143 * @see restore_current_blog() 144 * 145 * @return int 146 */ 147 function restore_current_blog() { 148 return bp_get_root_blog_id(); 149 } 150 } 151 152 if ( !function_exists( 'get_blogs_of_user' ) ) { 153 154 /** 155 * Retrive blogs associated with user. 156 * 157 * @since 1.2.0 158 * 159 * @see get_blogs_of_user() 160 * 161 * @param int $user_id ID of the user. Not used. 162 * @param bool $all Whether or not to return all. Not used. 163 * @return bool 164 */ 165 function get_blogs_of_user( $user_id, $all = false ) { 166 return false; 167 } 168 } 169 170 if ( !function_exists( 'update_blog_status' ) ) { 171 172 /** 173 * Whether or not to update blog status. 174 * 175 * @since 1.2.0 176 * 177 * @see update_blog_status() 178 * 179 * @param int $blog_id Blog to update status for. Not used. 180 * @param mixed $pref Preference. Not used. 181 * @param string $value Value. Not used. 182 * @param null $deprecated Whether or not deprecated. Not used. 183 * @return bool 184 */ 185 function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { 186 return true; 187 } 188 } 189 190 if ( !function_exists( 'is_subdomain_install' ) ) { 191 192 /** 193 * Whether or not if subdomain install. 194 * 195 * @since 1.2.5.1 196 * 197 * @see is_subdomain_install() 198 * 199 * @return bool 200 */ 201 function is_subdomain_install() { 202 if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) ) 203 return true; 204 205 return false; 206 } 207 } 208 } 209 210 /** 211 * Get SQL chunk for filtering spam users from member queries. 212 * 213 * @internal 214 * @todo Why is this function defined in this file? 215 * 216 * @param string|bool $prefix Global table prefix. 217 * @return string SQL chunk. 218 */ 219 function bp_core_get_status_sql( $prefix = false ) { 220 if ( !is_multisite() ) 221 return "{$prefix}user_status = 0"; 222 else 223 return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0"; 224 } 225 226 /** 227 * Multibyte encoding fallback functions. 228 * 229 * The PHP multibyte encoding extension is not enabled by default. In cases where it is not enabled, 230 * these functions provide a fallback. 231 * 232 * Borrowed from MediaWiki, under the GPLv2. Thanks! 233 */ 234 if ( !function_exists( 'mb_strlen' ) ) { 235 236 /** 237 * Fallback implementation of mb_strlen(), hardcoded to UTF-8. 238 * 239 * @param string $str String to be measured. 240 * @param string $enc Optional. Encoding type. Ignored. 241 * @return int String length. 242 */ 243 function mb_strlen( $str, $enc = '' ) { 244 $counts = count_chars( $str ); 245 $total = 0; 246 247 // Count ASCII bytes. 248 for( $i = 0; $i < 0x80; $i++ ) { 249 $total += $counts[$i]; 250 } 251 252 // Count multibyte sequence heads. 253 for( $i = 0xc0; $i < 0xff; $i++ ) { 254 $total += $counts[$i]; 255 } 256 return $total; 257 } 258 } 259 260 if ( !function_exists( 'mb_strpos' ) ) { 261 262 /** 263 * Fallback implementation of mb_strpos(), hardcoded to UTF-8. 264 * 265 * @param string $haystack String to search in. 266 * @param string $needle String to search for. 267 * @param int $offset Optional. Start position for the search. Default: 0. 268 * @param string $encoding Optional. Encoding type. Ignored. 269 * @return int|false Position of needle in haystack if found, else false. 270 */ 271 function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) { 272 $needle = preg_quote( $needle, '/' ); 273 274 $ar = array(); 275 preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); 276 277 if( isset( $ar[0][1] ) ) { 278 return $ar[0][1]; 279 } else { 280 return false; 281 } 282 } 283 } 284 285 if ( !function_exists( 'mb_strrpos' ) ) { 286 287 /** 288 * Fallback implementation of mb_strrpos(), hardcoded to UTF-8. 289 * 290 * @param string $haystack String to search in. 291 * @param string $needle String to search for. 292 * @param int $offset Optional. Start position for the search. Default: 0. 293 * @param string $encoding Optional. Encoding type. Ignored. 294 * @return string|false Position of last needle in haystack if found, else false. 295 */ 296 function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) { 297 $needle = preg_quote( $needle, '/' ); 298 299 $ar = array(); 300 preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); 301 302 if( isset( $ar[0] ) && count( $ar[0] ) > 0 && 303 isset( $ar[0][count( $ar[0] ) - 1][1] ) ) { 304 return $ar[0][count( $ar[0] ) - 1][1]; 305 } else { 306 return false; 307 } 308 } 309 } 310 311 /** 312 * Catch the new site data for a later use. 313 * 314 * @since 6.0.0 315 */ 316 function bp_catch_site_data( $errors = null, $data = array() ) { 317 buddypress()->new_site_data = $data; 318 } 319 add_action( 'wp_validate_site_data', 'bp_catch_site_data', 10, 2 ); 320 321 /** 322 * Fires a BuddyPress hook when a new WordPress site is inserted into the database. 323 * 324 * This hook makes sure BuddyPress is back compatible with WordPress versions < 5.1.0. 325 * 326 * @since 6.0.0 327 * 328 * @param int|WP_Site $site The Site ID or the WP Site object. 329 * @param int|array $args_or_user_id An array of Site arguments or the User ID. 330 * @param string $domain Site domain. 331 * @param string $path Site path. 332 * @param int $network_id Network ID. Only relevant on multi-network installations. 333 * @param array $meta Meta data. Used to set initial site options. 334 */ 335 function bp_insert_site( $site, $args_or_user_id = null, $domain = '', $path = '', $network_id = 0, $meta = array() ) { 336 if ( $site instanceof WP_Site ) { 337 $bp = buddypress(); 338 $site_id = $site->id; 339 $domain = $site->domain; 340 $path = $site->path; 341 $network_id = $site->network_id; 342 $args = (array) $args_or_user_id; 343 344 $user_id = 0; 345 if ( isset( $args['user_id'] ) && $args['user_id'] ) { 346 $user_id = (int) $args['user_id']; 347 } 348 349 $meta = array(); 350 if ( isset( $args['options'] ) && $args['options'] ) { 351 $meta = (array) $args['options']; 352 353 if ( ! array_key_exists( 'WPLANG', $meta ) ) { 354 $meta['WPLANG'] = get_network_option( $site->network_id, 'WPLANG' ); 355 } 356 357 if ( isset( $bp->new_site_data ) ) { 358 $meta = array_merge( $bp->new_site_data, $meta ); 359 } 360 } 361 } else { 362 $site_id = $site; 363 $user_id = (int) $args_or_user_id; 364 } 365 366 /** 367 * Fires when a new WordPress site has been inserted into the database. 368 * 369 * @since 6.0.0 370 * 371 * @param int $site_id Site ID. 372 * @param int $user_id User ID. 373 * @param string $domain Site domain. 374 * @param string $path Site path. 375 * @param int $network_id Network ID. Only relevant on multi-network installations. 376 * @param array $meta Meta data. Used to set initial site options. 377 */ 378 do_action( 'bp_insert_site', $site_id, $user_id, $domain, $path, $network_id, $meta ); 379 } 380 add_action( 'wp_initialize_site', 'bp_insert_site' ); 381 382 /** 383 * Makes sure the `bp_delete_site` hook is fired if site's deletion 384 * was performed without dropping tables. 385 * 386 * @since 6.0.0 387 * 388 * @param WP_Site $site The site object. 389 */ 390 function bp_delete_site_no_tables_drop( $site ) { 391 if ( isset( $site->deleted ) && 1 === (int) $site->deleted ) { 392 return bp_delete_site( $site->id, false ); 393 } 394 } 395 add_action( 'wp_update_site', 'bp_delete_site_no_tables_drop', 10, 1 ); 396 397 /** 398 * Fires a BuddyPress hook when a new WordPress site is deleted. 399 * 400 * This hook makes sure BuddyPress is back compatible with WordPress versions < 5.1.0. 401 * 402 * @since 6.0.0 403 * 404 * @param int|WP_Error $site_id_or_error A WP Error object or the site ID. 405 * @param bool|WP_Site $drop_or_site A WP Site object or a boolean to inform whether site's table should be dropped. 406 */ 407 function bp_delete_site( $site_id_or_error, $drop_or_site = false ) { 408 if ( $drop_or_site instanceof WP_Site ) { 409 if ( ! empty( $site_id_or_error->errors ) ) { 410 return; 411 } 412 413 $site_id = (int) $drop_or_site->id; 414 $drop = true; 415 } else { 416 $site_id = (int) $site_id_or_error; 417 $drop = (bool) $drop_or_site; 418 } 419 420 /** 421 * Fires when a WordPress site is deleted. 422 * 423 * @since 6.0.0 424 * 425 * @param int $site_id The site ID. 426 * @param bool $drop True if site's table should be dropped. Default is false. 427 */ 428 do_action( 'bp_delete_site', $site_id, $drop ); 429 } 430 add_action( 'wp_validate_site_deletion', 'bp_delete_site', 10, 2 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |