Skip to content

Commit

Permalink
Merge pull request #1558 from xwp/feature/1476-add-export-filter
Browse files Browse the repository at this point in the history
Add filter to allow more records in exports with tests
  • Loading branch information
marcinkrzeminski authored Oct 4, 2024
2 parents 1613cfa + 32175f3 commit a51ad95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion classes/class-connectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function load_connectors() {
}

// Initialize connector.
$class = new $class_name();
$class = new $class_name();
$classes[ $class->name ] = $class;
}

Expand Down
9 changes: 8 additions & 1 deletion classes/class-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ public function build_record( $item, $columns ) {
* @return int
*/
public function disable_paginate() {
return 10000;

/**
* Filter to change how many records are exported.
* Increasing this too much could cause your export to time out.
*
* @return int The number of records to export.
*/
return apply_filters( 'wp_stream_export_limit', 10000 );
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/test-class-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ public function test_disable_paginate() {
$this->assertEquals( $limit, 10000 );
}

/**
* Test pagination limit filter
*/
public function test_export_limit_filter() {
add_filter(
'wp_stream_export_limit',
static function () {
return 5;
}
);

$filtered_limit = $this->export->disable_paginate();
$this->assertEquals( $filtered_limit, 5 );

remove_all_filters( 'wp_stream_export_limit' );
}

/**
* Test for present columns returning
*/
Expand Down

0 comments on commit a51ad95

Please sign in to comment.