[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-includes/ -> ms-blogs.php (source)

   1  <?php
   2  
   3  /**
   4   * Site/blog functions that work with the blogs table and related data.
   5   *
   6   * @package WordPress
   7   * @subpackage Multisite
   8   * @since MU
   9   */
  10  
  11  /**
  12   * Update the last_updated field for the current blog.
  13   *
  14   * @since MU
  15   */
  16  function wpmu_update_blogs_date() {
  17      global $wpdb;
  18  
  19      // TODO: use update_blog_details
  20  
  21      $wpdb->update( $wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $wpdb->blogid) );
  22      refresh_blog_details( $wpdb->blogid );
  23  
  24      do_action( 'wpmu_blog_updated', $wpdb->blogid );
  25  }
  26  
  27  /**
  28   * Get a full blog URL, given a blog id.
  29   *
  30   * @since MU
  31   *
  32   * @param int $blog_id Blog ID
  33   * @return string
  34   */
  35  function get_blogaddress_by_id( $blog_id ) {
  36      $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
  37      return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
  38  }
  39  
  40  /**
  41   * Get a full blog URL, given a blog name.
  42   *
  43   * @since MU
  44   *
  45   * @param string $blogname The (subdomain or directory) name
  46   * @return string
  47   */
  48  function get_blogaddress_by_name( $blogname ) {
  49      global $current_site;
  50  
  51      if ( is_subdomain_install() ) {
  52          if ( $blogname == 'main' )
  53              $blogname = 'www';
  54          $url = rtrim( network_home_url(), '/' );
  55          if ( !empty( $blogname ) )
  56              $url = preg_replace( '|^([^\.]+://)|', '$1' . $blogname . '.', $url );
  57      } else {
  58          $url = network_home_url( $blogname );
  59      }
  60      return esc_url( $url . '/' );
  61  }
  62  
  63  /**
  64   * Get a full blog URL, given a domain and a path.
  65   *
  66   * @since MU
  67   *
  68   * @param string $domain
  69   * @param string $path
  70   * @return string
  71   */
  72  function get_blogaddress_by_domain( $domain, $path ) {
  73      if ( is_subdomain_install() ) {
  74          $url = "http://" . $domain.$path;
  75      } else {
  76          if ( $domain != $_SERVER['HTTP_HOST'] ) {
  77              $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
  78              $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
  79              // we're not installing the main blog
  80              if ( $blogname != 'www.' )
  81                  $url .= $blogname . '/';
  82          } else { // main blog
  83              $url = 'http://' . $domain . $path;
  84          }
  85      }
  86      return esc_url( $url );
  87  }
  88  
  89  /**
  90   * Given a blog's (subdomain or directory) name, retrieve it's id.
  91   *
  92   * @since MU
  93   *
  94   * @param string $name
  95   * @return int A blog id
  96   */
  97  function get_id_from_blogname( $name ) {
  98      global $wpdb, $current_site;
  99      $blog_id = wp_cache_get( 'get_id_from_blogname_' . $name, 'blog-details' );
 100      if ( $blog_id )
 101          return $blog_id;
 102  
 103      if ( is_subdomain_install() ) {
 104          $domain = $name . '.' . $current_site->domain;
 105          $path = $current_site->path;
 106      } else {
 107          $domain = $current_site->domain;
 108          $path = $current_site->path . $name . '/';
 109      }
 110      $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) );
 111      wp_cache_set( 'get_id_from_blogname_' . $name, $blog_id, 'blog-details' );
 112      return $blog_id;
 113  }
 114  
 115  /**
 116   * Retrieve the details for a blog from the blogs table and blog options.
 117   *
 118   * @since MU
 119   *
 120   * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
 121   * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
 122   * @return object Blog details.
 123   */
 124  function get_blog_details( $fields, $get_all = true ) {
 125      global $wpdb;
 126  
 127      if ( is_array($fields ) ) {
 128          if ( isset($fields['blog_id']) ) {
 129              $blog_id = $fields['blog_id'];
 130          } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
 131              $key = md5( $fields['domain'] . $fields['path'] );
 132              $blog = wp_cache_get($key, 'blog-lookup');
 133              if ( false !== $blog )
 134                  return $blog;
 135              if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
 136                  $nowww = substr( $fields['domain'], 4 );
 137                  $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
 138              } else {
 139                  $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
 140              }
 141              if ( $blog ) {
 142                  wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
 143                  $blog_id = $blog->blog_id;
 144              } else {
 145                  return false;
 146              }
 147          } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
 148              $key = md5( $fields['domain'] );
 149              $blog = wp_cache_get($key, 'blog-lookup');
 150              if ( false !== $blog )
 151                  return $blog;
 152              if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
 153                  $nowww = substr( $fields['domain'], 4 );
 154                  $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
 155              } else {
 156                  $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
 157              }
 158              if ( $blog ) {
 159                  wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
 160                  $blog_id = $blog->blog_id;
 161              } else {
 162                  return false;
 163              }
 164          } else {
 165              return false;
 166          }
 167      } else {
 168          if ( !is_numeric( $fields ) )
 169              $blog_id = get_id_from_blogname( $fields );
 170          else
 171              $blog_id = $fields;
 172      }
 173  
 174      $blog_id = (int) $blog_id;
 175  
 176      $all = $get_all == true ? '' : 'short';
 177      $details = wp_cache_get( $blog_id . $all, 'blog-details' );
 178  
 179      if ( $details ) {
 180          if ( ! is_object( $details ) ) {
 181              if ( $details == -1 ) {
 182                  return false;
 183              } else {
 184                  // Clear old pre-serialized objects. Cache clients do better with that.
 185                  wp_cache_delete( $blog_id . $all, 'blog-details' );
 186                  unset($details);
 187              }
 188          } else {
 189              return $details;
 190          }
 191      }
 192  
 193      // Try the other cache.
 194      if ( $get_all ) {
 195          $details = wp_cache_get( $blog_id . 'short', 'blog-details' );
 196      } else {
 197          $details = wp_cache_get( $blog_id, 'blog-details' );
 198          // If short was requested and full cache is set, we can return.
 199          if ( $details ) {
 200              if ( ! is_object( $details ) ) {
 201                  if ( $details == -1 ) {
 202                      return false;
 203                  } else {
 204                      // Clear old pre-serialized objects. Cache clients do better with that.
 205                      wp_cache_delete( $blog_id, 'blog-details' );
 206                      unset($details);
 207                  }
 208              } else {
 209                  return $details;
 210              }
 211          }
 212      }
 213  
 214      if ( empty($details) ) {
 215          $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );
 216          if ( ! $details ) {
 217              // Set the full cache.
 218              wp_cache_set( $blog_id, -1, 'blog-details' );
 219              return false;
 220          }
 221      }
 222  
 223      if ( ! $get_all ) {
 224          wp_cache_set( $blog_id . $all, $details, 'blog-details' );
 225          return $details;
 226      }
 227  
 228      $details->blogname        = get_blog_option( $blog_id, 'blogname' );
 229      $details->siteurl        = get_blog_option( $blog_id, 'siteurl' );
 230      $details->post_count    = get_blog_option( $blog_id, 'post_count' );
 231  
 232      $details = apply_filters( 'blog_details', $details );
 233  
 234      wp_cache_set( $blog_id . $all, $details, 'blog-details' );
 235  
 236      $key = md5( $details->domain . $details->path );
 237      wp_cache_set( $key, $details, 'blog-lookup' );
 238  
 239      return $details;
 240  }
 241  
 242  /**
 243   * Clear the blog details cache.
 244   *
 245   * @since MU
 246   *
 247   * @param int $blog_id Blog ID
 248   */
 249  function refresh_blog_details( $blog_id ) {
 250      $blog_id = (int) $blog_id;
 251      $details = get_blog_details( $blog_id, false );
 252  
 253      wp_cache_delete( $blog_id , 'blog-details' );
 254      wp_cache_delete( $blog_id . 'short' , 'blog-details' );
 255      wp_cache_delete( md5( $details->domain . $details->path )  , 'blog-lookup' );
 256      wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
 257      wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
 258  }
 259  
 260  /**
 261   * Update the details for a blog. Updates the blogs table for a given blog id.
 262   *
 263   * @since MU
 264   *
 265   * @param int $blog_id Blog ID
 266   * @param array $details Array of details keyed by blogs table field names.
 267   * @return bool True if update succeeds, false otherwise.
 268   */
 269  function update_blog_details( $blog_id, $details = array() ) {
 270      global $wpdb;
 271  
 272      if ( empty($details) )
 273          return false;
 274  
 275      if ( is_object($details) )
 276          $details = get_object_vars($details);
 277  
 278      $current_details = get_blog_details($blog_id, false);
 279      if ( empty($current_details) )
 280          return false;
 281  
 282      $current_details = get_object_vars($current_details);
 283  
 284      $details = array_merge($current_details, $details);
 285      $details['last_updated'] = current_time('mysql', true);
 286  
 287      $update_details = array();
 288      $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
 289      foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
 290          $update_details[$field] = $details[$field];
 291  
 292      $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
 293  
 294      // If spam status changed, issue actions.
 295      if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) {
 296          if ( $details[ 'spam' ] == 1 )
 297              do_action( "make_spam_blog", $blog_id );
 298          else
 299              do_action( "make_ham_blog", $blog_id );
 300      }
 301  
 302      if ( isset($details[ 'public' ]) )
 303          update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
 304  
 305      refresh_blog_details($blog_id);
 306  
 307      return true;
 308  }
 309  
 310  /**
 311   * Retrieve option value based on setting name and blog_id.
 312   *
 313   * If the option does not exist or does not have a value, then the return value
 314   * will be false. This is useful to check whether you need to install an option
 315   * and is commonly used during installation of plugin options and to test
 316   * whether upgrading is required.
 317   *
 318   * There is a filter called 'blog_option_$option' with the $option being
 319   * replaced with the option name. The filter takes two parameters. $value and
 320   * $blog_id. It returns $value.
 321   * The 'option_$option' filter in get_option() is not called.
 322   *
 323   * @since MU
 324   * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
 325   *
 326   * @param int $blog_id is the id of the blog.
 327   * @param string $setting Name of option to retrieve. Should already be SQL-escaped.
 328   * @param string $default (optional) Default value returned if option not found.
 329   * @return mixed Value set for the option.
 330   */
 331  function get_blog_option( $blog_id, $setting, $default = false ) {
 332      global $wpdb;
 333  
 334      $key = $blog_id . '-' . $setting . '-blog_option';
 335      $value = wp_cache_get( $key, 'site-options' );
 336      if ( $value == null ) {
 337          if ( $blog_id == $wpdb->blogid ) {
 338              $value = get_option( $setting, $default );
 339              $notoptions = wp_cache_get( 'notoptions', 'options' );
 340              if ( isset( $notoptions[$setting] ) ) {
 341                  wp_cache_set( $key, 'noop', 'site-options' );
 342                  $value = $default;
 343              } elseif ( $value == false ) {
 344                  wp_cache_set( $key, 'falsevalue', 'site-options' );
 345              } else {
 346                  wp_cache_set( $key, $value, 'site-options' );
 347              }
 348              return apply_filters( 'blog_option_' . $setting, $value, $blog_id );
 349          } else {
 350              $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
 351              $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting ) );
 352              if ( is_object( $row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
 353                  $value = $row->option_value;
 354                  if ( $value == false )
 355                      wp_cache_set( $key, 'falsevalue', 'site-options' );
 356                  else
 357                      wp_cache_set( $key, $value, 'site-options' );
 358              } else { // option does not exist, so we must cache its non-existence
 359                  wp_cache_set( $key, 'noop', 'site-options' );
 360                  $value = $default;
 361              }
 362          }
 363      } elseif ( $value == 'noop' ) {
 364          $value = $default;
 365      } elseif ( $value == 'falsevalue' ) {
 366          $value = false;
 367      }
 368      // If home is not set use siteurl.
 369      if ( 'home' == $setting && '' == $value )
 370          return get_blog_option( $blog_id, 'siteurl' );
 371  
 372      if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
 373          $value = untrailingslashit( $value );
 374  
 375      return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id );
 376  }
 377  
 378  /**
 379   * Add an option for a particular blog.
 380   *
 381   * @since MU
 382   *
 383   * @param int $id The blog id
 384   * @param string $key The option key
 385   * @param mixed $value The option value
 386   */
 387  function add_blog_option( $id, $key, $value ) {
 388      $id = (int) $id;
 389  
 390      switch_to_blog($id);
 391      add_option( $key, $value );
 392      restore_current_blog();
 393      wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' );
 394  }
 395  
 396  /**
 397   * Delete an option for a particular blog.
 398   *
 399   * @since MU
 400   *
 401   * @param int $id The blog id
 402   * @param string $key The option key
 403   */
 404  function delete_blog_option( $id, $key ) {
 405      $id = (int) $id;
 406  
 407      switch_to_blog($id);
 408      delete_option( $key );
 409      restore_current_blog();
 410      wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' );
 411  }
 412  
 413  /**
 414   * Update an option for a particular blog.
 415   *
 416   * @since MU
 417   *
 418   * @param int $id The blog id
 419   * @param string $key The option key
 420   * @param mixed $value The option value
 421   */
 422  function update_blog_option( $id, $key, $value, $deprecated = null ) {
 423      $id = (int) $id;
 424  
 425      if ( null !== $deprecated  )
 426          _deprecated_argument( __FUNCTION__, '3.1' );
 427  
 428      switch_to_blog($id);
 429      update_option( $key, $value );
 430      restore_current_blog();
 431  
 432      refresh_blog_details( $id );
 433  
 434      wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');
 435  }
 436  
 437  /**
 438   * Switch the current blog.
 439   *
 440   * This function is useful if you need to pull posts, or other information,
 441   * from other blogs. You can switch back afterwards using restore_current_blog().
 442   *
 443   * Things that aren't switched:
 444   *  - autoloaded options. See #14992
 445   *  - plugins. See #14941
 446   *
 447   * @see restore_current_blog()
 448   * @since MU
 449   *
 450   * @param int $new_blog The id of the blog you want to switch to. Default: current blog
 451   * @param bool $validate Whether to check if $new_blog exists before proceeding
 452   * @return bool    True on success, False if the validation failed
 453   */
 454  function switch_to_blog( $new_blog, $validate = false ) {
 455      global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
 456  
 457      if ( empty($new_blog) )
 458          $new_blog = $blog_id;
 459  
 460      if ( $validate && ! get_blog_details( $new_blog ) )
 461          return false;
 462  
 463      if ( empty($switched_stack) )
 464          $switched_stack = array();
 465  
 466      $switched_stack[] = $blog_id;
 467  
 468      /* If we're switching to the same blog id that we're on,
 469      * set the right vars, do the associated actions, but skip
 470      * the extra unnecessary work */
 471      if ( $blog_id == $new_blog ) {
 472          do_action( 'switch_blog', $blog_id, $blog_id );
 473          $switched = true;
 474          return true;
 475      }
 476  
 477      $wpdb->set_blog_id($new_blog);
 478      $table_prefix = $wpdb->prefix;
 479      $prev_blog_id = $blog_id;
 480      $blog_id = $new_blog;
 481  
 482      if ( is_object( $wp_roles ) ) {
 483          $wpdb->suppress_errors();
 484          if ( method_exists( $wp_roles ,'_init' ) )
 485              $wp_roles->_init();
 486          elseif ( method_exists( $wp_roles, '__construct' ) )
 487              $wp_roles->__construct();
 488          $wpdb->suppress_errors( false );
 489      }
 490  
 491      if ( did_action('init') ) {
 492          $current_user = wp_get_current_user();
 493          if ( is_object( $current_user ) )
 494              $current_user->for_blog( $blog_id );
 495      }
 496  
 497      if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
 498          $global_groups = $wp_object_cache->global_groups;
 499      else
 500          $global_groups = false;
 501  
 502      wp_cache_init();
 503      if ( function_exists('wp_cache_add_global_groups') ) {
 504          if ( is_array( $global_groups ) )
 505              wp_cache_add_global_groups( $global_groups );
 506          else
 507              wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
 508          wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
 509      }
 510  
 511      do_action('switch_blog', $blog_id, $prev_blog_id);
 512      $switched = true;
 513      return true;
 514  }
 515  
 516  /**
 517   * Restore the current blog, after calling switch_to_blog()
 518   *
 519   * @see switch_to_blog()
 520   * @since MU
 521   *
 522   * @return bool True on success, False if we're already on the current blog
 523   */
 524  function restore_current_blog() {
 525      global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
 526  
 527      if ( !$switched )
 528          return false;
 529  
 530      if ( !is_array( $switched_stack ) )
 531          return false;
 532  
 533      $blog = array_pop( $switched_stack );
 534      if ( $blog_id == $blog ) {
 535          do_action( 'switch_blog', $blog, $blog );
 536          /* If we still have items in the switched stack, consider ourselves still 'switched' */
 537          $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
 538          return true;
 539      }
 540  
 541      $wpdb->set_blog_id($blog);
 542      $prev_blog_id = $blog_id;
 543      $blog_id = $blog;
 544      $table_prefix = $wpdb->prefix;
 545  
 546      if ( is_object( $wp_roles ) ) {
 547          $wpdb->suppress_errors();
 548          if ( method_exists( $wp_roles ,'_init' ) )
 549              $wp_roles->_init();
 550          elseif ( method_exists( $wp_roles, '__construct' ) )
 551              $wp_roles->__construct();
 552          $wpdb->suppress_errors( false );
 553      }
 554  
 555      if ( did_action('init') ) {
 556          $current_user = wp_get_current_user();
 557          if ( is_object( $current_user ) )
 558              $current_user->for_blog( $blog_id );
 559      }
 560  
 561      if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
 562          $global_groups = $wp_object_cache->global_groups;
 563      else
 564          $global_groups = false;
 565  
 566      wp_cache_init();
 567      if ( function_exists('wp_cache_add_global_groups') ) {
 568          if ( is_array( $global_groups ) )
 569              wp_cache_add_global_groups( $global_groups );
 570          else
 571              wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
 572          wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
 573      }
 574  
 575      do_action('switch_blog', $blog_id, $prev_blog_id);
 576  
 577      /* If we still have items in the switched stack, consider ourselves still 'switched' */
 578      $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
 579      return true;
 580  }
 581  
 582  /**
 583   * Check if a particular blog is archived.
 584   *
 585   * @since MU
 586   *
 587   * @param int $id The blog id
 588   * @return string Whether the blog is archived or not
 589   */
 590  function is_archived( $id ) {
 591      return get_blog_status($id, 'archived');
 592  }
 593  
 594  /**
 595   * Update the 'archived' status of a particular blog.
 596   *
 597   * @since MU
 598   *
 599   * @param int $id The blog id
 600   * @param string $archived The new status
 601   * @return string $archived
 602   */
 603  function update_archived( $id, $archived ) {
 604      update_blog_status($id, 'archived', $archived);
 605      return $archived;
 606  }
 607  
 608  /**
 609   * Update a blog details field.
 610   *
 611   * @since MU
 612   *
 613   * @param int $blog_id BLog ID
 614   * @param string $pref A field name
 615   * @param string $value Value for $pref
 616   * @return string $value
 617   */
 618  function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
 619      global $wpdb;
 620  
 621      if ( null !== $deprecated  )
 622          _deprecated_argument( __FUNCTION__, '3.1' );
 623  
 624      if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
 625          return $value;
 626  
 627      $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
 628  
 629      refresh_blog_details($blog_id);
 630  
 631      if ( 'spam' == $pref )
 632          ( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) :    do_action( 'make_ham_blog', $blog_id );
 633      elseif ( 'mature' == $pref )
 634          ( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
 635      elseif ( 'archived' == $pref )
 636          ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
 637      elseif ( 'archived' == $pref )
 638          ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
 639  
 640      return $value;
 641  }
 642  
 643  /**
 644   * Get a blog details field.
 645   *
 646   * @since MU
 647   *
 648   * @param int $id The blog id
 649   * @param string $pref A field name
 650   * @return bool $value
 651   */
 652  function get_blog_status( $id, $pref ) {
 653      global $wpdb;
 654  
 655      $details = get_blog_details( $id, false );
 656      if ( $details )
 657          return $details->$pref;
 658  
 659      return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
 660  }
 661  
 662  /**
 663   * Get a list of most recently updated blogs.
 664   *
 665   * @since MU
 666   *
 667   * @param mixed $deprecated Not used
 668   * @param int $start The offset
 669   * @param int $quantity The maximum number of blogs to retrieve. Default is 40.
 670   * @return array The list of blogs
 671   */
 672  function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
 673      global $wpdb;
 674  
 675      if ( ! empty( $deprecated ) )
 676          _deprecated_argument( __FUNCTION__, 'MU' ); // never used
 677  
 678      return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A );
 679  }
 680  
 681  ?>


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting