PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-includes/ms-deprecated.php

https://gitlab.com/pankajmohale/chef2go
PHP | 518 lines | 245 code | 55 blank | 218 comment | 39 complexity | 594e9e63d40b507e65db930dc887f9e8 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 Use get_site()
  20. * @see get_site()
  21. *
  22. * @return WP_Site Current site object.
  23. */
  24. function get_dashboard_blog() {
  25. _deprecated_function( __FUNCTION__, '3.1.0' );
  26. if ( $blog = get_site_option( 'dashboard_blog' ) ) {
  27. return get_site( $blog );
  28. }
  29. return get_site( get_network()->site_id );
  30. }
  31. /**
  32. * Generates a random password.
  33. *
  34. * @since MU
  35. * @deprecated 3.0.0 Use wp_generate_password()
  36. * @see wp_generate_password()
  37. *
  38. * @param int $len Optional. The length of password to generate. Default 8.
  39. */
  40. function generate_random_password( $len = 8 ) {
  41. _deprecated_function( __FUNCTION__, '3.0.0', 'wp_generate_password()' );
  42. return wp_generate_password( $len );
  43. }
  44. /**
  45. * Determine if user is a site admin.
  46. *
  47. * Plugins should use is_multisite() instead of checking if this function exists
  48. * to determine if multisite is enabled.
  49. *
  50. * This function must reside in a file included only if is_multisite() due to
  51. * legacy function_exists() checks to determine if multisite is enabled.
  52. *
  53. * @since MU
  54. * @deprecated 3.0.0 Use is_super_admin()
  55. * @see is_super_admin()
  56. *
  57. * @param string $user_login Optional. Username for the user to check. Default empty.
  58. */
  59. function is_site_admin( $user_login = '' ) {
  60. _deprecated_function( __FUNCTION__, '3.0.0', 'is_super_admin()' );
  61. if ( empty( $user_login ) ) {
  62. $user_id = get_current_user_id();
  63. if ( !$user_id )
  64. return false;
  65. } else {
  66. $user = get_user_by( 'login', $user_login );
  67. if ( ! $user->exists() )
  68. return false;
  69. $user_id = $user->ID;
  70. }
  71. return is_super_admin( $user_id );
  72. }
  73. if ( !function_exists( 'graceful_fail' ) ) :
  74. /**
  75. * Deprecated functionality to gracefully fail.
  76. *
  77. * @since MU
  78. * @deprecated 3.0.0 Use wp_die()
  79. * @see wp_die()
  80. */
  81. function graceful_fail( $message ) {
  82. _deprecated_function( __FUNCTION__, '3.0.0', 'wp_die()' );
  83. $message = apply_filters( 'graceful_fail', $message );
  84. $message_template = apply_filters( 'graceful_fail_template',
  85. '<!DOCTYPE html>
  86. <html xmlns="http://www.w3.org/1999/xhtml"><head>
  87. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  88. <title>Error!</title>
  89. <style type="text/css">
  90. img {
  91. border: 0;
  92. }
  93. body {
  94. line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto;
  95. text-align: center;
  96. }
  97. .message {
  98. font-size: 22px;
  99. width: 350px;
  100. margin: auto;
  101. }
  102. </style>
  103. </head>
  104. <body>
  105. <p class="message">%s</p>
  106. </body>
  107. </html>' );
  108. die( sprintf( $message_template, $message ) );
  109. }
  110. endif;
  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. global $wpdb;
  176. $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 );
  177. $blog_list = array();
  178. foreach ( (array) $blogs as $details ) {
  179. $blog_list[ $details['blog_id'] ] = $details;
  180. $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'" );
  181. }
  182. if ( ! $blog_list ) {
  183. return array();
  184. }
  185. if ( $num == 'all' ) {
  186. return array_slice( $blog_list, $start, count( $blog_list ) );
  187. } else {
  188. return array_slice( $blog_list, $start, $num );
  189. }
  190. }
  191. /**
  192. * Deprecated functionality to retrieve a list of the most active sites.
  193. *
  194. * @since MU
  195. * @deprecated 3.0.0
  196. *
  197. * @param int $num Optional. Number of activate blogs to retrieve. Default 10.
  198. * @param bool $display Optional. Whether or not to display the most active blogs list. Default true.
  199. * @return array List of "most active" sites.
  200. */
  201. function get_most_active_blogs( $num = 10, $display = true ) {
  202. _deprecated_function( __FUNCTION__, '3.0.0' );
  203. $blogs = get_blog_list( 0, 'all', false ); // $blog_id -> $details
  204. if ( is_array( $blogs ) ) {
  205. reset( $blogs );
  206. $most_active = array();
  207. $blog_list = array();
  208. foreach ( (array) $blogs as $key => $details ) {
  209. $most_active[ $details['blog_id'] ] = $details['postcount'];
  210. $blog_list[ $details['blog_id'] ] = $details; // array_slice() removes keys!!
  211. }
  212. arsort( $most_active );
  213. reset( $most_active );
  214. $t = array();
  215. foreach ( (array) $most_active as $key => $details ) {
  216. $t[ $key ] = $blog_list[ $key ];
  217. }
  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. }
  228. }
  229. }
  230. return array_slice( $most_active, 0, $num );
  231. }
  232. /**
  233. * Redirect a user based on $_GET or $_POST arguments.
  234. *
  235. * The function looks for redirect arguments in the following order:
  236. * 1) $_GET['ref']
  237. * 2) $_POST['ref']
  238. * 3) $_SERVER['HTTP_REFERER']
  239. * 4) $_GET['redirect']
  240. * 5) $_POST['redirect']
  241. * 6) $url
  242. *
  243. * @since MU
  244. * @deprecated 3.3.0 Use wp_redirect()
  245. * @see wp_redirect()
  246. *
  247. * @param string $url Optional. Redirect URL. Default empty.
  248. */
  249. function wpmu_admin_do_redirect( $url = '' ) {
  250. _deprecated_function( __FUNCTION__, '3.3.0' );
  251. $ref = '';
  252. if ( isset( $_GET['ref'] ) )
  253. $ref = $_GET['ref'];
  254. if ( isset( $_POST['ref'] ) )
  255. $ref = $_POST['ref'];
  256. if ( $ref ) {
  257. $ref = wpmu_admin_redirect_add_updated_param( $ref );
  258. wp_redirect( $ref );
  259. exit();
  260. }
  261. if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
  262. wp_redirect( $_SERVER['HTTP_REFERER'] );
  263. exit();
  264. }
  265. $url = wpmu_admin_redirect_add_updated_param( $url );
  266. if ( isset( $_GET['redirect'] ) ) {
  267. if ( substr( $_GET['redirect'], 0, 2 ) == 's_' )
  268. $url .= '&action=blogs&s='. esc_html( substr( $_GET['redirect'], 2 ) );
  269. } elseif ( isset( $_POST['redirect'] ) ) {
  270. $url = wpmu_admin_redirect_add_updated_param( $_POST['redirect'] );
  271. }
  272. wp_redirect( $url );
  273. exit();
  274. }
  275. /**
  276. * Adds an 'updated=true' argument to a URL.
  277. *
  278. * @since MU
  279. * @deprecated 3.3.0 Use add_query_arg()
  280. * @see add_query_arg()
  281. *
  282. * @param string $url Optional. Redirect URL. Default empty.
  283. * @return string
  284. */
  285. function wpmu_admin_redirect_add_updated_param( $url = '' ) {
  286. _deprecated_function( __FUNCTION__, '3.3.0' );
  287. if ( strpos( $url, 'updated=true' ) === false ) {
  288. if ( strpos( $url, '?' ) === false )
  289. return $url . '?updated=true';
  290. else
  291. return $url . '&updated=true';
  292. }
  293. return $url;
  294. }
  295. /**
  296. * Get a numeric user ID from either an email address or a login.
  297. *
  298. * A numeric string is considered to be an existing user ID
  299. * and is simply returned as such.
  300. *
  301. * @since MU
  302. * @deprecated 3.6.0 Use get_user_by()
  303. * @see get_user_by()
  304. *
  305. * @param string $string Either an email address or a login.
  306. * @return int
  307. */
  308. function get_user_id_from_string( $string ) {
  309. _deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' );
  310. if ( is_email( $string ) )
  311. $user = get_user_by( 'email', $string );
  312. elseif ( is_numeric( $string ) )
  313. return $string;
  314. else
  315. $user = get_user_by( 'login', $string );
  316. if ( $user )
  317. return $user->ID;
  318. return 0;
  319. }
  320. /**
  321. * Get a full blog URL, given a domain and a path.
  322. *
  323. * @since MU
  324. * @deprecated 3.7.0
  325. *
  326. * @param string $domain
  327. * @param string $path
  328. * @return string
  329. */
  330. function get_blogaddress_by_domain( $domain, $path ) {
  331. _deprecated_function( __FUNCTION__, '3.7.0' );
  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. }
  344. }
  345. return esc_url_raw( $url );
  346. }
  347. /**
  348. * Create an empty blog.
  349. *
  350. * @since MU 1.0
  351. * @deprecated 4.4.0
  352. *
  353. * @param string $domain The new blog's domain.
  354. * @param string $path The new blog's path.
  355. * @param string $weblog_title The new blog's title.
  356. * @param int $site_id Optional. Defaults to 1.
  357. * @return string|int The ID of the newly created blog
  358. */
  359. function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
  360. _deprecated_function( __FUNCTION__, '4.4.0' );
  361. if ( empty($path) )
  362. $path = '/';
  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. // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
  367. // Need to get blog_id from wp_blogs, and create new table names.
  368. // Must restore table names at the end of function.
  369. if ( ! $blog_id = insert_blog($domain, $path, $site_id) )
  370. return __( '<strong>ERROR</strong>: problem creating site entry.' );
  371. switch_to_blog($blog_id);
  372. install_blog($blog_id);
  373. restore_current_blog();
  374. return $blog_id;
  375. }
  376. /**
  377. * Get the admin for a domain/path combination.
  378. *
  379. * @since MU 1.0
  380. * @deprecated 4.4.0
  381. *
  382. * @global wpdb $wpdb WordPress database abstraction object.
  383. *
  384. * @param string $sitedomain Optional. Site domain.
  385. * @param string $path Optional. Site path.
  386. * @return array|false The network admins
  387. */
  388. function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
  389. _deprecated_function( __FUNCTION__, '4.4.0' );
  390. global $wpdb;
  391. if ( ! $sitedomain )
  392. $site_id = $wpdb->siteid;
  393. else
  394. $site_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM $wpdb->site WHERE domain = %s AND path = %s", $sitedomain, $path ) );
  395. if ( $site_id )
  396. 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 );
  397. return false;
  398. }
  399. /**
  400. * Return an array of sites for a network or networks.
  401. *
  402. * @since 3.7.0
  403. * @deprecated 4.6.0
  404. * @see get_sites()
  405. *
  406. * @global wpdb $wpdb WordPress database abstraction object.
  407. *
  408. * @param array $args {
  409. * Array of default arguments. Optional.
  410. *
  411. * @type int|array $network_id A network ID or array of network IDs. Set to null to retrieve sites
  412. * from all networks. Defaults to current network ID.
  413. * @type int $public Retrieve public or non-public sites. Default null, for any.
  414. * @type int $archived Retrieve archived or non-archived sites. Default null, for any.
  415. * @type int $mature Retrieve mature or non-mature sites. Default null, for any.
  416. * @type int $spam Retrieve spam or non-spam sites. Default null, for any.
  417. * @type int $deleted Retrieve deleted or non-deleted sites. Default null, for any.
  418. * @type int $limit Number of sites to limit the query to. Default 100.
  419. * @type int $offset Exclude the first x sites. Used in combination with the $limit parameter. Default 0.
  420. * }
  421. * @return array An empty array if the install is considered "large" via wp_is_large_network(). Otherwise,
  422. * an associative array of site data arrays, each containing the site (network) ID, blog ID,
  423. * site domain and path, dates registered and modified, and the language ID. Also, boolean
  424. * values for whether the site is public, archived, mature, spam, and/or deleted.
  425. */
  426. function wp_get_sites( $args = array() ) {
  427. global $wpdb;
  428. _deprecated_function( __FUNCTION__, '4.6.0', 'get_sites()' );
  429. if ( wp_is_large_network() )
  430. return array();
  431. $defaults = array(
  432. 'network_id' => $wpdb->siteid,
  433. 'public' => null,
  434. 'archived' => null,
  435. 'mature' => null,
  436. 'spam' => null,
  437. 'deleted' => null,
  438. 'limit' => 100,
  439. 'offset' => 0,
  440. );
  441. $args = wp_parse_args( $args, $defaults );
  442. // Backwards compatibility
  443. if( is_array( $args['network_id'] ) ){
  444. $args['network__in'] = $args['network_id'];
  445. $args['network_id'] = null;
  446. }
  447. if( is_numeric( $args['limit'] ) ){
  448. $args['number'] = $args['limit'];
  449. $args['limit'] = null;
  450. } elseif ( ! $args['limit'] ) {
  451. $args['number'] = 0;
  452. $args['limit'] = null;
  453. }
  454. // Make sure count is disabled.
  455. $args['count'] = false;
  456. $_sites = get_sites( $args );
  457. $results = array();
  458. foreach ( $_sites as $_site ) {
  459. $_site = get_site( $_site );
  460. $results[] = $_site->to_array();
  461. }
  462. return $results;
  463. }