Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions inc/packages/admin/class-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,33 @@ class List_Table extends WP_Plugin_Install_List_Table {
/**
* Replace Add Plugins message with ours.
*
* Skip for WP versions prior to 6.9.0.
*
* @since WordPress 6.9.0
* @return void
*/
public function views() {
if ( ! is_wp_version_compatible( '6.9' ) ) {
parent::views();
return;
}

ob_start();
parent::views();
$views = ob_get_clean();

echo wp_kses_post(
str_replace(
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Intentional use of Core's text domain.
[ __( 'https://wordpress.org/plugins/' ), __( 'WordPress Plugin Directory' ) ],
[ esc_url( 'https://fair.pm/packages/plugins/' ), __( 'FAIR Package Directory', 'fair' ) ],
$views
)
);
preg_match( '|<a href="(?<url>[^"]+)">(?<text>[^>]+)<\/a>|', $views, $matches );
if ( ! empty( $matches['text'] ) ) {
$text_with_fair = str_replace( 'WordPress', 'FAIR', $matches['text'] );
$str = str_replace(
[ $matches['url'], $matches['text'] ],
[ __( 'https://fair.pm/packages/plugins/', 'fair' ), $text_with_fair ],
$matches[0]
);
}

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Replacements are escaped. The previous content is direct from Core.
echo str_replace( $matches[0], $str, $views );
}

/**
Expand Down
23 changes: 13 additions & 10 deletions inc/packages/admin/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ function bootstrap() {
add_filter( 'wp_list_table_class_name', __NAMESPACE__ . '\\maybe_override_list_table' );

// Needed for pre WordPress 6.9 compatibility.
global $wp_version;
if ( version_compare( $wp_version, '6.9-beta1', '<' ) ) {
if ( ! is_wp_version_compatible( '6.9' ) ) {
add_action( 'install_plugins_featured', __NAMESPACE__ . '\\replace_featured_message' );
add_action( 'admin_init', fn() => remove_action( 'install_plugins_featured', 'install_dashboard' ) );
}
Expand Down Expand Up @@ -87,14 +86,18 @@ function replace_featured_message() {
\display_plugins_table();
$views = ob_get_clean();

echo wp_kses_post(
str_replace(
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain -- Intentional use of Core's text domain.
[ __( 'https://wordpress.org/plugins/' ), __( 'WordPress Plugin Directory' ) ],
[ esc_url( 'https://fair.pm/packages/plugins/' ), __( 'FAIR Package Directory', 'fair' ) ],
$views
)
);
preg_match( '|<a href="(?<url>[^"]+)">(?<text>[^>]+)<\/a>|', $views, $matches );
if ( ! empty( $matches['text'] ) ) {
$text_with_fair = str_replace( 'WordPress', 'FAIR', $matches['text'] );
$str = str_replace(
[ $matches['url'], $matches['text'] ],
[ __( 'https://fair.pm/packages/plugins/', 'fair' ), $text_with_fair ],
$matches[0]
);
}

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Replacements are escaped. The previous content is direct from Core.
echo str_replace( $matches[0], $str, $views );
}

/**
Expand Down