Skip to content

Commit 39306dc

Browse files
committed
👌 IMPROVE: #50 - Stop pulling tasks after page number in settings
1 parent 2773fb3 commit 39306dc

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

‎classes/api_calls.php

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class wpcable_api_calls {
2525
*/
2626
public $auth_token = '';
2727

28+
/**
29+
* Get the option to know when to stop pulling tasks
30+
*
31+
* @var int
32+
*/
33+
private $tasks_stop_at_page = 0;
34+
2835
/**
2936
* Returns the singleton instance to the API object.
3037
*
@@ -45,6 +52,7 @@ public static function inst() {
4552
*/
4653
private function __construct() {
4754
$this->get_auth_token();
55+
$this->tasks_stop_at_page = (int) get_option( 'wpcable_tasks_stop_at_page', 0 );
4856
}
4957

5058
/**
@@ -176,6 +184,12 @@ public function tasks_page( $filter = 'preferred', $page = 1 ) {
176184
'per_page' => $num,
177185
];
178186

187+
// Stop at the next page before it does the call
188+
if ( $this->tasks_stop_at_page
189+
&& ( $this->tasks_stop_at_page + 1 ) === $page ) {
190+
return [];
191+
}
192+
179193
$tasks = $this->get_curl( $url, $args, 'get' );
180194

181195
return $tasks;

‎functions/admin-settings.php

+19-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function codeable_register_settings() {
7171
register_setting( 'wpcable_group', 'wpcable_fee_type' );
7272
register_setting( 'wpcable_group', 'wpcable_rate' );
7373
register_setting( 'wpcable_group', 'wpcable_cancel_after_days' );
74+
register_setting( 'wpcable_group', 'wpcable_tasks_stop_at_page' );
7475

7576
if ( ! codeable_api_logged_in() ) {
7677
register_setting( 'wpcable_group', 'wpcable_email' );
@@ -111,10 +112,11 @@ function codeable_handle_login( $value, $old_value ) {
111112
function codeable_settings_callback() {
112113
codeable_admin_notices();
113114

114-
$wpcable_email = get_option( 'wpcable_email' );
115-
$wpcable_rate = get_option( 'wpcable_rate', 80 );
116-
$wpcable_fee_type = get_option( 'wpcable_fee_type', 'client' );
117-
$wpcable_cancel_after_days = get_option( 'wpcable_cancel_after_days', 180 );
115+
$wpcable_email = get_option( 'wpcable_email' );
116+
$wpcable_rate = get_option( 'wpcable_rate', 80 );
117+
$wpcable_fee_type = get_option( 'wpcable_fee_type', 'client' );
118+
$wpcable_cancel_after_days = get_option( 'wpcable_cancel_after_days', 180 );
119+
$wpcable_tasks_stop_at_page = get_option( 'wpcable_tasks_stop_at_page', 0 );
118120

119121
$logout_url = wp_nonce_url(
120122
add_query_arg( 'action', 'logout' ),
@@ -163,6 +165,19 @@ function codeable_settings_callback() {
163165
</p>
164166
</td>
165167
</tr>
168+
<tr>
169+
<th scope="row">
170+
<label class="wpcable_label" for="wpcable_tasks_stop_at_page">
171+
<?php esc_html_e( 'Stop pulling tasks after page', 'wpcable' ); ?>
172+
</label>
173+
</th>
174+
<td>
175+
<input type="number" name="wpcable_tasks_stop_at_page" id="wpcable_tasks_stop_at_page" min="0" max="720" value="<?php echo (int) $wpcable_tasks_stop_at_page; ?>" /> pages
176+
<p class="description">
177+
<?php esc_html_e( 'Pull a specific number of pages for the tasks section. Default is 0 (pull all). We suggest setting it to 0 to retrieve ALL tasks the first time, and then set it to 1 or 2 to retrieve/update only the latest 1/2 pages.', 'wpcable' ); ?>
178+
</p>
179+
</td>
180+
</tr>
166181
</tbody>
167182
</table>
168183

0 commit comments

Comments
 (0)