is_protected_ajax_action

函数
is_protected_ajax_action ( No parameters )
返回值
  • (bool) True if the current Ajax action should be protected.
定义位置
相关方法
is_protected_meta_deprecated_functionis_protected_endpointwp_is_site_protected_by_basic_authwp_protect_special_option
引入
5.2.0
弃用
-

is_protected_ajax_action – 这个函数检查一个给定的Ajax动作是否被保护。如果该动作是受保护的,该函数返回true。

确定我们当前是否在处理一个应该防止WSOD的Ajax动作。

function is_protected_ajax_action() {
	if ( ! wp_doing_ajax() ) {
		return false;
	}

	if ( ! isset( $_REQUEST['action'] ) ) {
		return false;
	}

	$actions_to_protect = array(
		'edit-theme-plugin-file', // Saving changes in the core code editor.
		'heartbeat',              // Keep the heart beating.
		'install-plugin',         // Installing a new plugin.
		'install-theme',          // Installing a new theme.
		'search-plugins',         // Searching in the list of plugins.
		'search-install-plugins', // Searching for a plugin in the plugin install screen.
		'update-plugin',          // Update an existing plugin.
		'update-theme',           // Update an existing theme.
	);

	/**
	 * Filters the array of protected Ajax actions.
	 *
	 * This filter is only fired when doing Ajax and the Ajax request has an 'action' property.
	 *
	 * @since 5.2.0
	 *
	 * @param string[] $actions_to_protect Array of strings with Ajax actions to protect.
	 */
	$actions_to_protect = (array) apply_filters( 'wp_protected_ajax_actions', $actions_to_protect );

	if ( ! in_array( $_REQUEST['action'], $actions_to_protect, true ) ) {
		return false;
	}

	return true;
}

常见问题

FAQs
查看更多 >