Skip to content

Commit

Permalink
feat: automatically go to plugin settings after activation
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Jan 22, 2024
1 parent 5fa2c17 commit b0c5ea2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions alt-text-generator-gpt-vision.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: AI Alt Text Generator for GPT Vision
* Plugin URI: https://github.com/android-com-pl/wp-ai-alt-generator
* Description: Automatically generate alternative text for images using OpenAI's GPT Vision API.
* Version: 2.0.1
* Version: 2.0.2
* Requires at least: 6.3
* Requires PHP: 8.1
* Author: android.com.pl
Expand Down Expand Up @@ -39,8 +39,8 @@ public function __construct() {
add_action( 'enqueue_block_editor_assets', fn()=> $this->enqueue_script( 'editor' ) );
add_action( 'wp_enqueue_media', fn()=> $this->enqueue_script( 'media-modal', true ) );
add_action( 'admin_enqueue_scripts', fn()=> $this->enqueue_attachment_edit_page_script() );
/** @phpstan-ignore-next-line */
add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 4 );
add_action( 'activated_plugin', [ $this,'redirect_to_plugin_settings_after_activation' ] );
add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 );
}

public static function get_options(): array|false {
Expand Down Expand Up @@ -72,6 +72,22 @@ private function enqueue_attachment_edit_page_script(): void {
}
}

public function redirect_to_plugin_settings_after_activation( string $plugin ): void {
global $pagenow;

// Disable redirect if there are multiple plugins activated at once.
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( 'plugins.php' === $pagenow && isset( $_REQUEST['action'] ) && 'activate-selected' === $_REQUEST['action'] ) {
return;
}
// phpcs:enable

if ( plugin_basename( __FILE__ ) === $plugin ) {
wp_safe_redirect( admin_url( 'options-media.php#' . Admin::SETTINGS_SECTION_ID ) );
exit();
}
}

public function plugin_row_meta( array $plugin_meta, string $plugin_file ): array {
if ( str_contains( $plugin_file, basename( ACPL_AI_ALT_PLUGIN_FILE ) ) ) {
$plugin_meta[] = sprintf(
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: alt text, accessibility, SEO, GPT-4, GPT-V, OpenAI, image
Requires at least: 6.3
Tested up to: 6.4
Requires PHP: 8.1
Stable tag: 2.0.1
Stable tag: 2.0.2
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Plugin URI: https://github.com/android-com-pl/wp-ai-alt-generator
Expand Down

0 comments on commit b0c5ea2

Please sign in to comment.