/wp-includes/ms-deprecated.php

  1. <?php 
  2. /** 
  3. * Deprecated functions from WordPress MU and the multisite feature. You shouldn't 
  4. * use these functions and look for the alternatives instead. The functions will be 
  5. * removed in a later version. 
  6. * 
  7. * @package WordPress 
  8. * @subpackage Deprecated 
  9. * @since 3.0.0 
  10. */ 
  11.  
  12. /** 
  13. * Deprecated functions come here to die. 
  14. */ 
  15.  
  16. /** 
  17. * Get the "dashboard blog", the blog where users without a blog edit their profile data. 
  18. * Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin. 
  19. * 
  20. * @since MU 
  21. * @deprecated 3.1.0 Use get_site() 
  22. * @see get_site() 
  23. * 
  24. * @return WP_Site Current site object. 
  25. */ 
  26. function get_dashboard_blog() { 
  27. _deprecated_function( __FUNCTION__, '3.1.0' ); 
  28. if ( $blog = get_site_option( 'dashboard_blog' ) ) { 
  29. return get_site( $blog ); 
  30.  
  31. return get_site( get_network()->site_id ); 
  32.  
  33. /** 
  34. * Generates a random password. 
  35. * 
  36. * @since MU 
  37. * @deprecated 3.0.0 Use wp_generate_password() 
  38. * @see wp_generate_password() 
  39. * 
  40. * @param int $len Optional. The length of password to generate. Default 8. 
  41. */ 
  42. function generate_random_password( $len = 8 ) { 
  43. _deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' ); 
  44. return wp_generate_password( $len ); 
  45.  
  46. /** 
  47. * Determine if user is a site admin. 
  48. * 
  49. * Plugins should use is_multisite() instead of checking if this function exists 
  50. * to determine if multisite is enabled. 
  51. * 
  52. * This function must reside in a file included only if is_multisite() due to 
  53. * legacy function_exists() checks to determine if multisite is enabled. 
  54. * 
  55. * @since MU 
  56. * @deprecated 3.0.0 Use is_super_admin() 
  57. * @see is_super_admin() 
  58. * 
  59. * @param string $user_login Optional. Username for the user to check. Default empty. 
  60. */ 
  61. function is_site_admin( $user_login = '' ) { 
  62. _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' ); 
  63.  
  64. if ( empty( $user_login ) ) { 
  65. $user_id = get_current_user_id(); 
  66. if ( !$user_id ) 
  67. return false; 
  68. } else { 
  69. $user = get_user_by( 'login', $user_login ); 
  70. if ( ! $user->exists() ) 
  71. return false; 
  72. $user_id = $user->ID; 
  73.  
  74. return is_super_admin( $user_id ); 
  75.  
  76. if ( !function_exists( 'graceful_fail' ) ) : 
  77. /** 
  78. * Deprecated functionality to gracefully fail. 
  79. * 
  80. * @since MU 
  81. * @deprecated 3.0.0 Use wp_die() 
  82. * @see wp_die() 
  83. */ 
  84. function graceful_fail( $message ) { 
  85. _deprecated_function( __FUNCTION__, '3.0.0', 'wp_die()' ); 
  86. $message = apply_filters( 'graceful_fail', $message ); 
  87. $message_template = apply_filters( 'graceful_fail_template',  
  88. '<!DOCTYPE html> 
  89. <html xmlns="http://www.w3.org/1999/xhtml"><head> 
  90. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
  91. <title>Error!</title> 
  92. <style type="text/css"> 
  93. img { 
  94. border: 0; 
  95. body { 
  96. line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto; 
  97. text-align: center; 
  98. .message { 
  99. font-size: 22px; 
  100. width: 350px; 
  101. margin: auto; 
  102. </style> 
  103. </head> 
  104. <body> 
  105. <p class="message">%s</p> 
  106. </body> 
  107. </html>' ); 
  108. die( sprintf( $message_template, $message ) ); 
  109. endif; 
  110.  
  111. /** 
  112. * Deprecated functionality to retrieve user information. 
  113. * 
  114. * @since MU 
  115. * @deprecated 3.0.0 Use get_user_by() 
  116. * @see get_user_by() 
  117. * 
  118. * @param string $username Username. 
  119. */ 
  120. function get_user_details( $username ) { 
  121. _deprecated_function( __FUNCTION__, '3.0.0', 'get_user_by()' ); 
  122. return get_user_by('login', $username); 
  123.  
  124. /** 
  125. * Deprecated functionality to clear the global post cache. 
  126. * 
  127. * @since MU 
  128. * @deprecated 3.0.0 Use clean_post_cache() 
  129. * @see clean_post_cache() 
  130. * 
  131. * @param int $post_id Post ID. 
  132. */ 
  133. function clear_global_post_cache( $post_id ) { 
  134. _deprecated_function( __FUNCTION__, '3.0.0', 'clean_post_cache()' ); 
  135.  
  136. /** 
  137. * Deprecated functionality to determin if the current site is the main site. 
  138. * 
  139. * @since MU 
  140. * @deprecated 3.0.0 Use is_main_site() 
  141. * @see is_main_site() 
  142. */ 
  143. function is_main_blog() { 
  144. _deprecated_function( __FUNCTION__, '3.0.0', 'is_main_site()' ); 
  145. return is_main_site(); 
  146.  
  147. /** 
  148. * Deprecated functionality to validate an email address. 
  149. * 
  150. * @since MU 
  151. * @deprecated 3.0.0 Use is_email() 
  152. * @see is_email() 
  153. * 
  154. * @param string $email Email address to verify. 
  155. * @param bool $check_domain Deprecated. 
  156. * @return string|bool Either false or the valid email address. 
  157. */ 
  158. function validate_email( $email, $check_domain = true) { 
  159. _deprecated_function( __FUNCTION__, '3.0.0', 'is_email()' ); 
  160. return is_email( $email, $check_domain ); 
  161.  
  162. /** 
  163. * Deprecated functionality to retrieve a list of all sites. 
  164. * 
  165. * @since MU 
  166. * @deprecated 3.0.0 Use wp_get_sites() 
  167. * @see wp_get_sites() 
  168. * 
  169. * @param int $start Optional. Offset for retrieving the blog list. Default 0. 
  170. * @param int $num Optional. Number of blogs to list. Default 10. 
  171. * @param string $deprecated Unused. 
  172. */ 
  173. function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) { 
  174. _deprecated_function( __FUNCTION__, '3.0.0', 'wp_get_sites()' ); 
  175.  
  176. global $wpdb; 
  177. $blogs = $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' ORDER BY registered DESC", $wpdb->siteid), ARRAY_A ); 
  178.  
  179. $blog_list = array(); 
  180. foreach ( (array) $blogs as $details ) { 
  181. $blog_list[ $details['blog_id'] ] = $details; 
  182. $blog_list[ $details['blog_id'] ]['postcount'] = $wpdb->get_var( "SELECT COUNT(ID) FROM " . $wpdb->get_blog_prefix( $details['blog_id'] ). "posts WHERE post_status='publish' AND post_type='post'" ); 
  183.  
  184. if ( ! $blog_list ) { 
  185. return array(); 
  186.  
  187. if ( $num == 'all' ) { 
  188. return array_slice( $blog_list, $start, count( $blog_list ) ); 
  189. } else { 
  190. return array_slice( $blog_list, $start, $num ); 
  191.  
  192. /** 
  193. * Deprecated functionality to retrieve a list of the most active sites. 
  194. * 
  195. * @since MU 
  196. * @deprecated 3.0.0 
  197. * 
  198. * @param int $num Optional. Number of activate blogs to retrieve. Default 10. 
  199. * @param bool $display Optional. Whether or not to display the most active blogs list. Default true. 
  200. * @return array List of "most active" sites. 
  201. */ 
  202. function get_most_active_blogs( $num = 10, $display = true ) { 
  203. _deprecated_function( __FUNCTION__, '3.0.0' ); 
  204.  
  205. $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details 
  206. if ( is_array( $blogs ) ) { 
  207. reset( $blogs ); 
  208. $most_active = array(); 
  209. $blog_list = array(); 
  210. foreach ( (array) $blogs as $key => $details ) { 
  211. $most_active[ $details['blog_id'] ] = $details['postcount']; 
  212. $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!! 
  213. arsort( $most_active ); 
  214. reset( $most_active ); 
  215. $t = array(); 
  216. foreach ( (array) $most_active as $key => $details ) { 
  217. $t[ $key ] = $blog_list[ $key ]; 
  218. unset( $most_active ); 
  219. $most_active = $t; 
  220.  
  221. if ( $display ) { 
  222. if ( is_array( $most_active ) ) { 
  223. reset( $most_active ); 
  224. foreach ( (array) $most_active as $key => $details ) { 
  225. $url = esc_url('http://' . $details['domain'] . $details['path']); 
  226. echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>"; 
  227. return array_slice( $most_active, 0, $num ); 
  228.  
  229. /** 
  230. * Redirect a user based on $_GET or $_POST arguments. 
  231. * 
  232. * The function looks for redirect arguments in the following order: 
  233. * 1) $_GET['ref'] 
  234. * 2) $_POST['ref'] 
  235. * 3) $_SERVER['HTTP_REFERER'] 
  236. * 4) $_GET['redirect'] 
  237. * 5) $_POST['redirect'] 
  238. * 6) $url 
  239. * 
  240. * @since MU 
  241. * @deprecated 3.3.0 Use wp_redirect() 
  242. * @see wp_redirect() 
  243. * 
  244. * @param string $url Optional. Redirect URL. Default empty. 
  245. */ 
  246. function wpmu_admin_do_redirect( $url = '' ) { 
  247. _deprecated_function( __FUNCTION__, '3.3.0' ); 
  248.  
  249. $ref = ''; 
  250. if ( isset( $_GET['ref'] ) ) 
  251. $ref = $_GET['ref']; 
  252. if ( isset( $_POST['ref'] ) ) 
  253. $ref = $_POST['ref']; 
  254.  
  255. if ( $ref ) { 
  256. $ref = wpmu_admin_redirect_add_updated_param( $ref ); 
  257. wp_redirect( $ref ); 
  258. exit(); 
  259. if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) { 
  260. wp_redirect( $_SERVER['HTTP_REFERER'] ); 
  261. exit(); 
  262.  
  263. $url = wpmu_admin_redirect_add_updated_param( $url ); 
  264. if ( isset( $_GET['redirect'] ) ) { 
  265. if ( substr( $_GET['redirect'], 0, 2 ) == 's_' ) 
  266. $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) ); 
  267. } elseif ( isset( $_POST['redirect'] ) ) { 
  268. $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] ); 
  269. wp_redirect( $url ); 
  270. exit(); 
  271.  
  272. /** 
  273. * Adds an 'updated=true' argument to a URL. 
  274. * 
  275. * @since MU 
  276. * @deprecated 3.3.0 Use add_query_arg() 
  277. * @see add_query_arg() 
  278. * 
  279. * @param string $url Optional. Redirect URL. Default empty. 
  280. * @return string 
  281. */ 
  282. function wpmu_admin_redirect_add_updated_param( $url = '' ) { 
  283. _deprecated_function( __FUNCTION__, '3.3.0' ); 
  284.  
  285. if ( strpos( $url, 'updated=true' ) === false ) { 
  286. if ( strpos( $url, '?' ) === false ) 
  287. return $url . '?updated=true'; 
  288. else 
  289. return $url . '&updated=true'; 
  290. return $url; 
  291.  
  292. /** 
  293. * Get a numeric user ID from either an email address or a login. 
  294. * 
  295. * A numeric string is considered to be an existing user ID 
  296. * and is simply returned as such. 
  297. * 
  298. * @since MU 
  299. * @deprecated 3.6.0 Use get_user_by() 
  300. * @see get_user_by() 
  301. * 
  302. * @param string $string Either an email address or a login. 
  303. * @return int 
  304. */ 
  305. function get_user_id_from_string( $string ) { 
  306. _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' ); 
  307.  
  308. if ( is_email( $string ) ) 
  309. $user = get_user_by( 'email', $string ); 
  310. elseif ( is_numeric( $string ) ) 
  311. return $string; 
  312. else 
  313. $user = get_user_by( 'login', $string ); 
  314.  
  315. if ( $user ) 
  316. return $user->ID; 
  317. return 0; 
  318.  
  319. /** 
  320. * Get a full blog URL, given a domain and a path. 
  321. * 
  322. * @since MU 
  323. * @deprecated 3.7.0 
  324. * 
  325. * @param string $domain 
  326. * @param string $path 
  327. * @return string 
  328. */ 
  329. function get_blogaddress_by_domain( $domain, $path ) { 
  330. _deprecated_function( __FUNCTION__, '3.7.0' ); 
  331.  
  332. if ( is_subdomain_install() ) { 
  333. $url = "http://" . $domain.$path; 
  334. } else { 
  335. if ( $domain != $_SERVER['HTTP_HOST'] ) { 
  336. $blogname = substr( $domain, 0, strpos( $domain, '.' ) ); 
  337. $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path; 
  338. // we're not installing the main blog 
  339. if ( $blogname != 'www.' ) 
  340. $url .= $blogname . '/'; 
  341. } else { // main blog 
  342. $url = 'http://' . $domain . $path; 
  343. return esc_url_raw( $url ); 
  344.  
  345. /** 
  346. * Create an empty blog. 
  347. * 
  348. * @since MU 1.0 
  349. * @deprecated 4.4.0 
  350. * 
  351. * @param string $domain The new blog's domain. 
  352. * @param string $path The new blog's path. 
  353. * @param string $weblog_title The new blog's title. 
  354. * @param int $site_id Optional. Defaults to 1. 
  355. * @return string|int The ID of the newly created blog 
  356. */ 
  357. function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { 
  358. _deprecated_function( __FUNCTION__, '4.4.0' ); 
  359.  
  360. if ( empty($path) ) 
  361. $path = '/'; 
  362.  
  363. // Check if the domain has been used already. We should return an error message. 
  364. if ( domain_exists($domain, $path, $site_id) ) 
  365. return __( '<strong>ERROR</strong>: Site URL already taken.' ); 
  366.  
  367. // Need to back up wpdb table names, and create a new wp_blogs entry for new blog. 
  368. // Need to get blog_id from wp_blogs, and create new table names. 
  369. // Must restore table names at the end of function. 
  370.  
  371. if ( ! $blog_id = insert_blog($domain, $path, $site_id) ) 
  372. return __( '<strong>ERROR</strong>: problem creating site entry.' ); 
  373.  
  374. switch_to_blog($blog_id); 
  375. install_blog($blog_id); 
  376. restore_current_blog(); 
  377.  
  378. return $blog_id; 
  379.  
  380. /** 
  381. * Get the admin for a domain/path combination. 
  382. * 
  383. * @since MU 1.0 
  384. * @deprecated 4.4.0 
  385. * 
  386. * @global wpdb $wpdb WordPress database abstraction object. 
  387. * 
  388. * @param string $sitedomain Optional. Site domain. 
  389. * @param string $path Optional. Site path. 
  390. * @return array|false The network admins 
  391. */ 
  392. function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { 
  393. _deprecated_function( __FUNCTION__, '4.4.0' ); 
  394.  
  395. global $wpdb; 
  396.  
  397. if ( ! $sitedomain ) 
  398. $site_id = $wpdb->siteid; 
  399. else 
  400. $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) ); 
  401.  
  402. if ( $site_id ) 
  403. return $wpdb->get_results( $wpdb->prepare( "SELECT u.ID, u.user_login, u.user_pass FROM $wpdb->users AS u, $wpdb->sitemeta AS sm WHERE sm.meta_key = 'admin_user_id' AND u.ID = sm.meta_value AND sm.site_id = %d", $site_id ), ARRAY_A ); 
  404.  
  405. return false; 
  406.  
  407. /** 
  408. * Return an array of sites for a network or networks. 
  409. * 
  410. * @since 3.7.0 
  411. * @deprecated 4.6.0 
  412. * @see get_sites() 
  413. * 
  414. * @global wpdb $wpdb WordPress database abstraction object. 
  415. * 
  416. * @param array $args { 
  417. * Array of default arguments. Optional. 
  418. * 
  419. * @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites 
  420. * from all networks. Defaults to current network ID. 
  421. * @type int $public Retrieve public or non-public sites. Default null, for any. 
  422. * @type int $archived Retrieve archived or non-archived sites. Default null, for any. 
  423. * @type int $mature Retrieve mature or non-mature sites. Default null, for any. 
  424. * @type int $spam Retrieve spam or non-spam sites. Default null, for any. 
  425. * @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any. 
  426. * @type int $limit Number of sites to limit the query to. Default 100. 
  427. * @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0. 
  428. * } 
  429. * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,  
  430. * an associative array of site data arrays, each containing the site (network) ID, blog ID,  
  431. * site domain and path, dates registered and modified, and the language ID. Also, boolean 
  432. * values for whether the site is public, archived, mature, spam, and/or deleted. 
  433. */ 
  434. function wp_get_sites( $args = array() ) { 
  435. global $wpdb; 
  436.  
  437. _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' ); 
  438.  
  439. if ( wp_is_large_network() ) 
  440. return array(); 
  441.  
  442. $defaults = array( 
  443. 'network_id' => $wpdb->siteid,  
  444. 'public' => null,  
  445. 'archived' => null,  
  446. 'mature' => null,  
  447. 'spam' => null,  
  448. 'deleted' => null,  
  449. 'limit' => 100,  
  450. 'offset' => 0,  
  451. ); 
  452.  
  453. $args = wp_parse_args( $args, $defaults ); 
  454.  
  455. // Backwards compatibility 
  456. if( is_array( $args['network_id'] ) ) { 
  457. $args['network__in'] = $args['network_id']; 
  458. $args['network_id'] = null; 
  459.  
  460. if( is_numeric( $args['limit'] ) ) { 
  461. $args['number'] = $args['limit']; 
  462. $args['limit'] = null; 
  463.  
  464. // Make sure count is disabled. 
  465. $args['count'] = false; 
  466.  
  467. $_sites = get_sites( $args ); 
  468.  
  469. $results = array(); 
  470.  
  471. foreach ( $_sites as $_site ) { 
  472. $_site = get_site( $_site ); 
  473. $results[] = $_site->to_array(); 
  474.  
  475. return $results; 
.