| 1014 | * Allow 'meta_query' to persist during wp(). |
| 1015 | * |
| 1016 | * @since 4.0.0 |
| 1017 | * @access private |
| 1018 | * |
| 1019 | * @param array $q Query vars constructed during WP->parse_request(). |
| 1020 | * @return array The altered query vars. |
| 1021 | */ |
| 1022 | function _wp_filter_attachment_search( $q ) { |
| 1023 | remove_filter( 'request', __FUNCTION__ ); |
| 1024 | |
| 1025 | $q['meta_query'] = array( |
| 1026 | 'relation' => 'OR', |
| 1027 | array( |
| 1028 | 'key' => '_wp_attached_file', |
| 1029 | 'value' => $q['s'], |
| 1030 | 'compare' => 'LIKE' |
| 1031 | ) |
| 1032 | ); |
| 1033 | return $q; |
| 1034 | } |
| 1035 | |
| 1036 | /** |
| 1037 | * Filter meta SQL to mark this search criteria as optional. |
| 1038 | * |
| 1039 | * @since 4.0.0 |
| 1040 | * @access private |
| 1041 | * |
| 1042 | * @param array $sql WHERE and JOIN SQL clauses. |
| 1043 | * @return array The filtered clauses. |
| 1044 | */ |
| 1045 | function _wp_filter_attachment_meta_sql( $sql ) { |
| 1046 | remove_filter( 'get_meta_sql', __FUNCTION__ ); |
| 1047 | |
| 1048 | /* |
| 1049 | * Split AND-operated WHERE sub-clauses into an OR-operated clause group. |
| 1050 | * This serves to mark the meta search criteria optional as a group. |
| 1051 | */ |
| 1052 | if ( 0 === strpos( $sql['where'], ' AND (' ) ) { |
| 1053 | list( $_, $clauses ) = explode( ' AND ', $sql['where'], 2 ); |
| 1054 | $sql['where'] = " OR ({$clauses})"; |
| 1055 | } |
| 1056 | return $sql; |
| 1057 | } |
| 1058 | |
| 1059 | /** |