wp/wp-admin/includes/credits.php
changeset 7 cf61fcea0001
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     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 		$results = json_decode( wp_remote_retrieve_body( $response ), true );
       
    42 
       
    43 		if ( ! is_array( $results ) )
       
    44 			return false;
       
    45 
       
    46 		set_site_transient( 'wordpress_credits_' . $locale, $results, DAY_IN_SECONDS );
       
    47 	}
       
    48 
       
    49 	return $results;
       
    50 }
       
    51 
       
    52 /**
       
    53  * Retrieve the link to a contributor's WordPress.org profile page.
       
    54  *
       
    55  * @access private
       
    56  * @since 3.2.0
       
    57  *
       
    58  * @param string $display_name  The contributor's display name (passed by reference).
       
    59  * @param string $username      The contributor's username.
       
    60  * @param string $profiles      URL to the contributor's WordPress.org profile page.
       
    61  */
       
    62 function _wp_credits_add_profile_link( &$display_name, $username, $profiles ) {
       
    63 	$display_name = '<a href="' . esc_url( sprintf( $profiles, $username ) ) . '">' . esc_html( $display_name ) . '</a>';
       
    64 }
       
    65 
       
    66 /**
       
    67  * Retrieve the link to an external library used in WordPress.
       
    68  *
       
    69  * @access private
       
    70  * @since 3.2.0
       
    71  *
       
    72  * @param string $data External library data (passed by reference).
       
    73  */
       
    74 function _wp_credits_build_object_link( &$data ) {
       
    75 	$data = '<a href="' . esc_url( $data[1] ) . '">' . esc_html( $data[0] ) . '</a>';
       
    76 }