media_upload_max_image_resize()
概述
media_upload_max_image_resize() 函数用于在媒体上传界面显示一个复选框,允许用户选择是否缩放图像。它基于用户设置和权限条件来生成HTML输出。
关键要点
- 函数显示一个复选框,用于控制图像缩放,其状态由用户设置 'upload_resize' 决定。
- 使用 get_user_setting() 获取用户设置,current_user_can() 检查用户权限(如 manage_options)。
- 输出包含HTML表单元素,如 input 和 label,并支持国际化(__())和URL清理(esc_url())。
- 自 WordPress 3.3.0 版本引入,是媒体上传功能的一部分。
代码示例
function media_upload_max_image_resize() {
$checked = get_user_setting( 'upload_resize' ) ? ' checked="true"' : '';
$a = '';
$end = '';
if ( current_user_can( 'manage_options' ) ) {
$a = '';
$end = '';
}
?>
/>
} Displays the checkbox to scale images.
Source
function media_upload_max_image_resize() {
$checked = get_user_setting( 'upload_resize' ) ? ' checked="true"' : '';
$a = '';
$end = '';
if ( current_user_can( 'manage_options' ) ) {
$a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">';
$end = '</a>';
}
?>
<p class="hide-if-no-js"><label>
<input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
</label></p>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/media.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/media.php#L3077">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/media.php#L3077-L3097">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/get_user_setting/">get_user_setting()</a><code>wp-includes/option.php
Retrieves user interface setting value based on setting name.
current_user_can()wp-includes/capabilities.php
Returns whether the current user has the specified capability.
__()wp-includes/l10n.php
Retrieves the translation of $text.
esc_url()wp-includes/formatting.php
Checks and cleans a URL.
admin_url()wp-includes/link-template.php
Retrieves the URL to the admin area for the current site.
get_option()wp-includes/option.php
Retrieves an option value based on an option name.
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |