Skip to content

Commit

Permalink
feat: add a bulk actions option
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Apr 6, 2024
1 parent fd75fb1 commit 66ff6a3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
10 changes: 9 additions & 1 deletion 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.3
* Version: 2.1.0
* Requires at least: 6.3
* Requires PHP: 8.1
* Author: android.com.pl
Expand Down Expand Up @@ -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 );
}
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.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
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const API_PATH = "acpl/ai-alt-generator";
export const BULK_ACTION_OPTION_VALUE = "generate_alt_text";
20 changes: 20 additions & 0 deletions src/media/media-upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { qs, qsa } from "ts-dom-utils";
import { BULK_ACTION_OPTION_VALUE } from "../constants";

const bulkActions = qsa<HTMLDivElement>(".bulkactions");

bulkActions.forEach((bulkActionsContainer) => {
const selector = qs<HTMLSelectElement>(
"select[name='action'],select[name='action2']",
bulkActionsContainer,
);
const submit = qs<HTMLInputElement>(".action", bulkActionsContainer);
if (!selector || !submit) return;

submit.addEventListener("click", (e) => {
if (selector.value === BULK_ACTION_OPTION_VALUE) {
e.preventDefault();
//TODO
}
});
});
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
};

0 comments on commit 66ff6a3

Please sign in to comment.