GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#35)
by Vincent
02:27
created

advancedCustomSearch.php ➔ list_searcheable_acf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
<?php
2
3
/**
4
 * [list_searcheable_acf list all the custom fields we want to include in our search query]
5
 * @return [array] [list of custom fields]
0 ignored issues
show
Documentation introduced by
The doc-type [array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
6
 */
7
function list_searcheable_acf()
8
{
9
    $list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
10
    return $list_searcheable_acf;
11
}
12
13
/**
14
 * [advanced_custom_search search that encompasses ACF/advanced custom fields and taxonomies and split expression before request]
15
 * @param  [query-part/string]      $where    [the initial "where" part of the search query]
0 ignored issues
show
Documentation introduced by
The doc-type [query-part/string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
16
 * @param  [object]                 $wp_query []
0 ignored issues
show
Documentation introduced by
The doc-type [object] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
17
 * @return [query-part/string]      $where    [the "where" part of the search query as we customized]
0 ignored issues
show
Documentation introduced by
The doc-type [query-part/string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

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.

Loading history...
18
 * see https://vzurczak.wordpress.com/2013/06/15/extend-the-default-wordpress-search/
19
 * credits to Vincent Zurczak for the base query structure/spliting tags section
20
 */
21
function advanced_custom_search($where, &$wp_query)
22
{
23
    global $wpdb;
1 ignored issue
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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
}