diff --git a/inc/packages/admin/class-list-table.php b/inc/packages/admin/class-list-table.php index 065ec588..1d2238b1 100644 --- a/inc/packages/admin/class-list-table.php +++ b/inc/packages/admin/class-list-table.php @@ -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>|', $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 ); } /** diff --git a/inc/packages/admin/namespace.php b/inc/packages/admin/namespace.php index 6b62a69a..ecd94444 100644 --- a/inc/packages/admin/namespace.php +++ b/inc/packages/admin/namespace.php @@ -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' ) ); } @@ -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>|', $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 ); } /**