[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> credits.php (source)

   1  <?php
   2  /**
   3   * WordPress Credits Administration API.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Retrieve the contributor credits.
  12   *
  13   * @since 3.2.0
  14   * @since 5.6.0 Added the `$version` and `$locale` parameters.
  15   *
  16   * @param string $version WordPress version. Defaults to the current version.
  17   * @param string $locale  WordPress locale. Defaults to the current user's locale.
  18   * @return array|false A list of all of the contributors, or false on error.
  19   */
  20  function wp_credits( $version = '', $locale = '' ) {
  21      if ( ! $version ) {
  22          // Include an unmodified $wp_version.
  23          require  ABSPATH . WPINC . '/version.php';
  24  
  25          $version = $wp_version;
  26      }
  27  
  28      if ( ! $locale ) {
  29          $locale = get_user_locale();
  30      }
  31  
  32      $results = get_site_transient( 'wordpress_credits_' . $locale );
  33  
  34      if ( ! is_array( $results )
  35          || false !== strpos( $version, '-' )
  36          || ( isset( $results['data']['version'] ) && strpos( $version, $results['data']['version'] ) !== 0 )
  37      ) {
  38          $url     = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}";
  39          $options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) );
  40  
  41          if ( wp_http_supports( array( 'ssl' ) ) ) {
  42              $url = set_url_scheme( $url, 'https' );
  43          }
  44  
  45          $response = wp_remote_get( $url, $options );
  46  
  47          if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
  48              return false;
  49          }
  50  
  51          $results = json_decode( wp_remote_retrieve_body( $response ), true );
  52  
  53          if ( ! is_array( $results ) ) {
  54              return false;
  55          }
  56  
  57          set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
  58      }
  59  
  60      return $results;
  61  }
  62  
  63  /**
  64   * Retrieve the link to a contributor's WordPress.org profile page.
  65   *
  66   * @access private
  67   * @since 3.2.0
  68   *
  69   * @param string $display_name  The contributor's display name (passed by reference).
  70   * @param string $username      The contributor's username.
  71   * @param string $profiles      URL to the contributor's WordPress.org profile page.
  72   */
  73  function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
  74      $display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
  75  }
  76  
  77  /**
  78   * Retrieve the link to an external library used in WordPress.
  79   *
  80   * @access private
  81   * @since 3.2.0
  82   *
  83   * @param string $data External library data (passed by reference).
  84   */
  85  function _wp_credits_build_object_link( &$data ) {
  86      $data = '<a href="' . esc_url( $data[1] ) . '">' . esc_html( $data[0] ) . '</a>';
  87  }
  88  
  89  /**
  90   * Displays the title for a given group of contributors.
  91   *
  92   * @since 5.3.0
  93   *
  94   * @param array $group_data The current contributor group.
  95   */
  96  function wp_credits_section_title( $group_data = array() ) {
  97      if ( ! count( $group_data ) ) {
  98          return;
  99      }
 100  
 101      if ( $group_data['name'] ) {
 102          if ( 'Translators' === $group_data['name'] ) {
 103              // Considered a special slug in the API response. (Also, will never be returned for en_US.)
 104              $title = _x( 'Translators', 'Translate this to be the equivalent of English Translators in your language for the credits page Translators section' );
 105          } elseif ( isset( $group_data['placeholders'] ) ) {
 106              // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
 107              $title = vsprintf( translate( $group_data['name'] ), $group_data['placeholders'] );
 108          } else {
 109              // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
 110              $title = translate( $group_data['name'] );
 111          }
 112  
 113          echo '<h2 class="wp-people-group-title">' . esc_html( $title ) . "</h2>\n";
 114      }
 115  }
 116  
 117  /**
 118   * Displays a list of contributors for a given group.
 119   *
 120   * @since 5.3.0
 121   *
 122   * @param array  $credits The credits groups returned from the API.
 123   * @param string $slug    The current group to display.
 124   */
 125  function wp_credits_section_list( $credits = array(), $slug = '' ) {
 126      $group_data   = isset( $credits['groups'][ $slug ] ) ? $credits['groups'][ $slug ] : array();
 127      $credits_data = $credits['data'];
 128      if ( ! count( $group_data ) ) {
 129          return;
 130      }
 131  
 132      if ( ! empty( $group_data['shuffle'] ) ) {
 133          shuffle( $group_data['data'] ); // We were going to sort by ability to pronounce "hierarchical," but that wouldn't be fair to Matt.
 134      }
 135  
 136      switch ( $group_data['type'] ) {
 137          case 'list':
 138              array_walk( $group_data['data'], '_wp_credits_add_profile_link', $credits_data['profiles'] );
 139              echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n";
 140              break;
 141          case 'libraries':
 142              array_walk( $group_data['data'], '_wp_credits_build_object_link' );
 143              echo '<p class="wp-credits-list">' . wp_sprintf( '%l.', $group_data['data'] ) . "</p>\n\n";
 144              break;
 145          default:
 146              $compact = 'compact' === $group_data['type'];
 147              $classes = 'wp-people-group ' . ( $compact ? 'compact' : '' );
 148              echo '<ul class="' . $classes . '" id="wp-people-group-' . $slug . '">' . "\n";
 149              foreach ( $group_data['data'] as $person_data ) {
 150                  echo '<li class="wp-person" id="wp-person-' . esc_attr( $person_data[2] ) . '">' . "\n\t";
 151                  echo '<a href="' . esc_url( sprintf( $credits_data['profiles'], $person_data[2] ) ) . '" class="web">';
 152                  $size   = $compact ? 80 : 160;
 153                  $data   = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size ) );
 154                  $data2x = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size * 2 ) );
 155                  echo '<span class="wp-person-avatar"><img src="' . esc_url( $data['url'] ) . '" srcset="' . esc_url( $data2x['url'] ) . ' 2x" class="gravatar" alt="" /></span>' . "\n";
 156                  echo esc_html( $person_data[0] ) . "</a>\n\t";
 157                  if ( ! $compact && ! empty( $person_data[3] ) ) {
 158                      // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
 159                      echo '<span class="title">' . translate( $person_data[3] ) . "</span>\n";
 160                  }
 161                  echo "</li>\n";
 162              }
 163              echo "</ul>\n";
 164              break;
 165      }
 166  }


Generated: Sun Dec 22 01:00:02 2024 Cross-referenced by PHPXref 0.7.1