Conditions | 7 |
Paths | 9 |
Total Lines | 68 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
21 | function advanced_custom_search($where, &$wp_query) |
||
22 | { |
||
23 | global $wpdb; |
||
1 ignored issue
–
show
|
|||
24 | |||
25 | if (empty($where)) { |
||
26 | return $where; |
||
27 | } |
||
28 | |||
29 | // get search expression |
||
30 | $terms = $wp_query->query_vars['s']; |
||
31 | |||
32 | // explode search expression to get search terms |
||
33 | $exploded = explode(' ', $terms); |
||
34 | |||
35 | if ($exploded === FALSE || count($exploded) == 0) { |
||
36 | $exploded = array(0 => $terms); |
||
37 | } |
||
38 | |||
39 | // reset search in order to rebuilt it as we whish |
||
40 | $where = ''; |
||
41 | |||
42 | // get searcheable_acf, a list of advanced custom fields you want to search content in |
||
43 | $list_searcheable_acf = list_searcheable_acf(); |
||
44 | |||
45 | foreach ($exploded as $tag) : |
||
46 | $where .= " |
||
47 | AND ( |
||
48 | (wp_posts.post_title LIKE '%$tag%') |
||
49 | OR (wp_posts.post_content LIKE '%$tag%') |
||
50 | OR EXISTS ( |
||
51 | SELECT * FROM wp_postmeta |
||
52 | WHERE post_id = wp_posts.ID |
||
53 | AND ("; |
||
54 | |||
55 | foreach ($list_searcheable_acf as $searcheable_acf) : |
||
56 | if ($searcheable_acf == $list_searcheable_acf[0]): |
||
57 | $where .= " (meta_key LIKE '%" . $searcheable_acf . "%' AND meta_value LIKE '%$tag%') "; |
||
58 | else : |
||
59 | $where .= " OR (meta_key LIKE '%" . $searcheable_acf . "%' AND meta_value LIKE '%$tag%') "; |
||
60 | endif; |
||
61 | endforeach; |
||
62 | |||
63 | $where .= ") |
||
64 | ) |
||
65 | OR EXISTS ( |
||
66 | SELECT * FROM wp_comments |
||
67 | WHERE comment_post_ID = wp_posts.ID |
||
68 | AND comment_content LIKE '%$tag%' |
||
69 | ) |
||
70 | OR EXISTS ( |
||
71 | SELECT * FROM wp_terms |
||
72 | INNER JOIN wp_term_taxonomy |
||
73 | ON wp_term_taxonomy.term_id = wp_terms.term_id |
||
74 | INNER JOIN wp_term_relationships |
||
75 | ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id |
||
76 | WHERE ( |
||
77 | taxonomy = 'post_tag' |
||
78 | OR taxonomy = 'category' |
||
79 | OR taxonomy = 'myCustomTax' |
||
80 | ) |
||
81 | AND object_id = wp_posts.ID |
||
82 | AND wp_terms.name LIKE '%$tag%' |
||
83 | ) |
||
84 | )"; |
||
85 | endforeach; |
||
86 | |||
87 | return $where; |
||
88 | } |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.