PageRenderTime 55ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/web/wp-includes/ms-blogs.php

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