From 0ca162181352b752d11bdc92730807f3d13258ac Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:09:35 +1300 Subject: [PATCH] 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 --- .../src/release-tables/index.php | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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 f415cc8a..1d837fbd 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,36 @@ 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; + if ( ! $post ) { + return null; + } + + $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. * @@ -203,8 +233,19 @@ function render_table( $releases ) { * @return string Returns the row markup. */ function render_table_row( $version ) { + $version_number = $version['version']; + $microsite_url = find_microsite_url_for_version( $version_number ); + $row = '