@@ -34,7 +34,7 @@ public function __construct() {
34
34
add_action ( 'pre_get_posts ' , array ( $ this , 'pre_get_posts ' ), 10 , 2 );
35
35
}
36
36
37
- private function applies ( $ query , $ direction = 'both ' ) {
37
+ private static function applies ( $ query , $ direction = 'both ' ) {
38
38
$ applies = false ;
39
39
if ( false === is_admin () ) {
40
40
if ( true === $ query ->is_main_query () && ( true === isset ( $ _GET [ 'next ' ] ) || true === isset ( $ _GET ['prev ' ] ) ) ) {
@@ -57,7 +57,7 @@ private function applies( $query, $direction = 'both' ) {
57
57
return $ applies ;
58
58
}
59
59
60
- private function get_direction ( $ query ) {
60
+ private static function get_direction ( $ query ) {
61
61
$ direction = 'next ' ;
62
62
if ( true === $ query ->is_main_query () && true === isset ( $ _GET ['prev ' ] ) ) {
63
63
$ direction = 'prev ' ;
@@ -71,8 +71,8 @@ private function get_direction( $query ) {
71
71
return $ direction ;
72
72
}
73
73
74
- private function get_post_id ( $ query = null ) {
75
- $ direction = $ this -> get_direction ( $ query );
74
+ private static function get_post_id ( $ query = null ) {
75
+ $ direction = self :: get_direction ( $ query );
76
76
if ( true === isset ( $ _GET [ $ direction ] ) ) {
77
77
return intval ( $ _GET [ $ direction ] );
78
78
} else if ( true === isset ( $ query ->query_vars ['nooffset ' ] ) && false === empty ( $ query ->query_vars ['nooffset ' ] ) ) {
@@ -81,7 +81,7 @@ private function get_post_id( $query = null ) {
81
81
return null ;
82
82
}
83
83
84
- private function reverse_order ( $ order ) {
84
+ private static function reverse_order ( $ order ) {
85
85
if ('DESC ' === $ order ) {
86
86
$ order = 'ASC ' ;
87
87
} else {
@@ -90,25 +90,25 @@ private function reverse_order( $order ) {
90
90
return $ order ;
91
91
}
92
92
93
- private function get_order ( $ query , $ direction = null ) {
94
- $ direction = $ this -> get_direction ( $ query );
93
+ private static function get_order ( $ query , $ direction = null ) {
94
+ $ direction = self :: get_direction ( $ query );
95
95
if ( true === isset ( $ query ->query_vars ['order ' ] ) && false === empty ( $ query ->query_vars ['order ' ] ) ) {
96
96
$ order = $ query ->query_vars ['order ' ];
97
97
} else {
98
98
$ order = 'DESC ' ;
99
99
}
100
100
if ( 'prev ' === $ direction ) {
101
- $ order = $ this -> reverse_order ( $ order );
101
+ $ order = self :: reverse_order ( $ order );
102
102
}
103
103
return $ order ;
104
104
}
105
105
106
106
public function where ( $ where , $ query ) {
107
- if ( true === $ this -> applies ( $ query ) ) {
107
+ if ( true === self :: applies ( $ query ) ) {
108
108
global $ wpdb ;
109
- $ post = get_post ( $ this -> get_post_id ( $ query ) );
109
+ $ post = get_post ( self :: get_post_id ( $ query ) );
110
110
if ( false === empty ( $ post ) ) {
111
- $ order = $ this -> get_order ( $ query );
111
+ $ order = self :: get_order ( $ query );
112
112
$ operator = ( 'DESC ' !== $ order ) ? '> ' : '< ' ;
113
113
$ where .= $ wpdb ->prepare ( " AND ( {$ wpdb ->posts }.post_date, {$ wpdb ->posts }.ID ) {$ operator } ( %s, %d ) " , $ post ->post_date , $ post ->ID );
114
114
}
@@ -118,42 +118,42 @@ public function where( $where, $query ) {
118
118
}
119
119
120
120
public function limit ( $ limit , $ query ) {
121
- if ( true === $ this -> applies ( $ query ) ) {
121
+ if ( true === self :: applies ( $ query ) ) {
122
122
global $ wpdb ;
123
123
$ limit = $ wpdb ->prepare ( "LIMIT %d " , $ query ->query_vars ['posts_per_page ' ] );
124
124
}
125
125
126
126
return $ limit ;
127
127
}
128
128
129
- private function get_orderby_param ( $ query ) {
129
+ private static function get_orderby_param ( $ query ) {
130
130
return ( true === isset ( $ query ->query_vars ['orderby ' ] ) && false === empty ( $ query ->query_vars ['orderby ' ] ) ) ? $ query ->query_vars ['orderby ' ] : 'post_date ' ;
131
131
}
132
132
133
133
public function orderby ( $ orderby , $ query ) {
134
- if ( true === $ this -> applies ( $ query ) ) {
134
+ if ( true === self :: applies ( $ query ) ) {
135
135
global $ wpdb ;
136
- $ order = $ this -> get_order ( $ query );
137
- $ orderby_param = $ this -> get_orderby_param ( $ query );
136
+ $ order = self :: get_order ( $ query );
137
+ $ orderby_param = self :: get_orderby_param ( $ query );
138
138
$ orderby = "{$ wpdb ->posts }. {$ orderby_param } {$ order }, {$ wpdb ->posts }.ID {$ order }" ;
139
139
}
140
140
141
141
return $ orderby ;
142
142
}
143
143
144
144
public function posts_request ( $ request , $ query ) {
145
- if ( true === $ this -> applies ( $ query , 'prev ' ) ) {
146
- $ orderby_param = $ this -> get_orderby_param ( $ query );
147
- $ order = $ this -> get_order ( $ query , 'prev ' );
148
- $ order = $ this -> reverse_order ( $ order );
145
+ if ( true === self :: applies ( $ query , 'prev ' ) ) {
146
+ $ orderby_param = self :: get_orderby_param ( $ query );
147
+ $ order = self :: get_order ( $ query , 'prev ' );
148
+ $ order = self :: reverse_order ( $ order );
149
149
$ request = "SELECT * FROM ( " . $ request . ") as results ORDER BY results. {$ orderby_param } {$ order }, results.ID {$ order }" ;
150
150
}
151
151
152
152
return $ request ;
153
153
}
154
154
155
155
public function pre_get_posts ( $ query ) {
156
- if ( true === $ this -> applies ( $ query ) ) {
156
+ if ( true === self :: applies ( $ query ) ) {
157
157
$ query ->set ( 'no_found_rows ' , true );
158
158
}
159
159
}
0 commit comments