[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/ -> bp-core-wpabstraction.php (source)

   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  }


Generated: Sat Sep 21 01:01:46 2019 Cross-referenced by PHPXref 0.7.1