函数文档

display_plugins_table()

💡 云策文档标注

概述

display_plugins_table() 函数用于根据插件列表显示插件内容,主要处理不同插件安装场景下的输出逻辑。

关键要点

  • 函数根据 current_filter() 判断当前上下文,如 install_plugins_beta、install_plugins_featured 等,并输出相应提示信息。
  • 使用 WP_List_Table::display() 方法渲染插件表格。
  • 涉及国际化处理,使用 __() 函数进行文本翻译。
  • 在 install_plugins_favorites 场景下,检查用户参数和 wporg_favorites 选项,若无则直接返回。

代码示例

switch ( current_filter() ) {
    case 'install_plugins_beta':
        printf(
            /* translators: %s: URL to "Features as Plugins" page. */
            '' . __( 'You are using a development version of WordPress. These feature plugins are also under development. Learn more.' ) . '',
            'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
        );
        break;
    case 'install_plugins_featured':
        echo '';
        break;
    case 'install_plugins_recommended':
        echo '' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '';
        break;
    case 'install_plugins_favorites':
        if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
            return;
        }
        break;
}

注意事项

  • 函数依赖于全局变量 $wp_list_table 和 current_filter() 钩子。
  • 在 install_plugins_favorites 分支中,需确保用户参数或 wporg_favorites 选项存在,否则函数会提前返回。
  • 输出内容包含国际化字符串,需注意翻译上下文。

📄 原文内容

Displays plugin content based on plugin list.

Source

function display_plugins_table() {
global $wp_list_table;

switch ( current_filter() ) {
case 'install_plugins_beta':
printf(
/* translators: %s: URL to "Features as Plugins" page. */
'<p>' . __( 'You are using a development version of WordPress. These feature plugins are also under development. <a href="%s">Learn more</a>.' ) . '</p>',
'https://make.wordpress.org/core/handbook/about/release-cycle/features-as-plugins/'
);
break;
case 'install_plugins_featured':
echo '<br>';
break;
case 'install_plugins_recommended':
echo '<p>' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '</p>';
break;
case 'install_plugins_favorites':
if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) {
return;
}
break;
}
?>
<form id="plugin-filter" method="post">
display(); ?>
</form>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/plugin-install.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/plugin-install.php#L390">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/plugin-install.php#L390-L418">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/classes/wp_list_table/display/">WP_List_Table::display()</a><code>wp-admin/includes/class-wp-list-table.php

Displays the table.

current_filter()wp-includes/plugin.php

Retrieves the name of the current filter hook.

get_user_option()wp-includes/user.php

Retrieves user option that can be either per Site or per Network.

__()wp-includes/l10n.php

Retrieves the translation of $text.

Show 1 moreShow less

Used by Description
install_dashboard()wp-admin/includes/plugin-install.php

Displays the Featured tab of Add Plugins screen.

Changelog

Version Description
2.7.0 Introduced.