@@ -49,6 +49,7 @@ function init() {
49
49
}
50
50
51
51
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 );
52
53
}
53
54
54
55
/**
@@ -129,3 +130,42 @@ function get_amp_github_releases() {
129
130
}
130
131
return json_decode ( $ raw_response ['body ' ] );
131
132
}
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