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