diff --git a/alt-text-generator-gpt-vision.php b/alt-text-generator-gpt-vision.php index 01b5df1..f776ec1 100644 --- a/alt-text-generator-gpt-vision.php +++ b/alt-text-generator-gpt-vision.php @@ -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.3 + * Version: 2.1.0 * Requires at least: 6.3 * Requires PHP: 8.1 * Author: android.com.pl @@ -36,9 +36,17 @@ class AltGeneratorPlugin { public function __construct() { add_filter( 'wp_generate_attachment_metadata', [ AltGenerator::class, 'on_attachment_upload' ], 10, 3 ); add_action( 'rest_api_init', [ ( new Api() ), 'register_routes' ] ); + 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() ); + + add_action( 'load-upload.php', fn()=> $this->enqueue_script( 'media-upload', true ) ); + add_filter( + 'bulk_actions-upload', + fn( $actions ) => $actions + [ 'generate_alt_text' => __( 'Generate Alternative Text', 'alt-text-generator-gpt-vision' ) ] + ); + add_action( 'activated_plugin', [ $this,'redirect_to_plugin_settings_after_activation' ] ); add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); } diff --git a/readme.txt b/readme.txt index 26651b4..f518fa9 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: alt text, accessibility, SEO, GPT-4, GPT-V, OpenAI, image Requires at least: 6.3 Tested up to: 6.5 Requires PHP: 8.1 -Stable tag: 2.0.3.1 +Stable tag: 2.1.0 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 diff --git a/src/constants.ts b/src/constants.ts index dab1c59..b6baac4 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1 +1,2 @@ export const API_PATH = "acpl/ai-alt-generator"; +export const BULK_ACTION_OPTION_VALUE = "generate_alt_text"; diff --git a/src/media/media-upload.ts b/src/media/media-upload.ts new file mode 100644 index 0000000..3fa40aa --- /dev/null +++ b/src/media/media-upload.ts @@ -0,0 +1,20 @@ +import { qs, qsa } from "ts-dom-utils"; +import { BULK_ACTION_OPTION_VALUE } from "../constants"; + +const bulkActions = qsa(".bulkactions"); + +bulkActions.forEach((bulkActionsContainer) => { + const selector = qs( + "select[name='action'],select[name='action2']", + bulkActionsContainer, + ); + const submit = qs(".action", bulkActionsContainer); + if (!selector || !submit) return; + + submit.addEventListener("click", (e) => { + if (selector.value === BULK_ACTION_OPTION_VALUE) { + e.preventDefault(); + //TODO + } + }); +}); diff --git a/webpack.config.js b/webpack.config.js index a202355..10b709c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -5,6 +5,7 @@ module.exports = { entry: { "media-modal": "./src/media/media-modal.ts", "media-edit-page": "./src/media/media-edit-page.ts", + "media-upload": "./src/media/media-upload.ts", editor: "./src/editor/index.tsx", }, };