| @@ -54,13 +54,24 @@ | ||
| 54 | 54 | * @return array |
| 55 | 55 | */ |
| 56 | 56 | $record = apply_filters( 'wp_stream_record_array', $record ); |
| 57 | 57 | |
| 58 | - $data = $this->sanitize_record( $record ); | |
| 59 | - if ( empty( $data ) ) { | |
| 58 | + array_walk( | |
| 59 | + $record, | |
| 60 | + function( &$value, &$key ) { | |
| 61 | + if ( ! is_array( $value ) ) { | |
| 62 | + $value = wp_strip_all_tags( $value ); | |
| 63 | + } | |
| 64 | + } | |
| 65 | + ); | |
| 66 | + | |
| 67 | + if ( empty( $record ) ) { | |
| 60 | 68 | return false; |
| 61 | 69 | } |
| 62 | 70 | |
| 71 | + $fields = array( 'object_id', 'site_id', 'blog_id', 'user_id', 'user_role', 'created', 'summary', 'ip', 'connector', 'context', 'action', 'meta' ); | |
| 72 | + $data = array_intersect_key( $record, array_flip( $fields ) ); | |
| 73 | + | |
| 63 | 74 | $record_id = $this->driver->insert_record( $data ); |
| 64 | 75 | |
| 65 | 76 | if ( ! $record_id ) { |
| 66 | 77 | /** |
| @@ -82,51 +93,8 @@ | ||
| 82 | 93 | */ |
| 83 | 94 | do_action( 'wp_stream_record_inserted', $record_id, $record ); |
| 84 | 95 | |
| 85 | 96 | return absint( $record_id ); |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * Ensure the record matches our schema. | |
| 90 | - * | |
| 91 | - * @param array $record Record to store. | |
| 92 | - * | |
| 93 | - * @return array | |
| 94 | - */ | |
| 95 | - protected function sanitize_record( $record ) { | |
| 96 | - if ( ! is_array( $record ) ) { | |
| 97 | - return array(); | |
| 98 | - } | |
| 99 | - | |
| 100 | - $record_defaults = array( | |
| 101 | - 'object_id' => null, | |
| 102 | - 'site_id' => null, | |
| 103 | - 'blog_id' => null, | |
| 104 | - 'user_id' => null, | |
| 105 | - 'user_role' => null, | |
| 106 | - 'created' => null, | |
| 107 | - 'summary' => null, | |
| 108 | - 'ip' => null, | |
| 109 | - 'connector' => null, | |
| 110 | - 'context' => null, | |
| 111 | - 'action' => null, | |
| 112 | - 'meta' => array(), | |
| 113 | - ); | |
| 114 | - | |
| 115 | - // Records can have only these fields. | |
| 116 | - $record = array_intersect_key( $record, $record_defaults ); | |
| 117 | - | |
| 118 | - // Sanitize all record values. | |
| 119 | - return array_map( | |
| 120 | - function ( $value ) { | |
| 121 | - if ( ! is_array( $value ) ) { | |
| 122 | - return wp_strip_all_tags( $value ); | |
| 123 | - } | |
| 124 | - | |
| 125 | - return $value; | |
| 126 | - }, | |
| 127 | - $record | |
| 128 | - ); | |
| 129 | 97 | } |
| 130 | 98 | |
| 131 | 99 | /** |
| 132 | 100 | * Returns array of existing values for requested column. |