Skip to content

Commit 920d0b2

Browse files
authored
dev: remove deprecated get_offset() use (#760)
1 parent d09ce7d commit 920d0b2

6 files changed

+27
-84
lines changed

includes/data/connection/class-coupon-connection-resolver.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,22 @@ public function get_query_args() {
116116
];
117117

118118
/**
119-
* Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support
120-
* to filter the WP_Query to support cursor pagination
119+
* Set the cursor args.
120+
*
121+
* @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support
121122
*/
122-
$cursor_offset = $this->get_offset();
123-
$query_args['graphql_cursor_offset'] = $cursor_offset;
124-
$query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<';
123+
$query_args['graphql_after_cursor'] = $this->get_after_offset();
124+
$query_args['graphql_before_cursor'] = $this->get_before_offset();
125+
$query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<';
125126

126127
/**
127128
* If the starting offset is not 0 sticky posts will not be queried as the automatic checks in wp-query don't
128129
* trigger due to the page parameter not being set in the query_vars, fixes #732
129130
*/
130-
if ( 0 !== $cursor_offset ) {
131+
if ( empty( $query_args['graphql_after_cursor'] ) && empty( $query_args['graphql_before_cursor'] ) ) {
131132
$query_args['ignore_sticky_posts'] = true;
132133
}
134+
133135
/**
134136
* Pass the graphql $args to the WP_Query
135137
*/

includes/data/connection/class-customer-connection-resolver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public function get_query_args() {
6161
$query_args['number'] = $this->get_query_amount() + 1;
6262

6363
/**
64-
* Set the graphql_cursor_offset which is used by Config::graphql_wp_user_query_cursor_pagination_support
65-
* to filter the WP_User_Query to support cursor pagination
64+
* Set the cursor args.
65+
*
66+
* @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support
6667
*/
67-
$cursor_offset = $this->get_offset();
68-
$query_args['graphql_cursor_offset'] = $cursor_offset;
69-
$query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<';
68+
$query_args['graphql_after_cursor'] = $this->get_after_offset();
69+
$query_args['graphql_before_cursor'] = $this->get_before_offset();
70+
$query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<';
7071

7172
$input_fields = [];
7273
if ( ! empty( $this->args['where'] ) ) {

includes/data/connection/class-order-item-connection-resolver.php

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function get_query() {
112112
}
113113
}
114114

115-
$cursor = absint( $this->get_offset() );
115+
$cursor = (int) $this->get_offset_for_cursor( $this->args['after'] ?? ( $this->args['before'] ?? 0 ) );
116116
$first = ! empty( $this->args['first'] ) ? $this->args['first'] : null;
117117
$last = ! empty( $this->args['last'] ) ? $this->args['last'] : null;
118118

@@ -171,35 +171,4 @@ public function get_ids() {
171171
public function is_valid_offset( $offset ) {
172172
return 'string' === gettype( $offset );
173173
}
174-
175-
/**
176-
* Get_offset
177-
*
178-
* This returns the offset to be used in the $query_args based on the $args passed to the
179-
* GraphQL query.
180-
*
181-
* @return int|mixed
182-
*/
183-
public function get_offset() {
184-
/**
185-
* Defaults
186-
*/
187-
$offset = 0;
188-
189-
/**
190-
* Get the $after offset
191-
*/
192-
if ( ! empty( $this->args['after'] ) ) {
193-
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
194-
$offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) );
195-
} elseif ( ! empty( $this->args['before'] ) ) {
196-
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
197-
$offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) );
198-
}
199-
200-
/**
201-
* Return the higher of the two values
202-
*/
203-
return $offset;
204-
}
205174
}

includes/data/connection/class-product-connection-resolver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ public function get_query_args() {
146146
}
147147

148148
/**
149-
* Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support
150-
* to filter the WP_Query to support cursor pagination
149+
* Set the cursor args.
150+
*
151+
* @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support
151152
*/
152-
$cursor_offset = $this->get_offset();
153-
$query_args['graphql_cursor_offset'] = $cursor_offset;
154-
$query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<';
153+
$query_args['graphql_after_cursor'] = $this->get_after_offset();
154+
$query_args['graphql_before_cursor'] = $this->get_before_offset();
155+
$query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<';
155156

156157
/**
157158
* Pass the graphql $args to the WP_Query

includes/data/connection/class-shipping-method-connection-resolver.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,4 @@ public function get_ids() {
8484
public function is_valid_offset( $offset ) {
8585
return is_string( $offset );
8686
}
87-
88-
/**
89-
* Get_offset
90-
*
91-
* This returns the offset to be used in the $query_args based on the $args passed to the
92-
* GraphQL query.
93-
*
94-
* @return int|mixed
95-
*/
96-
public function get_offset() {
97-
/**
98-
* Defaults
99-
*/
100-
$offset = 0;
101-
102-
/**
103-
* Get the $after offset
104-
*/
105-
if ( ! empty( $this->args['after'] ) ) {
106-
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
107-
$offset = substr( base64_decode( $this->args['after'] ), strlen( 'arrayconnection:' ) );
108-
} elseif ( ! empty( $this->args['before'] ) ) {
109-
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
110-
$offset = substr( base64_decode( $this->args['before'] ), strlen( 'arrayconnection:' ) );
111-
}
112-
113-
/**
114-
* Return the higher of the two values
115-
*/
116-
return $offset;
117-
}
11887
}

includes/data/connection/class-tax-rate-connection-resolver.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ public function get_query_args() {
6868
$query_args['items_per_page'] = min( max( absint( $first ), absint( $last ), 10 ), $this->query_amount ) + 1;
6969

7070
/**
71-
* Set the graphql_cursor_offset which is used by Config::graphql_wp_query_cursor_pagination_support
72-
* to filter the WP_Query to support cursor pagination
71+
* Set the cursor args.
72+
*
73+
* @see \WPGraphQL\Data\Config::graphql_wp_query_cursor_pagination_support
7374
*/
74-
$cursor_offset = $this->get_offset();
75-
$query_args['graphql_cursor_offset'] = $cursor_offset;
76-
$query_args['graphql_cursor_compare'] = ( ! empty( $last ) ) ? '>' : '<';
75+
$query_args['graphql_after_cursor'] = $this->get_after_offset();
76+
$query_args['graphql_before_cursor'] = $this->get_before_offset();
77+
$query_args['graphql_cursor_compare'] = ! empty( $last ) ? '>' : '<';
7778

7879
/**
7980
* If there's no orderby params in the inputArgs, set order based on the first/last argument

0 commit comments

Comments
 (0)