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


Generated: Sun Dec 8 01:00:03 2019 Cross-referenced by PHPXref 0.7.1