-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into testStatus
- Loading branch information
Showing
17 changed files
with
374 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
components/admin-notification/views/admin-notification-new-tests-added.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="vrts-notice notice notice-success" data-view="<?php echo esc_attr( $data['view'] ); ?>"> | ||
<?php wp_nonce_field( 'vrts_admin_notice_nonce' ); ?> | ||
<h3><?php esc_html_e( 'Tests added successfully', 'visual-regression-tests' ); ?></h3> | ||
<p> | ||
<?php | ||
printf( | ||
/* translators: %s: the title of the page. */ | ||
esc_html__( 'Tests will be run for the following pages: %s', 'visual-regression-tests' ), | ||
esc_html( $data['page_titles'] ) | ||
); | ||
?> | ||
</p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Vrts\Features; | ||
|
||
use Vrts\Services\Test_Service; | ||
|
||
class Bulk_Actions { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
add_action( 'admin_init', function() { | ||
$post_types = vrts()->get_public_post_types(); | ||
|
||
foreach ( $post_types as $post_type ) { | ||
add_filter( 'bulk_actions-edit-' . $post_type, [ $this, 'register_bulk_test_option' ] ); | ||
add_filter( 'handle_bulk_actions-edit-' . $post_type, [ $this, 'handle_bulk_optimize_action' ], 10, 3 ); | ||
} | ||
} ); | ||
} | ||
|
||
/** | ||
* Register bulk optimize option. | ||
* | ||
* @param array $bulk_actions Bulk actions. | ||
* @return array | ||
*/ | ||
public function register_bulk_test_option( $bulk_actions ) { | ||
$bulk_actions['add-to-vrts'] = __( 'Add to VRTs', 'visual-regression-tests-service' ); | ||
|
||
return $bulk_actions; | ||
} | ||
|
||
/** | ||
* Handle bulk optimize action. | ||
* | ||
* @param string $redirect_to Redirect to. | ||
* @param string $doaction Action. | ||
* @param array $post_ids Post ids. | ||
* @return string | ||
*/ | ||
public function handle_bulk_optimize_action( $redirect_to, $doaction, $post_ids ) { | ||
if ( 'add-to-vrts' !== $doaction ) { | ||
return $redirect_to; | ||
} | ||
|
||
$service = new Test_Service(); | ||
$created_tests = $service->create_tests( $post_ids ); | ||
$vrts_url = admin_url( 'admin.php?page=vrts' ); | ||
|
||
if ( is_wp_error( $created_tests ) ) { | ||
$redirect_to = add_query_arg([ | ||
'new-test-failed' => true, | ||
], $vrts_url); | ||
} else { | ||
$redirect_to = add_query_arg([ | ||
'message' => 'success', | ||
'new-tests-added' => true, | ||
'post_ids' => wp_list_pluck( $created_tests, 'post_id' ), | ||
], $vrts_url); | ||
} | ||
|
||
return $redirect_to; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.