Skip to content

Commit 0ca1621

Browse files
authored
Releases Archive: Link releases to microsites (#345)
* Link the version number column to the microsite if it exists * Attempt to find microsite in child pages and fix escaping * Check if $post is null
1 parent b5c0c6a commit 0ca1621

File tree

1 file changed

+42
-1
lines changed
  • source/wp-content/themes/wporg-main-2022/src/release-tables

1 file changed

+42
-1
lines changed

source/wp-content/themes/wporg-main-2022/src/release-tables/index.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,36 @@ function render_table( $releases ) {
195195
return $table;
196196
}
197197

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+
198228
/**
199229
* Render a release row.
200230
*
@@ -203,8 +233,19 @@ function render_table( $releases ) {
203233
* @return string Returns the row markup.
204234
*/
205235
function render_table_row( $version ) {
236+
$version_number = $version['version'];
237+
$microsite_url = find_microsite_url_for_version( $version_number );
238+
206239
$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>';
208249
$row .= '<td class="wp-block-wporg-release-tables__cell-date">' . esc_html( date_i18n( get_option( 'date_format' ), $version['builton'] ) ) . '</td>';
209250
$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> &#183; <a href="%1$s.sha1">sha1</a>)</small></td>', esc_url( $version['zip_url'] ) );
210251

0 commit comments

Comments
 (0)