@@ -195,6 +195,36 @@ function render_table( $releases ) {
195
195
return $ table ;
196
196
}
197
197
198
+ /**
199
+ * Find the microsite url for a given version.
200
+ *
201
+ * @param string $version The version number to find the microsite url for.
202
+ *
203
+ * @return string|null Returns the microsite url if found, otherwise null.
204
+ */
205
+ function find_microsite_url_for_version ( $ version ) {
206
+ // attempt to find the microsite url only if the version number matches the format major.minor
207
+ if ( ! preg_match ( '/^\d+\.\d+$/ ' , $ version ) ) {
208
+ return null ;
209
+ }
210
+
211
+ global $ post ;
212
+ if ( ! $ post ) {
213
+ return null ;
214
+ }
215
+
216
+ $ child_pages = get_pages ( array ( 'child_of ' => $ post ->ID ) );
217
+ $ version_hyphenated = str_replace ( '. ' , '- ' , $ version );
218
+
219
+ foreach ( $ child_pages as $ child_page ) {
220
+ if ( $ version_hyphenated === $ child_page ->post_name ) {
221
+ return get_permalink ( $ child_page ->ID );
222
+ }
223
+ }
224
+
225
+ return null ;
226
+ }
227
+
198
228
/**
199
229
* Render a release row.
200
230
*
@@ -203,8 +233,19 @@ function render_table( $releases ) {
203
233
* @return string Returns the row markup.
204
234
*/
205
235
function render_table_row ( $ version ) {
236
+ $ version_number = $ version ['version ' ];
237
+ $ microsite_url = find_microsite_url_for_version ( $ version_number );
238
+
206
239
$ row = '<tr> ' ;
207
- $ row .= '<th class="wp-block-wporg-release-tables__cell-version" scope="row"> ' . esc_html ( $ version ['version ' ] ) . '</th> ' ;
240
+ $ row .= '<th class="wp-block-wporg-release-tables__cell-version" scope="row"> ' ;
241
+ $ row .= isset ( $ microsite_url )
242
+ ? sprintf (
243
+ '<a href="%1$s">%2$s</a> ' ,
244
+ esc_url ( $ microsite_url ),
245
+ esc_html ( $ version_number ),
246
+ )
247
+ : esc_html ( $ version_number );
248
+ $ row .= '</th> ' ;
208
249
$ row .= '<td class="wp-block-wporg-release-tables__cell-date"> ' . esc_html ( date_i18n ( get_option ( 'date_format ' ), $ version ['builton ' ] ) ) . '</td> ' ;
209
250
$ row .= sprintf ( '<td class="wp-block-wporg-release-tables__cell-zip"><a href="%1$s">zip</a><br /><small>(<a href="%1$s.md5">md5</a> · <a href="%1$s.sha1">sha1</a>)</small></td> ' , esc_url ( $ version ['zip_url ' ] ) );
210
251
0 commit comments