函数文档

install_theme_search_form()

💡 云策文档标注

概述

install_theme_search_form() 函数用于在 WordPress 后台显示主题搜索表单,支持通过关键词搜索主题,并可选择是否显示类型选择器。

关键要点

  • 函数定义:install_theme_search_form( $type_selector = true ),其中 $type_selector 参数可选,默认为 true,控制是否显示类型选择器。
  • 功能:输出一个搜索表单,包含搜索输入框和可选的主题类型筛选,用于在主题安装页面进行主题搜索。
  • 相关函数:涉及 submit_button()、__()、esc_attr() 等辅助函数,用于生成按钮、翻译文本和转义属性。

代码示例

// 调用函数,显示带类型选择器的搜索表单
install_theme_search_form();

// 调用函数,不显示类型选择器
install_theme_search_form( false );

注意事项

  • 函数从 WordPress 2.8.0 版本引入,属于后台主题安装功能的一部分。
  • 使用 wp_unslash() 处理请求参数以防止斜杠转义问题。
  • 表单元素使用 esc_attr() 进行属性转义,确保安全性。

📄 原文内容

Displays search form for searching themes.

Parameters

$type_selectorbooloptional

Default:true

Source

function install_theme_search_form( $type_selector = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? wp_unslash( $_REQUEST['s'] ) : '';
if ( ! $type_selector ) {
echo '<p class="install-help">' . __( 'Search for themes by keyword.' ) . '</p>';
}
?>
<form id="search-themes" method="get">
<input type="hidden" name="tab" value="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>
<label class="screen-reader-text" for="s">

</label>

<label class="screen-reader-text" for="s">

</label>

<input type="search" name="s" id="s" size="30" value="<?php echo esc_attr( $term ); ?>" autofocus="autofocus" />

</form>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/theme-install.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/theme-install.php#L91">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/theme-install.php#L91-L142">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.

__()wp-includes/l10n.php

Retrieves the translation of $text.

_e()wp-includes/l10n.php

Displays translated 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
install_themes_dashboard()wp-admin/includes/theme-install.php

Displays tags filter for themes.

Changelog

Version Description
2.8.0 Introduced.