函数文档

wp_removable_query_args()

💡 云策文档标注

概述

wp_removable_query_args() 函数返回一个数组,包含应从 URL 中移除的一次性查询变量名称。该函数主要用于清理 URL,避免重复参数影响用户体验或功能。

关键要点

  • 函数返回一个字符串数组,列出可移除的查询变量名,如 'activate'、'message'、'updated' 等。
  • 通过 'removable_query_args' 过滤器,开发者可以自定义或扩展这个列表。
  • 该函数在 WordPress 4.4.0 版本中引入,常用于后台管理界面和自定义功能中。

代码示例

function wp_removable_query_args() {
    $removable_query_args = array(
        'activate',
        'activated',
        // ... 其他变量名
        'updated',
        'wp-post-new-reload',
    );
    return apply_filters( 'removable_query_args', $removable_query_args );
}

注意事项

  • 使用 apply_filters() 允许其他插件或主题修改返回的数组,增强灵活性。
  • 这些变量通常用于临时状态传递,移除后有助于保持 URL 简洁和避免重复操作。

📄 原文内容

Returns an array of single-use query variable names that can be removed from a URL.

Return

string[] An array of query variable names to remove from the URL.

Source

function wp_removable_query_args() {
	$removable_query_args = array(
		'activate',
		'activated',
		'admin_email_remind_later',
		'approved',
		'core-major-auto-updates-saved',
		'deactivate',
		'delete_count',
		'deleted',
		'disabled',
		'doing_wp_cron',
		'enabled',
		'error',
		'hotkeys_highlight_first',
		'hotkeys_highlight_last',
		'ids',
		'locked',
		'message',
		'same',
		'saved',
		'settings-updated',
		'skipped',
		'spammed',
		'trashed',
		'unspammed',
		'untrashed',
		'update',
		'updated',
		'wp-post-new-reload',
	);

	/**
	 * Filters the list of query variable names to remove.
	 *
	 * @since 4.2.0
	 *
	 * @param string[] $removable_query_args An array of query variable names to remove from a URL.
	 */
	return apply_filters( 'removable_query_args', $removable_query_args );
}

Hooks

apply_filters( ‘removable_query_args’, string[] $removable_query_args )

Filters the list of query variable names to remove.

Changelog

Version Description
4.4.0 Introduced.