WordPress 安全过滤数组 内容

WordPress在日常主题插件开发中,保存内容时需要使用 sanitize_text_field 函数来保证数据的安全。

Clean everything, check everything, escape everything, and never trust the users to always have input sane data. After all, users come from all walks of life.

但是当我们需要保存一个数组时,比如多个input框,使用同一个name时,就需要用到。这里我们写一个具体的函数

function sanitize_text_or_array_field($array_or_string)  	{  		if (is_string($array_or_string)) {  			$array_or_string = sanitize_text_field($array_or_string);  		} elseif (is_array($array_or_string)) {  			foreach ($array_or_string as $key => &$value) {  				if (is_array($value)) {  					$value = $this->sanitize_text_or_array_field($value);  				} else {  					$value = sanitize_text_field($value);  				}  			}  		}    		return $array_or_string;  	}

腾讯云限时秒杀【点击购买】

搬瓦工,CN2高速线路,1GB带宽,电信联通优化KVM,延迟低,速度快,建站稳定,搬瓦工BandwagonHost VPS优惠码BWH26FXH3HIQ,支持<支付宝> 【点击购买】!

Vultr$3.5日本节点,512M内存/500G流量/1G带宽,电信联通优化,延迟低,速度快【点击购买】!

阿里云香港、新加坡VPS/1核/1G/25G SSD/1T流量/30M带宽/年付¥288【点击购买】

WordPress 安全过滤数组 内容

`微信`扫码 加好友

链接到文章: https://gkxyz.com/wordpress-anquanguolushuzu-neirong.html

推荐站点

评论已关闭