
如何实现WordPress网站降级(用于解决插件和主题问题)
sanitize_bookmark_field ( $field, $value, $bookmark_id, $context )
sanitize_bookmark_field: 这是一个WordPress的函数,可以对书签对象的一个特定字段进行净化。它用于验证和净化书签的一个特定字段,如名称或描述: 这个函数需要三个参数:书签对象,字段的名称,以及该字段被净化的背景。
净化一个书签字段。
根据字段的名称对书签字段进行净化。如果该字段有一个严格的值设置,那么它将被测试,否则将应用一个更通用的过滤。在应用了更严格的过滤后,如果`$context`是’raw’,那么该值将立即返回。
钩子存在于更通用的情况下。在’edit’上下文中,{@see ‘edit_$field’}过滤器将被调用并分别传递`$value’和`$bookmark_id’。
在’db’上下文中,{@see ‘pre_$field’}过滤器会被调用并传递值。’display’上下文是最终的上下文,`$field’有过滤器名称,并分别传递`$value’、`$bookmark_id’和`$context’。
function sanitize_bookmark_field( $field, $value, $bookmark_id, $context ) { $int_fields = array( 'link_id', 'link_rating' ); if ( in_array( $field, $int_fields, true ) ) { $value = (int) $value; } switch ( $field ) { case 'link_category': // array( ints ) $value = array_map( 'absint', (array) $value ); // We return here so that the categories aren't filtered. // The 'link_category' filter is for the name of a link category, not an array of a link's link categories. return $value; case 'link_visible': // bool stored as Y|N $value = preg_replace( '/[^YNyn]/', '', $value ); break; case 'link_target': // "enum" $targets = array( '_top', '_blank' ); if ( ! in_array( $value, $targets, true ) ) { $value = ''; } break; } if ( 'raw' === $context ) { return $value; } if ( 'edit' === $context ) { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "edit_{$field}", $value, $bookmark_id ); if ( 'link_notes' === $field ) { $value = esc_html( $value ); // textarea_escaped } else { $value = esc_attr( $value ); } } elseif ( 'db' === $context ) { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "pre_{$field}", $value ); } else { /** This filter is documented in wp-includes/post.php */ $value = apply_filters( "{$field}", $value, $bookmark_id, $context ); if ( 'attribute' === $context ) { $value = esc_attr( $value ); } elseif ( 'js' === $context ) { $value = esc_js( $value ); } } // Restore the type for integer fields after esc_attr(). if ( in_array( $field, $int_fields, true ) ) { $value = (int) $value; } return $value; }