Merge pull request 'Point plugin metadata links at Unsupervised and Gitea' (#92) from feature/view-details-gitea-releases into main
CI / Tests (PHP 8.1) (push) Successful in 42s
CI / Tests (PHP 8.2) (push) Successful in 44s
CI / No Debug Code (push) Successful in 2s
CI / Tests (PHP 8.3) (push) Successful in 2m39s
CI / PHPStan (push) Successful in 2m46s
CI / Coding Standards (push) Successful in 3m2s
CI / Build Plugin Zip (push) Successful in 2m46s
CI / Tests (PHP 8.1) (push) Successful in 42s
CI / Tests (PHP 8.2) (push) Successful in 44s
CI / No Debug Code (push) Successful in 2s
CI / Tests (PHP 8.3) (push) Successful in 2m39s
CI / PHPStan (push) Successful in 2m46s
CI / Coding Standards (push) Successful in 3m2s
CI / Build Plugin Zip (push) Successful in 2m46s
Reviewed-on: #92
This commit was merged in pull request #92.
This commit is contained in:
@@ -35,6 +35,43 @@ class UpdateChecker {
|
|||||||
|
|
||||||
public function register(): void {
|
public function register(): void {
|
||||||
add_filter( 'update_plugins_' . self::HOSTNAME, [ $this, 'provideUpdate' ], 10, 3 );
|
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,10 +35,45 @@ class UpdateCheckerTest extends TestCase
|
|||||||
public function testRegisterHooksHostnameFilter(): void
|
public function testRegisterHooksHostnameFilter(): void
|
||||||
{
|
{
|
||||||
Filters\expectAdded('update_plugins_git.unsupervised.ca')->once();
|
Filters\expectAdded('update_plugins_git.unsupervised.ca')->once();
|
||||||
|
Filters\expectAdded('plugin_row_meta')->once();
|
||||||
|
|
||||||
(new UpdateChecker())->register();
|
(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
|
public function testOffersUpdateWhenReleaseIsNewer(): void
|
||||||
{
|
{
|
||||||
Functions\when('plugin_basename')->justReturn(self::PLUGIN_FILE);
|
Functions\when('plugin_basename')->justReturn(self::PLUGIN_FILE);
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Plugin Name: Unsupervised Scheduler
|
* 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.
|
* Description: Instructor/student lesson scheduling for WordPress.
|
||||||
* Version: 1.1.0
|
* Version: 1.1.0
|
||||||
* Requires at least: 6.2
|
* Requires at least: 6.2
|
||||||
* Requires PHP: 8.1
|
* Requires PHP: 8.1
|
||||||
* Author: Unsupervised
|
* Author: Unsupervised
|
||||||
|
* Author URI: https://unsupervised.ca
|
||||||
* License: GPL-2.0-or-later
|
* License: GPL-2.0-or-later
|
||||||
* Text Domain: unsupervised-schedular
|
* Text Domain: unsupervised-schedular
|
||||||
* Update URI: https://git.unsupervised.ca/Unsupervised/unsupervised-scheduler
|
* Update URI: https://git.unsupervised.ca/Unsupervised/unsupervised-scheduler
|
||||||
|
|||||||
Reference in New Issue
Block a user