1 | <?php |
||||||
2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
||||||
3 | |||||||
4 | if ( ! defined( 'ABSPATH' ) ) exit; |
||||||
5 | |||||||
6 | /** |
||||||
7 | * WP Query class for querying WP database |
||||||
8 | * For more reference of arguments visit: https://gist.github.com/nirjharlo/5c6f8ac4cc5271f88376788e599c287b |
||||||
9 | * This class depends on WP pagenavi plugin: https://wordpress.org/plugins/wp-pagenavi/ |
||||||
10 | * |
||||||
11 | * @author Nirjhar Lo |
||||||
12 | * @package wp-plugin-framework |
||||||
13 | */ |
||||||
14 | if ( ! class_exists( 'Query' ) ) { |
||||||
15 | |||||||
16 | class Query { |
||||||
17 | |||||||
18 | |||||||
19 | /** |
||||||
20 | * @var Int |
||||||
21 | */ |
||||||
22 | public $display_count; |
||||||
23 | |||||||
24 | |||||||
25 | /** |
||||||
26 | * The post and user querying |
||||||
27 | * |
||||||
28 | * @return Void |
||||||
29 | */ |
||||||
30 | public function __construct() { |
||||||
31 | |||||||
32 | global $post, $user; |
||||||
33 | |||||||
34 | $this->display_count = get_option('posts_per_page', 10); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
35 | |||||||
36 | $paged = get_query_var('paged') ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1); |
||||||
0 ignored issues
–
show
The function
get_query_var was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
37 | |||||||
38 | $post_args = $this->post_args($paged); |
||||||
0 ignored issues
–
show
Are you sure the assignment to
$post_args is correct as $this->post_args($paged) targeting NirjharLo\WP_Plugin_Fram...\Src\Query::post_args() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
39 | $the_query = new WP_Query( $post_args ); |
||||||
0 ignored issues
–
show
The type
NirjharLo\WP_Plugin_Framework\Src\WP_Query was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
40 | |||||||
41 | /** |
||||||
42 | $user_args = $this->user_args($paged); |
||||||
43 | $the_query = new WP_User_Query( $user_args ); |
||||||
44 | */ |
||||||
45 | |||||||
46 | // The Loop |
||||||
47 | if ( $the_query->have_posts() ) { |
||||||
48 | while ( $the_query->have_posts() ) { |
||||||
49 | $the_query->the_post(); |
||||||
50 | // Do Stuff |
||||||
51 | } // end while |
||||||
52 | } // endif |
||||||
53 | |||||||
54 | if ( function_exists('wp_pagenavi' ) ) { |
||||||
55 | wp_pagenavi( array( 'query' => $the_query, 'echo' => true ) );//For user query add param 'type' => 'users' |
||||||
56 | } |
||||||
57 | |||||||
58 | // Reset Post Data |
||||||
59 | wp_reset_postdata(); |
||||||
0 ignored issues
–
show
The function
wp_reset_postdata was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
60 | } |
||||||
61 | |||||||
62 | |||||||
63 | /** |
||||||
64 | * User query arguments |
||||||
65 | * |
||||||
66 | * @return Void |
||||||
67 | */ |
||||||
68 | public function user_args( $paged ) { |
||||||
69 | |||||||
70 | $offset = ( $paged - 1 ) * $this->display_count; |
||||||
71 | |||||||
72 | $args = array ( |
||||||
73 | 'role' => '', // user role |
||||||
74 | 'order' => '', //ASC or DESC |
||||||
75 | 'fields' => '', // |
||||||
76 | 'orderby' => '', |
||||||
77 | 'role__in' => '', |
||||||
78 | 'role__not_in' => '', |
||||||
79 | 'include' => '', |
||||||
80 | 'exclude' => '', |
||||||
81 | 'blog_id' => '', |
||||||
82 | 'taxonomy' => '', |
||||||
83 | 'terms' => '', |
||||||
84 | 'number' => $this->display_count, |
||||||
85 | 'count_total' => true, |
||||||
86 | 'paged' => $paged, |
||||||
87 | 'offset' => $offset, |
||||||
88 | 'search' => '*' . esc_attr( $_GET['s'] ) . '*', |
||||||
0 ignored issues
–
show
The function
esc_attr was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
89 | 'meta_query' => array( // It supports nested meta query |
||||||
90 | 'relation' => 'AND', //or 'OR' |
||||||
91 | array( |
||||||
92 | 'key' => 'meta_key', |
||||||
93 | 'value' => 'some_value', |
||||||
94 | 'compare' => 'LIKE' //like others |
||||||
95 | ), |
||||||
96 | array( |
||||||
97 | 'key' => 'meta_key', |
||||||
98 | 'value' => 'some_value', |
||||||
99 | 'compare' => 'LIKE' //like others |
||||||
100 | ) |
||||||
101 | ) |
||||||
102 | ); |
||||||
103 | |||||||
104 | return $args; |
||||||
105 | } |
||||||
106 | |||||||
107 | |||||||
108 | /** |
||||||
109 | * Post query arguments |
||||||
110 | * |
||||||
111 | * @return Void |
||||||
112 | */ |
||||||
113 | public function post_args( $paged ) { |
||||||
114 | |||||||
115 | $offset = ( $paged - 1 ) * $this->display_count; |
||||||
116 | |||||||
117 | $args = array ( |
||||||
118 | 'post_type' => '', // array of type slugs |
||||||
119 | 'order' => 'ASC', |
||||||
120 | 'fields' => '', // |
||||||
121 | 'orderby' => '', |
||||||
122 | 'include' => '', |
||||||
123 | 'exclude' => '', |
||||||
124 | 'blog_id' => '', |
||||||
125 | 'taxonomy' => '', |
||||||
126 | 'terms' => '', |
||||||
127 | 'number' => $this->display_count, |
||||||
128 | 'count_total' => true, |
||||||
129 | 'paged' => $paged, |
||||||
130 | 'offset' => $offset, |
||||||
131 | 'search' => '*' . esc_attr( $_GET['s'] ) . '*', |
||||||
0 ignored issues
–
show
The function
esc_attr was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
132 | 'meta_query' => array( // It supports nested meta query |
||||||
133 | 'relation' => 'AND', //or 'OR' |
||||||
134 | array( |
||||||
135 | 'key' => 'meta_key', |
||||||
136 | 'value' => 'some_value', |
||||||
137 | 'compare' => 'LIKE' //like others |
||||||
138 | ), |
||||||
139 | array( |
||||||
140 | 'key' => 'meta_key', |
||||||
141 | 'value' => 'some_value', |
||||||
142 | 'compare' => 'LIKE' //like others |
||||||
143 | ) |
||||||
144 | ) |
||||||
145 | ); |
||||||
146 | |||||||
147 | return $args; |
||||||
148 | } |
||||||
149 | } |
||||||
150 | } ?> |
||||||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
|||||||
151 |