Skip to content

Commit b33c78a

Browse files
committed
Replace AMP beta plugin 'version details' link with the one to the release on GitHub
1 parent eeabc87 commit b33c78a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

amp-beta-tester.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function init() {
4949
}
5050

5151
add_filter( 'pre_set_site_transient_update_plugins', __NAMESPACE__ . '\update_amp_manifest' );
52+
add_action( 'after_plugin_row_' . AMP_PLUGIN_FILE, __NAMESPACE__ . '\replace_view_version_details_link', 10, 2 );
5253
}
5354

5455
/**
@@ -129,3 +130,42 @@ function get_amp_github_releases() {
129130
}
130131
return json_decode( $raw_response['body'] );
131132
}
133+
134+
/**
135+
* Replace the 'View version details' link with the link to the release on GitHub.
136+
*
137+
* @param string $file Plugin file.
138+
* @param array $plugin_data Plugin data.
139+
*/
140+
function replace_view_version_details_link( $file, $plugin_data ) {
141+
$plugin_version = $plugin_data['Version'];
142+
143+
if ( is_prerelease( $plugin_version ) ) {
144+
ob_start();
145+
?>
146+
<script>
147+
document.addEventListener('DOMContentLoaded', function() {
148+
const link = document.querySelectorAll("[data-slug='amp'] a.thickbox.open-plugin-details-modal");
149+
150+
link.forEach( (link) => {
151+
link.className = 'overridden'; // Override class so that onclick listeners are disabled.
152+
link.target = '_blank';
153+
link.href = '<?php echo $plugin_data['url']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>';
154+
} );
155+
}, false);
156+
</script>
157+
<?php
158+
159+
echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
160+
}
161+
}
162+
163+
/**
164+
* Determine if the supplied version code is a prerelease.
165+
*
166+
* @param string $plugin_version Plugin version code.
167+
* @return false|int
168+
*/
169+
function is_prerelease( $plugin_version ) {
170+
return preg_match( '/(beta|alpha)/', $plugin_version );
171+
}

0 commit comments

Comments
 (0)