wp/wp-admin/includes/credits.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     9 
     9 
    10 /**
    10 /**
    11  * Retrieve the contributor credits.
    11  * Retrieve the contributor credits.
    12  *
    12  *
    13  * @since 3.2.0
    13  * @since 3.2.0
       
    14  * @since 5.6.0 Added the `$version` and `$locale` parameters.
    14  *
    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.
    15  * @return array|false A list of all of the contributors, or false on error.
    18  * @return array|false A list of all of the contributors, or false on error.
    16  */
    19  */
    17 function wp_credits() {
    20 function wp_credits( $version = '', $locale = '' ) {
    18 	// Include an unmodified $wp_version.
    21 	if ( ! $version ) {
    19 	require ABSPATH . WPINC . '/version.php';
    22 		// Include an unmodified $wp_version.
       
    23 		require ABSPATH . WPINC . '/version.php';
    20 
    24 
    21 	$locale = get_user_locale();
    25 		$version = $wp_version;
       
    26 	}
       
    27 
       
    28 	if ( ! $locale ) {
       
    29 		$locale = get_user_locale();
       
    30 	}
    22 
    31 
    23 	$results = get_site_transient( 'wordpress_credits_' . $locale );
    32 	$results = get_site_transient( 'wordpress_credits_' . $locale );
    24 
    33 
    25 	if ( ! is_array( $results )
    34 	if ( ! is_array( $results )
    26 		|| false !== strpos( $wp_version, '-' )
    35 		|| false !== strpos( $version, '-' )
    27 		|| ( isset( $results['data']['version'] ) && strpos( $wp_version, $results['data']['version'] ) !== 0 )
    36 		|| ( isset( $results['data']['version'] ) && strpos( $version, $results['data']['version'] ) !== 0 )
    28 	) {
    37 	) {
    29 		$url     = "http://api.wordpress.org/core/credits/1.1/?version={$wp_version}&locale={$locale}";
    38 		$url     = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}";
    30 		$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) );
    39 		$options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) );
    31 
    40 
    32 		if ( wp_http_supports( array( 'ssl' ) ) ) {
    41 		if ( wp_http_supports( array( 'ssl' ) ) ) {
    33 			$url = set_url_scheme( $url, 'https' );
    42 			$url = set_url_scheme( $url, 'https' );
    34 		}
    43 		}
    35 
    44 
    36 		$response = wp_remote_get( $url, $options );
    45 		$response = wp_remote_get( $url, $options );
    37 
    46 
    38 		if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
    47 		if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
    39 			return false;
    48 			return false;
    40 		}
    49 		}
    41 
    50 
    42 		$results = json_decode( wp_remote_retrieve_body( $response ), true );
    51 		$results = json_decode( wp_remote_retrieve_body( $response ), true );
    43 
    52 
   138 			$classes = 'wp-people-group ' . ( $compact ? 'compact' : '' );
   147 			$classes = 'wp-people-group ' . ( $compact ? 'compact' : '' );
   139 			echo '<ul class="' . $classes . '" id="wp-people-group-' . $slug . '">' . "\n";
   148 			echo '<ul class="' . $classes . '" id="wp-people-group-' . $slug . '">' . "\n";
   140 			foreach ( $group_data['data'] as $person_data ) {
   149 			foreach ( $group_data['data'] as $person_data ) {
   141 				echo '<li class="wp-person" id="wp-person-' . esc_attr( $person_data[2] ) . '">' . "\n\t";
   150 				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">';
   151 				echo '<a href="' . esc_url( sprintf( $credits_data['profiles'], $person_data[2] ) ) . '" class="web">';
   143 				$size   = $compact ? 40 : 80;
   152 				$size   = $compact ? 80 : 160;
   144 				$data   = get_avatar_data( $person_data[1] . '@md5.gravatar.com', array( 'size' => $size ) );
   153 				$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 ) );
   154 				$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";
   155 				echo '<span class="wp-person-avatar"><img src="' . esc_url( $data['url'] ) . '" srcset="' . esc_url( $data2x['url'] ) . ' 2x" class="gravatar" alt="" /></span>' . "\n";
   147 				echo esc_html( $person_data[0] ) . "</a>\n\t";
   156 				echo esc_html( $person_data[0] ) . "</a>\n\t";
   148 				if ( ! $compact ) {
   157 				if ( ! $compact ) {
   149 					// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
   158 					// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText
   150 					echo '<span class="title">' . translate( $person_data[3] ) . "</span>\n";
   159 					echo '<span class="title">' . translate( $person_data[3] ) . "</span>\n";
   151 				}
   160 				}