wp/wp-includes/ms-site.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   350 function _prime_site_caches( $ids, $update_meta_cache = true ) {
   350 function _prime_site_caches( $ids, $update_meta_cache = true ) {
   351 	global $wpdb;
   351 	global $wpdb;
   352 
   352 
   353 	$non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
   353 	$non_cached_ids = _get_non_cached_ids( $ids, 'sites' );
   354 	if ( ! empty( $non_cached_ids ) ) {
   354 	if ( ! empty( $non_cached_ids ) ) {
   355 		$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
   355 		$fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", implode( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
   356 
   356 
   357 		update_site_cache( $fresh_sites, $update_meta_cache );
   357 		update_site_cache( $fresh_sites, $update_meta_cache );
   358 	}
   358 	}
   359 }
   359 }
   360 
   360 
   408  * @since 4.6.0
   408  * @since 4.6.0
   409  * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
   409  * @since 4.8.0 Introduced the 'lang_id', 'lang__in', and 'lang__not_in' parameters.
   410  *
   410  *
   411  * @see WP_Site_Query::parse_query()
   411  * @see WP_Site_Query::parse_query()
   412  *
   412  *
   413  * @param string|array $args {
   413  * @param string|array $args Optional. Array or string of arguments. See WP_Site_Query::__construct()
   414  *     Optional. Array or query string of site query parameters. Default empty.
   414  *                           for information on accepted arguments. Default empty array.
   415  *
       
   416  *     @type array        $site__in          Array of site IDs to include. Default empty.
       
   417  *     @type array        $site__not_in      Array of site IDs to exclude. Default empty.
       
   418  *     @type bool         $count             Whether to return a site count (true) or array of site objects.
       
   419  *                                           Default false.
       
   420  *     @type array        $date_query        Date query clauses to limit sites by. See WP_Date_Query.
       
   421  *                                           Default null.
       
   422  *     @type string       $fields            Site fields to return. Accepts 'ids' (returns an array of site IDs)
       
   423  *                                           or empty (returns an array of complete site objects). Default empty.
       
   424  *     @type int          $ID                A site ID to only return that site. Default empty.
       
   425  *     @type int          $number            Maximum number of sites to retrieve. Default 100.
       
   426  *     @type int          $offset            Number of sites to offset the query. Used to build LIMIT clause.
       
   427  *                                           Default 0.
       
   428  *     @type bool         $no_found_rows     Whether to disable the `SQL_CALC_FOUND_ROWS` query. Default true.
       
   429  *     @type string|array $orderby           Site status or array of statuses. Accepts 'id', 'domain', 'path',
       
   430  *                                           'network_id', 'last_updated', 'registered', 'domain_length',
       
   431  *                                           'path_length', 'site__in' and 'network__in'. Also accepts false,
       
   432  *                                           an empty array, or 'none' to disable `ORDER BY` clause.
       
   433  *                                           Default 'id'.
       
   434  *     @type string       $order             How to order retrieved sites. Accepts 'ASC', 'DESC'. Default 'ASC'.
       
   435  *     @type int          $network_id        Limit results to those affiliated with a given network ID. If 0,
       
   436  *                                           include all networks. Default 0.
       
   437  *     @type array        $network__in       Array of network IDs to include affiliated sites for. Default empty.
       
   438  *     @type array        $network__not_in   Array of network IDs to exclude affiliated sites for. Default empty.
       
   439  *     @type string       $domain            Limit results to those affiliated with a given domain. Default empty.
       
   440  *     @type array        $domain__in        Array of domains to include affiliated sites for. Default empty.
       
   441  *     @type array        $domain__not_in    Array of domains to exclude affiliated sites for. Default empty.
       
   442  *     @type string       $path              Limit results to those affiliated with a given path. Default empty.
       
   443  *     @type array        $path__in          Array of paths to include affiliated sites for. Default empty.
       
   444  *     @type array        $path__not_in      Array of paths to exclude affiliated sites for. Default empty.
       
   445  *     @type int          $public            Limit results to public sites. Accepts '1' or '0'. Default empty.
       
   446  *     @type int          $archived          Limit results to archived sites. Accepts '1' or '0'. Default empty.
       
   447  *     @type int          $mature            Limit results to mature sites. Accepts '1' or '0'. Default empty.
       
   448  *     @type int          $spam              Limit results to spam sites. Accepts '1' or '0'. Default empty.
       
   449  *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
       
   450  *     @type int          $lang_id           Limit results to a language ID. Default empty.
       
   451  *     @type array        $lang__in          Array of language IDs to include affiliated sites for. Default empty.
       
   452  *     @type array        $lang__not_in      Array of language IDs to exclude affiliated sites for. Default empty.
       
   453  *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
       
   454  *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
       
   455  *                                           Default empty array.
       
   456  *     @type bool         $update_site_cache Whether to prime the cache for found sites. Default true.
       
   457  * }
       
   458  * @return array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids',
   415  * @return array|int List of WP_Site objects, a list of site IDs when 'fields' is set to 'ids',
   459  *                   or the number of sites when 'count' is passed as a query var.
   416  *                   or the number of sites when 'count' is passed as a query var.
   460  */
   417  */
   461 function get_sites( $args = array() ) {
   418 function get_sites( $args = array() ) {
   462 	$query = new WP_Site_Query();
   419 	$query = new WP_Site_Query();
   666  *     @type array  $options Custom option $key => $value pairs to use. Default
   623  *     @type array  $options Custom option $key => $value pairs to use. Default
   667  *                           empty array.
   624  *                           empty array.
   668  *     @type array  $meta    Custom site metadata $key => $value pairs to use.
   625  *     @type array  $meta    Custom site metadata $key => $value pairs to use.
   669  *                           Default empty array.
   626  *                           Default empty array.
   670  * }
   627  * }
   671  * @return bool|WP_Error True on success, or error object on failure.
   628  * @return true|WP_Error True on success, or error object on failure.
   672  */
   629  */
   673 function wp_initialize_site( $site_id, array $args = array() ) {
   630 function wp_initialize_site( $site_id, array $args = array() ) {
   674 	global $wpdb, $wp_roles;
   631 	global $wpdb, $wp_roles;
   675 
   632 
   676 	if ( empty( $site_id ) ) {
   633 	if ( empty( $site_id ) ) {
   797  * @since 5.1.0
   754  * @since 5.1.0
   798  *
   755  *
   799  * @global wpdb $wpdb WordPress database abstraction object.
   756  * @global wpdb $wpdb WordPress database abstraction object.
   800  *
   757  *
   801  * @param int|WP_Site $site_id Site ID or object.
   758  * @param int|WP_Site $site_id Site ID or object.
   802  * @return bool|WP_Error True on success, or error object on failure.
   759  * @return true|WP_Error True on success, or error object on failure.
   803  */
   760  */
   804 function wp_uninitialize_site( $site_id ) {
   761 function wp_uninitialize_site( $site_id ) {
   805 	global $wpdb;
   762 	global $wpdb;
   806 
   763 
   807 	if ( empty( $site_id ) ) {
   764 	if ( empty( $site_id ) ) {
   858 	/**
   815 	/**
   859 	 * Filters the upload base directory to delete when the site is deleted.
   816 	 * Filters the upload base directory to delete when the site is deleted.
   860 	 *
   817 	 *
   861 	 * @since MU (3.0.0)
   818 	 * @since MU (3.0.0)
   862 	 *
   819 	 *
   863 	 * @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir()
   820 	 * @param string $basedir Uploads path without subdirectory. @see wp_upload_dir()
   864 	 * @param int    $site_id            The site ID.
   821 	 * @param int    $site_id The site ID.
   865 	 */
   822 	 */
   866 	$dir     = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $site->id );
   823 	$dir     = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $site->id );
   867 	$dir     = rtrim( $dir, DIRECTORY_SEPARATOR );
   824 	$dir     = rtrim( $dir, DIRECTORY_SEPARATOR );
   868 	$top_dir = $dir;
   825 	$top_dir = $dir;
   869 	$stack   = array( $dir );
   826 	$stack   = array( $dir );
  1082  *
  1039  *
  1083  * @param int    $site_id Site ID.
  1040  * @param int    $site_id Site ID.
  1084  * @param string $key     Optional. The meta key to retrieve. By default,
  1041  * @param string $key     Optional. The meta key to retrieve. By default,
  1085  *                        returns data for all keys. Default empty.
  1042  *                        returns data for all keys. Default empty.
  1086  * @param bool   $single  Optional. Whether to return a single value.
  1043  * @param bool   $single  Optional. Whether to return a single value.
  1087  *                        This parameter has no effect if $key is not specified.
  1044  *                        This parameter has no effect if `$key` is not specified.
  1088  *                        Default false.
  1045  *                        Default false.
  1089  * @return mixed An array if $single is false. The value of meta data field
  1046  * @return mixed An array of values if `$single` is false.
  1090  *               if $single is true. False for an invalid $site_id.
  1047  *               The value of meta data field if `$single` is true.
       
  1048  *               False for an invalid `$site_id` (non-numeric, zero, or negative value).
       
  1049  *               An empty string if a valid but non-existing site ID is passed.
  1091  */
  1050  */
  1092 function get_site_meta( $site_id, $key = '', $single = false ) {
  1051 function get_site_meta( $site_id, $key = '', $single = false ) {
  1093 	return get_metadata( 'blog', $site_id, $key, $single );
  1052 	return get_metadata( 'blog', $site_id, $key, $single );
  1094 }
  1053 }
  1095 
  1054