Skip to content

Commit

Permalink
Add settings link to plugin action links
Browse files Browse the repository at this point in the history
  • Loading branch information
b1ink0 committed Feb 13, 2025
1 parent c1e245d commit b7eeef7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/optimization-detective/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
add_action( 'admin_enqueue_scripts', 'od_enqueue_prime_url_metrics_scripts' );
add_action( 'enqueue_block_editor_assets', 'od_enqueue_block_editor_prime_url_metrics_scripts' );
add_filter( 'redirect_post_location', 'od_add_data_to_post_update_redirect_url_for_classic_editor' );
add_filter( 'plugin_action_links_' . OPTIMIZATION_DETECTIVE_MAIN_FILE, 'od_add_settings_action_link' );
// @codeCoverageIgnoreEnd
1 change: 1 addition & 0 deletions plugins/optimization-detective/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static function ( string $version ): void {
}

define( 'OPTIMIZATION_DETECTIVE_VERSION', $version );
define( 'OPTIMIZATION_DETECTIVE_MAIN_FILE', plugin_basename( __FILE__ ) );

Check warning on line 99 in plugins/optimization-detective/load.php

View check run for this annotation

Codecov / codecov/patch

plugins/optimization-detective/load.php#L99

Added line #L99 was not covered by tests

require_once __DIR__ . '/helper.php';

Expand Down
14 changes: 14 additions & 0 deletions plugins/optimization-detective/prime-url-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
'Resume',
'optimization-detective'
);
controlButton.classList.remove( 'updating-message' );
if ( abortController ) {
abortController.abort();
abortController = null;
Expand All @@ -84,6 +85,7 @@
// Start/resume processing
isProcessing = true;
controlButton.textContent = __( 'Pause', 'optimization-detective' );
controlButton.classList.add( 'updating-message' );
processBatches();
}
}
Expand All @@ -95,7 +97,18 @@
try {
while ( isProcessing ) {
if ( ! currentBatch ) {
controlButton.textContent = __(
'Getting next batch…',
'optimization-detective'
);

currentBatch = await getBatch( cursor );

controlButton.textContent = __(
'Pause',
'optimization-detective'
);

if ( ! currentBatch.batch.length ) {
isNextBatchAvailable = false;
break;
Expand Down Expand Up @@ -159,6 +172,7 @@
'optimization-detective'
);
controlButton.disabled = true;
controlButton.classList.remove( 'updating-message' );
iframe.src = 'about:blank';
iframe.width = '0';
iframe.height = '0';
Expand Down
28 changes: 27 additions & 1 deletion plugins/optimization-detective/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,30 @@ function od_render_optimization_detective_page(): void {
</div>
</div>
<?php
}
}

/**
* Adds a settings link to the plugin's action links.
*
* @since n.e.x.t
*
* @param string[]|mixed $links An array of plugin action links.
* @return string[]|mixed The modified list of actions.
*/
function od_add_settings_action_link( $links ) {
if ( ! is_array( $links ) ) {
return $links;

Check warning on line 86 in plugins/optimization-detective/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/optimization-detective/settings.php#L85-L86

Added lines #L85 - L86 were not covered by tests
}

return array_merge(
array(
'settings' => sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( admin_url( 'tools.php?page=od-optimization-detective' ) ),
esc_html__( 'Settings', 'optimization-detective' )
),
),
$links
);

Check warning on line 98 in plugins/optimization-detective/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/optimization-detective/settings.php#L89-L98

Added lines #L89 - L98 were not covered by tests
}
add_filter( 'plugin_action_links_' . OPTIMIZATION_DETECTIVE_MAIN_FILE, 'od_add_settings_action_link' );

Check warning on line 100 in plugins/optimization-detective/settings.php

View check run for this annotation

Codecov / codecov/patch

plugins/optimization-detective/settings.php#L100

Added line #L100 was not covered by tests

0 comments on commit b7eeef7

Please sign in to comment.