目录
一、背景
- 在使用wordpress的时候,有时候会用到wordpress的一些函数,或者xmlrpc等功能,往文章里面插入meta标签。(custom field)
- 自定义栏目/字段的数据以meta_key(字段/栏目名)->meta_value(值)的形式存放在wp_postmeta表内。
- 但是出于安全问题,以下划线开头的meta_key(字段/栏目名)被认为是保留字段,不允许用户添加。(某些seo插件会用到这些下划线的meta字段,譬如说 yoast和all in one seo)
二、参考文章
《Wordpress POST META_NAME校验绕过》
三、思路(wordpress版本大于4.8)
- 文件路径
/wordpress/wp-includes/meta.php: - 检测函数
function is_protected_meta( $meta_key, $meta_type = null ) {
4 $protected = ( '_' == $meta_key[0] );
7 /**
8 * Filters whether a meta key is protected.
9 *
10 * @since 3.2.0
11 *
12 * @param bool $protected Whether the key is protected. Default false.
13 * @param string $meta_key Meta key.
14 * @param string $meta_type Meta type.
15 */
16 return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
17 }
- 最关键的就是第4行了。
- 这里会判断meta字段的第一个字符是否为下划线。
- 我们在这里放行掉我们需要放行的那些字段就可以了。
四、demo
function is_protected_meta( $meta_key, $meta_type = null ) {
1 if($meta_key== '_metatest0' or $meta_key=='_metatest1' or $meta_key=='_metatest2' ){
2 $protected = false;
3 } else{
4 $protected = ( '_' == $meta_key[0] );
5 }
6
7 /**
8 * Filters whether a meta key is protected.
9 *
10 * @since 3.2.0
11 *
12 * @param bool $protected Whether the key is protected. Default false.
13 * @param string $meta_key Meta key.
14 * @param string $meta_type Meta type.
15 */
16 return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
17 }
http://xzh.i3geek.com
0 条评论