From b62cd020dc59cd012f1b2ea6afb184f96d399924 Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:11:27 +1300 Subject: [PATCH] Attempt to find microsite in child pages and fix escaping --- .../src/release-tables/index.php | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) 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 = '