Point plugin metadata links at Unsupervised and Gitea #92

Merged
thatguygriff merged 1 commits from feature/view-details-gitea-releases into main 2026-07-23 14:26:51 +00:00
3 changed files with 74 additions and 1 deletions
Showing only changes of commit 83be388186 - Show all commits
+37
View File
@@ -35,6 +35,43 @@ class UpdateChecker {
public function register(): void {
add_filter( 'update_plugins_' . self::HOSTNAME, [ $this, 'provideUpdate' ], 10, 3 );
add_filter( 'plugin_row_meta', [ $this, 'filterRowMeta' ], 10, 2 );
}
/**
* Replace core's "View details" link on the Plugins screen.
*
* Core points that link at the WordPress.org plugin-information API
* (`plugin-install.php?tab=plugin-information&plugin=…`), which 404s in a
* "Plugin not found" iframe for this off-directory plugin. We swap it for a
* direct link to the matching Gitea release tag page, opened in a new tab —
* embedding Gitea in the thickbox iframe would be blocked by its
* `X-Frame-Options: SAMEORIGIN` anyway.
*
* @param mixed $meta Row-meta links for the plugin.
* @param mixed $plugin_file Plugin file the meta belongs to.
* @return mixed The (possibly modified) row-meta array.
*/
public function filterRowMeta( mixed $meta, mixed $plugin_file ): mixed {
if ( ! is_array( $meta ) || plugin_basename( USC_PLUGIN_FILE ) !== $plugin_file ) {
return $meta;
}
// Drop core's WordPress.org "View details" thickbox link.
$meta = array_values(
array_filter(
$meta,
static fn( $item ): bool => ! ( is_string( $item ) && str_contains( $item, 'open-plugin-details-modal' ) )
)
);
$meta[] = sprintf(
'<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>',
esc_url( self::REPO_URL . '/releases/tag/v' . USC_VERSION ),
esc_html__( 'View details', 'unsupervised-schedular' )
);
return $meta;
}
/**
+35
View File
@@ -35,10 +35,45 @@ class UpdateCheckerTest extends TestCase
public function testRegisterHooksHostnameFilter(): void
{
Filters\expectAdded('update_plugins_git.unsupervised.ca')->once();
Filters\expectAdded('plugin_row_meta')->once();
(new UpdateChecker())->register();
}
public function testFilterRowMetaReplacesViewDetailsLinkForThisPlugin(): void
{
Functions\when('plugin_basename')->justReturn(self::PLUGIN_FILE);
$meta = [
'Version 1.0.0',
'<a href="https://wordpress.org/plugin-install.php?...&plugin=unsupervised-schedular" class="thickbox open-plugin-details-modal">View details</a>',
];
$result = (new UpdateChecker())->filterRowMeta($meta, self::PLUGIN_FILE);
// Core's thickbox modal link is gone.
foreach ($result as $item) {
self::assertStringNotContainsString('open-plugin-details-modal', $item);
}
// Replaced with a new-tab link to the Gitea release tag for USC_VERSION (1.0.0 in tests).
self::assertStringContainsString(
UpdateChecker::REPO_URL . '/releases/tag/v1.0.0',
end($result)
);
self::assertStringContainsString('target="_blank"', end($result));
}
public function testFilterRowMetaLeavesOtherPluginsUntouched(): void
{
Functions\when('plugin_basename')->justReturn(self::PLUGIN_FILE);
$meta = ['<a href="#" class="thickbox open-plugin-details-modal">View details</a>'];
$result = (new UpdateChecker())->filterRowMeta($meta, 'other-plugin/other-plugin.php');
self::assertSame($meta, $result);
}
public function testOffersUpdateWhenReleaseIsNewer(): void
{
Functions\when('plugin_basename')->justReturn(self::PLUGIN_FILE);
+2 -1
View File
@@ -1,12 +1,13 @@
<?php
/**
* Plugin Name: Unsupervised Scheduler
* Plugin URI: https://unsupervised.ca
* Plugin URI: https://git.unsupervised.ca/Unsupervised/unsupervised-scheduler
* Description: Instructor/student lesson scheduling for WordPress.
* Version: 1.1.0
* Requires at least: 6.2
* Requires PHP: 8.1
* Author: Unsupervised
* Author URI: https://unsupervised.ca
* License: GPL-2.0-or-later
* Text Domain: unsupervised-schedular
* Update URI: https://git.unsupervised.ca/Unsupervised/unsupervised-scheduler