diff --git a/source/wp-content/themes/wporg-main-2022/src/release-tables/index.php b/source/wp-content/themes/wporg-main-2022/src/release-tables/index.php index 0d66fabb..55f83a50 100644 --- a/source/wp-content/themes/wporg-main-2022/src/release-tables/index.php +++ b/source/wp-content/themes/wporg-main-2022/src/release-tables/index.php @@ -195,6 +195,31 @@ function render_table( $releases ) { return $table; } +/** + * Find the microsite url for a given version. + * + * @param string $version The version number to find the microsite url for. + * + * @return string|null Returns the microsite url if found, otherwise null. + */ +function find_microsite_url_for_version( $version ) { + // attempt to find the microsite url only if the version number matches the format major.minor + if ( ! preg_match( '/^\d+\.\d+$/', $version ) ) { + return null; + } + + global $post; + $child_pages = get_pages( array( 'child_of' => $post->ID ) ); + $version_hyphenated = str_replace( '.', '-', $version ); + + foreach ( $child_pages as $child_page ) { + if ( $version_hyphenated === $child_page->post_name ) { + return get_permalink( $child_page->ID ); + } + } + + return null; +} /** * Render a release row. @@ -204,20 +229,19 @@ function render_table( $releases ) { * @return string Returns the row markup. */ function render_table_row( $version ) { - // Link the version number column to the microsite if it exists. - // Microsite URL is expected to be https://wordpress.org/download/releases/{version}/ - $releases_with_microsites = array( '6.3', '6.4' ); $version_number = $version['version']; - $maybe_link_to_microsite = in_array( $version_number, $releases_with_microsites ) + $microsite_url = find_microsite_url_for_version( $version_number ); + + $row = ''; + $row .= ''; + $row .= isset( $microsite_url ) ? sprintf( - '%2$s', - esc_attr( $version_number ), + '%2$s', + esc_url( $microsite_url ), esc_html( $version_number ), ) : esc_html( $version_number ); - - $row = ''; - $row .= '' . $maybe_link_to_microsite . ''; + $row .= ''; $row .= '' . esc_html( date_i18n( get_option( 'date_format' ), $version['builton'] ) ) . ''; $row .= sprintf( 'zip
(md5 · sha1)', esc_url( $version['zip_url'] ) );