PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/ms-deprecated.php

https://gitlab.com/Blueprint-Marketing/WordPress-1
PHP | 347 lines | 179 code | 32 blank | 136 comment | 33 complexity | 6a70302a6b7e11866086b486afa1426c MD5 | raw file
  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. * Deprecated functions come here to die.
  13. */
  14. /**
  15. * Get the "dashboard blog", the blog where users without a blog edit their profile data.
  16. * Dashboard blog functionality was removed in WordPress 3.1, replaced by the user admin.
  17. *
  18. * @since MU
  19. * @deprecated 3.1.0
  20. * @see get_blog_details()
  21. * @return int
  22. */
  23. function get_dashboard_blog() {
  24. _deprecated_function( __FUNCTION__, '3.1' );
  25. if ( $blog = get_site_option( 'dashboard_blog' ) )
  26. return get_blog_details( $blog );
  27. return get_blog_details( $GLOBALS['current_site']->blog_id );
  28. }
  29. /**
  30. * @since MU
  31. * @deprecated 3.0.0
  32. * @deprecated Use wp_generate_password()
  33. * @see wp_generate_password()
  34. */
  35. function generate_random_password( $len = 8 ) {
  36. _deprecated_function( __FUNCTION__, '3.0', 'wp_generate_password()' );
  37. return wp_generate_password( $len );
  38. }
  39. /**
  40. * Determine if user is a site admin.
  41. *
  42. * Plugins should use is_multisite() instead of checking if this function exists
  43. * to determine if multisite is enabled.
  44. *
  45. * This function must reside in a file included only if is_multisite() due to
  46. * legacy function_exists() checks to determine if multisite is enabled.
  47. *
  48. * @since MU
  49. * @deprecated 3.0.0
  50. * @deprecated Use is_super_admin()
  51. * @see is_super_admin()
  52. * @see is_multisite()
  53. *
  54. */
  55. function is_site_admin( $user_login = '' ) {
  56. _deprecated_function( __FUNCTION__, '3.0', 'is_super_admin()' );
  57. if ( empty( $user_login ) ) {
  58. $user_id = get_current_user_id();
  59. if ( !$user_id )
  60. return false;
  61. } else {
  62. $user = get_user_by( 'login', $user_login );
  63. if ( ! $user->exists() )
  64. return false;
  65. $user_id = $user->ID;
  66. }
  67. return is_super_admin( $user_id );
  68. }
  69. if ( !function_exists( 'graceful_fail' ) ) :
  70. /**
  71. * @since MU
  72. * @deprecated 3.0.0
  73. * @deprecated Use wp_die()
  74. * @see wp_die()
  75. */
  76. function graceful_fail( $message ) {
  77. _deprecated_function( __FUNCTION__, '3.0', 'wp_die()' );
  78. $message = apply_filters( 'graceful_fail', $message );
  79. $message_template = apply_filters( 'graceful_fail_template',
  80. '<!DOCTYPE html>
  81. <html xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11">
  82. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  83. <title>Error!</title>
  84. <style type="text/css">
  85. img {
  86. border: 0;
  87. }
  88. body {
  89. line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto;
  90. text-align: center;
  91. }
  92. .message {
  93. font-size: 22px;
  94. width: 350px;
  95. margin: auto;
  96. }
  97. </style>
  98. </head>
  99. <body>
  100. <p class="message">%s</p>
  101. </body>
  102. </html>' );
  103. die( sprintf( $message_template, $message ) );
  104. }
  105. endif;
  106. /**
  107. * @since MU
  108. * @deprecated 3.0.0
  109. * @deprecated Use get_user_by()
  110. * @see get_user_by()
  111. */
  112. function get_user_details( $username ) {
  113. _deprecated_function( __FUNCTION__, '3.0', 'get_user_by()' );
  114. return get_user_by('login', $username);
  115. }
  116. /**
  117. * @since MU
  118. * @deprecated 3.0.0
  119. * @deprecated Use clean_post_cache()
  120. * @see clean_post_cache()
  121. */
  122. function clear_global_post_cache( $post_id ) {
  123. _deprecated_function( __FUNCTION__, '3.0', 'clean_post_cache()' );
  124. }
  125. /**
  126. * @since MU
  127. * @deprecated 3.0.0
  128. * @deprecated Use is_main_site()
  129. * @see is_main_site()
  130. */
  131. function is_main_blog() {
  132. _deprecated_function( __FUNCTION__, '3.0', 'is_main_site()' );
  133. return is_main_site();
  134. }
  135. /**
  136. * @since MU
  137. * @deprecated 3.0.0
  138. * @deprecated Use is_email()
  139. * @see is_email()
  140. */
  141. function validate_email( $email, $check_domain = true) {
  142. _deprecated_function( __FUNCTION__, '3.0', 'is_email()' );
  143. return is_email( $email, $check_domain );
  144. }
  145. /**
  146. * @since MU
  147. * @deprecated 3.0.0
  148. * @deprecated No alternative available. For performance reasons this function is not recommended.
  149. */
  150. function get_blog_list( $start = 0, $num = 10, $deprecated = '' ) {
  151. _deprecated_function( __FUNCTION__, '3.0', 'wp_get_sites()' );
  152. global $wpdb;
  153. $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 );
  154. foreach ( (array) $blogs as $details ) {
  155. $blog_list[ $details['blog_id'] ] = $details;
  156. $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'" );
  157. }
  158. unset( $blogs );
  159. $blogs = $blog_list;
  160. if ( false == is_array( $blogs ) )
  161. return array();
  162. if ( $num == 'all' )
  163. return array_slice( $blogs, $start, count( $blogs ) );
  164. else
  165. return array_slice( $blogs, $start, $num );
  166. }
  167. /**
  168. * @since MU
  169. * @deprecated 3.0.0
  170. * @deprecated No alternative available. For performance reasons this function is not recommended.
  171. */
  172. function get_most_active_blogs( $num = 10, $display = true ) {
  173. _deprecated_function( __FUNCTION__, '3.0' );
  174. $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
  175. if ( is_array( $blogs ) ) {
  176. reset( $blogs );
  177. foreach ( (array) $blogs as $key => $details ) {
  178. $most_active[ $details['blog_id'] ] = $details['postcount'];
  179. $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!!
  180. }
  181. arsort( $most_active );
  182. reset( $most_active );
  183. foreach ( (array) $most_active as $key => $details )
  184. $t[ $key ] = $blog_list[ $key ];
  185. unset( $most_active );
  186. $most_active = $t;
  187. }
  188. if ( $display == true ) {
  189. if ( is_array( $most_active ) ) {
  190. reset( $most_active );
  191. foreach ( (array) $most_active as $key => $details ) {
  192. $url = esc_url('http://' . $details['domain'] . $details['path']);
  193. echo '<li>' . $details['postcount'] . " <a href='$url'>$url</a></li>";
  194. }
  195. }
  196. }
  197. return array_slice( $most_active, 0, $num );
  198. }
  199. /**
  200. * Redirect a user based on $_GET or $_POST arguments.
  201. *
  202. * The function looks for redirect arguments in the following order:
  203. * 1) $_GET['ref']
  204. * 2) $_POST['ref']
  205. * 3) $_SERVER['HTTP_REFERER']
  206. * 4) $_GET['redirect']
  207. * 5) $_POST['redirect']
  208. * 6) $url
  209. *
  210. * @since MU
  211. * @deprecated 3.3.0
  212. * @deprecated Use wp_redirect()
  213. * @uses wpmu_admin_redirect_add_updated_param()
  214. *
  215. * @param string $url
  216. */
  217. function wpmu_admin_do_redirect( $url = '' ) {
  218. _deprecated_function( __FUNCTION__, '3.3' );
  219. $ref = '';
  220. if ( isset( $_GET['ref'] ) )
  221. $ref = $_GET['ref'];
  222. if ( isset( $_POST['ref'] ) )
  223. $ref = $_POST['ref'];
  224. if ( $ref ) {
  225. $ref = wpmu_admin_redirect_add_updated_param( $ref );
  226. wp_redirect( $ref );
  227. exit();
  228. }
  229. if ( empty( $_SERVER['HTTP_REFERER'] ) == false ) {
  230. wp_redirect( $_SERVER['HTTP_REFERER'] );
  231. exit();
  232. }
  233. $url = wpmu_admin_redirect_add_updated_param( $url );
  234. if ( isset( $_GET['redirect'] ) ) {
  235. if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
  236. $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
  237. } elseif ( isset( $_POST['redirect'] ) ) {
  238. $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
  239. }
  240. wp_redirect( $url );
  241. exit();
  242. }
  243. /**
  244. * Adds an 'updated=true' argument to a URL.
  245. *
  246. * @since MU
  247. * @deprecated 3.3.0
  248. * @deprecated Use add_query_arg()
  249. *
  250. * @param string $url
  251. * @return string
  252. */
  253. function wpmu_admin_redirect_add_updated_param( $url = '' ) {
  254. _deprecated_function( __FUNCTION__, '3.3' );
  255. if ( strpos( $url, 'updated=true' ) === false ) {
  256. if ( strpos( $url, '?' ) === false )
  257. return $url . '?updated=true';
  258. else
  259. return $url . '&updated=true';
  260. }
  261. return $url;
  262. }
  263. /**
  264. * Get a numeric user ID from either an email address or a login.
  265. *
  266. * A numeric string is considered to be an existing user ID
  267. * and is simply returned as such.
  268. *
  269. * @since MU
  270. * @deprecated 3.6.0
  271. * @deprecated Use get_user_by()
  272. * @uses get_user_by()
  273. *
  274. * @param string $string Either an email address or a login.
  275. * @return int
  276. */
  277. function get_user_id_from_string( $string ) {
  278. _deprecated_function( __FUNCTION__, '3.6', 'get_user_by()' );
  279. if ( is_email( $string ) )
  280. $user = get_user_by( 'email', $string );
  281. elseif ( is_numeric( $string ) )
  282. return $string;
  283. else
  284. $user = get_user_by( 'login', $string );
  285. if ( $user )
  286. return $user->ID;
  287. return 0;
  288. }
  289. /**
  290. * Get a full blog URL, given a domain and a path.
  291. *
  292. * @since MU
  293. * @deprecated 3.7.0
  294. *
  295. * @param string $domain
  296. * @param string $path
  297. * @return string
  298. */
  299. function get_blogaddress_by_domain( $domain, $path ) {
  300. _deprecated_function( __FUNCTION__, '3.7' );
  301. if ( is_subdomain_install() ) {
  302. $url = "http://" . $domain.$path;
  303. } else {
  304. if ( $domain != $_SERVER['HTTP_HOST'] ) {
  305. $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
  306. $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
  307. // we're not installing the main blog
  308. if ( $blogname != 'www.' )
  309. $url .= $blogname . '/';
  310. } else { // main blog
  311. $url = 'http://' . $domain . $path;
  312. }
  313. }
  314. return esc_url_raw( $url );
  315. }