Ticket #44238: 44238.1.diff
File 44238.1.diff, 2.1 KB (added by , 7 years ago) |
---|
-
src/wp-includes/meta.php
952 952 function is_protected_meta( $meta_key, $meta_type = null ) { 953 953 $protected = ( '_' == $meta_key[0] ); 954 954 955 if( $meta_type ) { 956 /** 957 * Filters whether a meta key is considered protected. 958 * 959 * @since 5.0.0 960 * 961 * @param bool $protected Whether the key is considered protected. 962 * @param string $meta_key Meta key. 963 * @param string|null $meta_type Type of object metadata is for (e.g., comment, post, or user). 964 */ 965 $protected = apply_filters( "protected_{$meta_type}_meta_{$meta_key}", $protected, $meta_key, $meta_type ); 966 } 955 967 /** 956 968 * Filters whether a meta key is considered protected. 957 969 * … … 1026 1038 $wp_meta_keys = array(); 1027 1039 } 1028 1040 1041 $protected = ( '_' == $meta_key[0] ); 1042 1029 1043 $defaults = array( 1030 1044 'type' => 'string', 1031 1045 'description' => '', 1032 1046 'single' => false, 1047 'protected' => $protected, 1033 1048 'sanitize_callback' => null, 1034 1049 'auth_callback' => null, 1035 1050 'show_in_rest' => false, … … 1067 1082 $args = apply_filters( 'register_meta_args', $args, $defaults, $object_type, $meta_key ); 1068 1083 $args = wp_parse_args( $args, $defaults ); 1069 1084 1085 if ( $protected ) { 1086 $protected_callback = "__return_true"; 1087 } else { 1088 $protected_callback = "__return_false"; 1089 } 1090 1091 add_filter( "protected_{$meta_type}_meta_{$meta_key}", $protected_callback, 8, 1 ); 1092 1093 1070 1094 // If `auth_callback` is not provided, fall back to `is_protected_meta()`. 1071 1095 if ( empty( $args['auth_callback'] ) ) { 1072 1096 if ( is_protected_meta( $meta_key, $object_type ) ) { … … 1149 1173 remove_filter( "auth_{$object_type}_meta_{$meta_key}", $args['auth_callback'] ); 1150 1174 } 1151 1175 1176 if ( isset( $args['protected'] ) ) { 1177 if ( $args['protected'] ) { 1178 $protected_callback = "__return_true"; 1179 } else { 1180 $protected_callback = "__return_false"; 1181 } 1182 remove_filter( "protected_{$object_type}_meta_{$meta_key}", $protected_callback, 8 ); 1183 } 1184 1152 1185 unset( $wp_meta_keys[ $object_type ][ $meta_key ] ); 1153 1186 1154 1187 // Do some clean up