函数文档

install_search_form()

💡 云策文档标注

概述

install_search_form() 函数用于在 WordPress 插件安装页面显示搜索表单,支持按类型和关键词筛选插件。该函数已弃用一个参数,但保持向后兼容。

关键要点

  • 函数用于生成插件搜索表单,包含输入框、类型选择器和提交按钮
  • 参数 $deprecated 已弃用,默认值为 true,不影响功能
  • 表单处理 $_REQUEST['type'] 和 $_REQUEST['s'] 来获取搜索类型和关键词
  • 使用 WordPress 核心函数如 wp_unslash()、esc_attr() 和国际化函数确保安全性和本地化
  • 自 WordPress 4.6.0 起 $type_selector 参数被弃用,函数自 2.7.0 引入

代码示例

注意事项

  • 此函数主要用于插件安装界面,不建议在主题或插件中直接调用,除非需要自定义类似功能
  • 由于参数已弃用,开发者应避免依赖 $deprecated 参数,未来版本可能移除
  • 确保使用 esc_attr() 等函数转义输出,防止 XSS 攻击

📄 原文内容

Displays a search form for searching plugins.

Parameters

$deprecatedbooloptional
Not used.

Default:true

Source

function install_search_form( $deprecated = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? urldecode( wp_unslash( $_REQUEST['s'] ) ) : '';
?>
<form class="search-form search-plugins" method="get">
<input type="hidden" name="tab" value="search" />
<label for="search-plugins"></label>
<input type="search" name="s" id="search-plugins" value="<?php echo esc_attr( $term ); ?>" class="wp-filter-search" />
<label class="screen-reader-text" for="typeselector">

</label>
<select name="type" id="typeselector">
<option value="term"<?php selected( 'term', $type ); ?>></option>
<option value="author"<?php selected( 'author', $type ); ?>></option>
<option value="tag"<?php selected( 'tag', $type ); ?>></option>
</select>
'search-submit' ) ); ?>
</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#L313">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/plugin-install.php#L313-L335">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/functions/submit_button/">submit_button()</a><code>wp-admin/includes/template.php

Echoes a submit button, with provided text and appropriate class(es).

_ex()wp-includes/l10n.php

Displays translated string with gettext context.

selected()wp-includes/general-template.php

Outputs the HTML selected attribute.

_e()wp-includes/l10n.php

Displays translated text.

__()wp-includes/l10n.php

Retrieves the translation of $text.

wp_unslash()wp-includes/formatting.php

Removes slashes from a string or recursively removes slashes from strings within an array.

esc_attr()wp-includes/formatting.php

Escaping for HTML attributes.

Show 4 moreShow less

Used by Description
WP_Plugin_Install_List_Table::views()wp-admin/includes/class-wp-plugin-install-list-table.php

Overrides parent views so we can use the filter bar display.

Changelog

Version Description
4.6.0 The $type_selector parameter was deprecated.
2.7.0 Introduced.