credits.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * WordPress Credits Administration API.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. * @since 4.4.0
  8. */
  9. /**
  10. * Retrieve the contributor credits.
  11. *
  12. * @since 3.2.0
  13. *
  14. * @return array|false A list of all of the contributors, or false on error.
  15. */
  16. function wp_credits() {
  17. // include an unmodified $wp_version
  18. include( ABSPATH . WPINC . '/version.php' );
  19. $locale = get_user_locale();
  20. $results = get_site_transient( 'wordpress_credits_' . $locale );
  21. if ( ! is_array( $results )
  22. || false !== strpos( $wp_version, '-' )
  23. || ( isset( $results['data']['version'] ) && strpos( $wp_version, $results['data']['version'] ) !== 0 )
  24. ) {
  25. $url = "http://api.wordpress.org/core/credits/1.1/?version={$wp_version}&locale={$locale}";
  26. $options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
  27. if ( wp_http_supports( array( 'ssl' ) ) ) {
  28. $url = set_url_scheme( $url, 'https' );
  29. }
  30. $response = wp_remote_get( $url, $options );
  31. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
  32. return false;
  33. $results = json_decode( wp_remote_retrieve_body( $response ), true );
  34. if ( ! is_array( $results ) )
  35. return false;
  36. set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
  37. }
  38. return $results;
  39. }
  40. /**
  41. * Retrieve the link to a contributor's WordPress.org profile page.
  42. *
  43. * @access private
  44. * @since 3.2.0
  45. *
  46. * @param string $display_name The contributor's display name (passed by reference).
  47. * @param string $username The contributor's username.
  48. * @param string $profiles URL to the contributor's WordPress.org profile page.
  49. */
  50. function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
  51. $display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
  52. }
  53. /**
  54. * Retrieve the link to an external library used in WordPress.
  55. *
  56. * @access private
  57. * @since 3.2.0
  58. *
  59. * @param string $data External library data (passed by reference).
  60. */
  61. function _wp_credits_build_object_link( &$data ) {
  62. $data = '<a href="' . esc_url( $data[1] ) . '">' . esc_html( $data[0] ) . '</a>';
  63. }