Skip to content

Commit 70e0bbc

Browse files
committed
use private static functions where applicable
1 parent ecaa9ea commit 70e0bbc

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

no-offset-pagination-for-wordpress.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct() {
3434
add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 10, 2 );
3535
}
3636

37-
private function applies( $query, $direction = 'both' ) {
37+
private static function applies( $query, $direction = 'both' ) {
3838
$applies = false;
3939
if ( false === is_admin() ) {
4040
if ( true === $query->is_main_query() && ( true === isset( $_GET[ 'next' ] ) || true === isset( $_GET['prev'] ) ) ) {
@@ -57,7 +57,7 @@ private function applies( $query, $direction = 'both' ) {
5757
return $applies;
5858
}
5959

60-
private function get_direction( $query ) {
60+
private static function get_direction( $query ) {
6161
$direction = 'next';
6262
if ( true === $query->is_main_query() && true === isset( $_GET['prev'] ) ) {
6363
$direction = 'prev';
@@ -71,8 +71,8 @@ private function get_direction( $query ) {
7171
return $direction;
7272
}
7373

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 );
7676
if ( true === isset( $_GET[ $direction ] ) ) {
7777
return intval( $_GET[ $direction ] );
7878
} 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 ) {
8181
return null;
8282
}
8383

84-
private function reverse_order( $order ) {
84+
private static function reverse_order( $order ) {
8585
if ('DESC' === $order ) {
8686
$order = 'ASC';
8787
} else {
@@ -90,25 +90,25 @@ private function reverse_order( $order ) {
9090
return $order;
9191
}
9292

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 );
9595
if ( true === isset( $query->query_vars['order'] ) && false === empty( $query->query_vars['order'] ) ) {
9696
$order = $query->query_vars['order'];
9797
} else{
9898
$order = 'DESC';
9999
}
100100
if ( 'prev' === $direction ) {
101-
$order = $this->reverse_order( $order );
101+
$order = self::reverse_order( $order );
102102
}
103103
return $order;
104104
}
105105

106106
public function where( $where, $query ) {
107-
if ( true === $this->applies( $query ) ) {
107+
if ( true === self::applies( $query ) ) {
108108
global $wpdb;
109-
$post = get_post( $this->get_post_id( $query ) );
109+
$post = get_post( self::get_post_id( $query ) );
110110
if ( false === empty( $post ) ) {
111-
$order = $this->get_order( $query );
111+
$order = self::get_order( $query );
112112
$operator = ( 'DESC' !== $order ) ? '>' : '<';
113113
$where .= $wpdb->prepare( " AND ( {$wpdb->posts}.post_date, {$wpdb->posts}.ID ) {$operator} ( %s, %d )", $post->post_date, $post->ID );
114114
}
@@ -118,42 +118,42 @@ public function where( $where, $query ) {
118118
}
119119

120120
public function limit( $limit, $query ) {
121-
if ( true === $this->applies( $query ) ) {
121+
if ( true === self::applies( $query ) ) {
122122
global $wpdb;
123123
$limit = $wpdb->prepare( "LIMIT %d", $query->query_vars['posts_per_page'] );
124124
}
125125

126126
return $limit;
127127
}
128128

129-
private function get_orderby_param( $query ) {
129+
private static function get_orderby_param( $query ) {
130130
return ( true === isset( $query->query_vars['orderby'] ) && false === empty( $query->query_vars['orderby'] ) ) ? $query->query_vars['orderby'] : 'post_date';
131131
}
132132

133133
public function orderby( $orderby, $query ) {
134-
if ( true === $this->applies( $query ) ) {
134+
if ( true === self::applies( $query ) ) {
135135
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 );
138138
$orderby = "{$wpdb->posts}.{$orderby_param} {$order}, {$wpdb->posts}.ID {$order}";
139139
}
140140

141141
return $orderby;
142142
}
143143

144144
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 );
149149
$request = "SELECT * FROM (" . $request . ") as results ORDER BY results.{$orderby_param} {$order}, results.ID {$order}";
150150
}
151151

152152
return $request;
153153
}
154154

155155
public function pre_get_posts( $query ) {
156-
if ( true === $this->applies( $query ) ) {
156+
if ( true === self::applies( $query ) ) {
157157
$query->set( 'no_found_rows', true );
158158
}
159159
}

0 commit comments

Comments
 (0)