函数文档

force_ssl_content()

💡 云策文档标注

概述

force_ssl_content() 函数用于确定是否强制在内容上使用 SSL,通过静态变量管理状态,并允许动态设置和获取强制状态。

关键要点

  • 函数接受一个可选的布尔参数 $force 来设置强制 SSL 状态,默认值为 null。
  • 返回值为布尔类型:true 表示强制 SSL,false 表示不强制。
  • 使用静态变量 $forced_content 来存储当前强制状态,确保状态在函数调用间持久化。
  • 当 $force 参数不为 null 时,函数设置新状态并返回旧状态;否则返回当前状态。
  • 该函数自 WordPress 2.8.5 版本引入,主要用于管理内容区域的 SSL 强制设置。

代码示例

function force_ssl_content( $force = null ) {
	static $forced_content = false;

	if ( ! is_null( $force ) ) {
		$old_forced     = $forced_content;
		$forced_content = (bool) $force;
		return $old_forced;
	}

	return $forced_content;
}

📄 原文内容

Determines whether to force SSL on content.

Parameters

$forcebool|nulloptional
Whether to force SSL in admin screens.

Default:null

Return

bool True if forced, false if not forced.

Source

function force_ssl_content( $force = null ) {
	static $forced_content = false;

	if ( ! is_null( $force ) ) {
		$old_forced     = $forced_content;
		$forced_content = (bool) $force;
		return $old_forced;
	}

	return $forced_content;
}

Changelog

Version Description
2.8.5 Introduced.