Changeset 3070233
- Timestamp:
- 04/14/2024 02:40:30 PM (2 years ago)
- Location:
- better-file-name
- Files:
-
- 14 added
- 4 deleted
- 20 edited
- 1 copied
-
tags/1.4.0 (copied) (copied from better-file-name/trunk)
-
tags/1.4.0/.gitattributes (modified) (1 diff)
-
tags/1.4.0/better-file-name.php (modified) (2 diffs)
-
tags/1.4.0/build/index.asset.php (added)
-
tags/1.4.0/build/index.build.asset.php (deleted)
-
tags/1.4.0/build/index.build.js (deleted)
-
tags/1.4.0/build/index.js (added)
-
tags/1.4.0/build/media-alt-text.asset.php (added)
-
tags/1.4.0/build/media-alt-text.js (added)
-
tags/1.4.0/js/media-alt-text.js (added)
-
tags/1.4.0/readme.md (modified) (1 diff)
-
tags/1.4.0/readme.txt (modified) (1 diff)
-
tags/1.4.0/src/Admin.php (modified) (3 diffs)
-
tags/1.4.0/src/Alt_Text_Rest_Api.php (added)
-
tags/1.4.0/src/File_Path.php (added)
-
tags/1.4.0/src/Generate_Alt_Text_Cli.php (modified) (1 diff)
-
tags/1.4.0/src/Openai_Wrapper.php (modified) (1 diff)
-
tags/1.4.0/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
tags/1.4.0/vendor/composer/autoload_static.php (modified) (1 diff)
-
tags/1.4.0/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/.gitattributes (modified) (1 diff)
-
trunk/better-file-name.php (modified) (2 diffs)
-
trunk/build/index.asset.php (added)
-
trunk/build/index.build.asset.php (deleted)
-
trunk/build/index.build.js (deleted)
-
trunk/build/index.js (added)
-
trunk/build/media-alt-text.asset.php (added)
-
trunk/build/media-alt-text.js (added)
-
trunk/js/media-alt-text.js (added)
-
trunk/readme.md (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/src/Admin.php (modified) (3 diffs)
-
trunk/src/Alt_Text_Rest_Api.php (added)
-
trunk/src/File_Path.php (added)
-
trunk/src/Generate_Alt_Text_Cli.php (modified) (1 diff)
-
trunk/src/Openai_Wrapper.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_static.php (modified) (1 diff)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
better-file-name/tags/1.4.0/.gitattributes
r3024634 r3070233 7 7 package.json export-ignore 8 8 package-lock.json export-ignore 9 /.wordpress-org export-ignore -
better-file-name/tags/1.4.0/better-file-name.php
r3070148 r3070233 7 7 * Author URI: github.com/patelutkarsh 8 8 * Text Domain: better-file-name 9 * Version: 1. 3.39 * Version: 1.4.0 10 10 * Requires PHP: 8.1 11 11 * License: GPL-2.0-or-later … … 35 35 $better_file_name_admin = new Admin( $better_file_name_settings, plugins_url( 'build', __FILE__ ) ); 36 36 $better_file_name_dalle_image_generator = new Dalle_Image_Generator( $better_file_name_settings ); 37 $better_file_name_alt_text_rest_api = new Better_File_Name_Ai\Alt_Text_Rest_Api( $better_file_name_settings ); 37 38 38 39 if ( defined( 'WP_CLI' ) && WP_CLI ) { -
better-file-name/tags/1.4.0/readme.md
r3024634 r3070233 13 13 </div> 14 14 15 ### Additional features: 15 16 16 ### Additional features: 17 - Allows generating featured image using dall-e-2 or dall-e-3 API. 17 - Allows generating featured image using dall-e-2 or dall-e-3 API. 18 18 19 19 > Note: GPT-4 Vision is in preview, It is not recommended to use this plugin on a production site. 20 20 21 21 ## Demo: 22 22 23 https://github.com/PatelUtkarsh/better-file-name-ai/assets/5015489/1f0ce636-ceeb-4e6e-918b-872d3069d40f 23 24 24 25 25 ## Installation -
better-file-name/tags/1.4.0/readme.txt
r3070148 r3070233 6 6 Tested up to: 6.4.1 7 7 Requires PHP: 8.1 8 Stable tag: 1. 3.38 Stable tag: 1.4.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
better-file-name/tags/1.4.0/src/Admin.php
r3024634 r3070233 18 18 return; 19 19 } 20 21 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 22 return; 23 } 24 20 25 if ( $this->settings->get_rename_file() ) { 21 26 add_filter( 'wp_handle_sideload_prefilter', [ $this, 'rename_new_file' ], 9999 ); … … 24 29 25 30 if ( $this->settings->should_generate_alt_text() ) { 26 add_filter( 'wp_update_attachment_metadata', [ $this, 'update_alt_text' ], 10, 2 ); 31 add_filter( 'wp_update_attachment_metadata', $this->update_alt_text( ... ), 10, 2 ); 32 add_filter( 'attachment_fields_to_edit', $this->attachment_fields_to_edit( ... ), 10, 2 ); 33 add_action( 'wp_enqueue_media', $this->enqueue_media( ... ) ); 27 34 } 28 35 … … 104 111 ); 105 112 } 113 114 /** 115 * Add custom field to media attachment 116 * 117 * @param array $form_fields Form fields. 118 * @param object $post WP_Post object. 119 * 120 * @return array 121 */ 122 public function attachment_fields_to_edit( $form_fields, $post ) { 123 if ( ! str_starts_with( $post->post_mime_type, 'image' ) ) { 124 return $form_fields; 125 } 126 127 $form_fields['alt-text-generator'] = [ 128 'input' => 'html', 129 'html' => sprintf( '<button class="button generate-alt-text" data-media-id="%d">%s</button><span class="generate-alt-text__loading hidden">%s</span><span class="spinner"></span>', $post->ID, __( 'Generate alt text', 'better-file-name' ), esc_html__( 'Generating alt text...', 'better-file-name' ) ), 130 'label' => '', 131 ]; 132 133 return $form_fields; 134 } 135 136 public function enqueue_media() { 137 $version_file = __DIR__ . '/../build/media-alt-text.asset.php'; 138 if ( ! file_exists( $version_file ) ) { 139 return; 140 } 141 $version = include $version_file; 142 wp_enqueue_script( 143 'better-file-name-ai-media', 144 $this->plugin_url . '/media-alt-text.js', 145 $version['dependencies'], 146 $version['version'], 147 [ 148 'in_footer' => true, 149 ] 150 ); 151 152 wp_localize_script( 153 'better-file-name-ai-media', 154 'betterFileName', 155 [ 156 'api' => rest_url( 'better-file-name/v1/alt-text-generator' ), 157 'nonce' => wp_create_nonce( 'wp_rest' ), 158 ] 159 ); 160 } 106 161 } -
better-file-name/tags/1.4.0/src/Generate_Alt_Text_Cli.php
r3024634 r3070233 57 57 58 58 $attachment_ids_chunks = array_chunk( $attachment_ids, 50 ); 59 $uploads = wp_get_upload_dir(); 60 $base_dir = $uploads['basedir']; 61 unset( $attachment_ids, $query, $uploads ); 59 unset( $attachment_ids, $query ); 62 60 63 61 $open_ai_wrapper = new Openai_Wrapper( $setting->get_openai_api_key(), $setting->get_dell_e_version() ); 64 62 63 $file_path = new File_Path( $use ); 65 64 $generated_alt_text_count = 0; 66 65 foreach ( $attachment_ids_chunks as $attachment_ids ) { 67 66 foreach ( $attachment_ids as $post_id ) { 68 67 WP_CLI::log( 'Processing attachment ID: ' . $post_id ); 69 if ( wp_get_environment_type() !== 'production' || $use === 'data' ) { 70 $attachment_data = wp_get_attachment_metadata( $post_id ); 71 if ( ! isset( $attachment_data['file'] ) ) { 72 continue; 73 } 74 $file_path = str_replace( basename( $attachment_data['file'] ), '', $attachment_data['file'] ); 75 if ( isset( $attachment_data['sizes']['large'] ) ) { 76 $file_path = $base_dir . DIRECTORY_SEPARATOR . $file_path . $attachment_data['sizes']['large']['file']; 77 } else { 78 $file_path = $base_dir . DIRECTORY_SEPARATOR . $file_path . $attachment_data['file']; 79 } 80 } else { 81 [ $file_path ] = image_downsize( $post_id, 'thumbnail' ); 82 if ( ! $file_path ) { 83 [ $file_path ] = image_downsize( $post_id, 'large' ); 84 } 85 if ( ! $file_path ) { 86 $file_path = wp_get_attachment_url( $post_id ); 87 } 88 } 68 $file_path = $file_path->get_image_path( $post_id ); 89 69 if ( ! $dry_run && $setting->get_openai_api_key() ) { 90 70 try { -
better-file-name/tags/1.4.0/src/Openai_Wrapper.php
r3024634 r3070233 73 73 'headers' => $headers, 74 74 'body' => wp_json_encode( $data ), 75 'timeout' => 10,75 'timeout' => defined( 'WP_CLI' ) && WP_CLI ? 30 : 15, 76 76 ] 77 77 ); -
better-file-name/tags/1.4.0/vendor/composer/autoload_classmap.php
r3024634 r3070233 8 8 return array( 9 9 'Better_File_Name_Ai\\Admin' => $baseDir . '/src/Admin.php', 10 'Better_File_Name_Ai\\Alt_Text_Rest_Api' => $baseDir . '/src/Alt_Text_Rest_Api.php', 10 11 'Better_File_Name_Ai\\Dalle_Image_Generator' => $baseDir . '/src/Dalle_Image_Generator.php', 12 'Better_File_Name_Ai\\File_Path' => $baseDir . '/src/File_Path.php', 11 13 'Better_File_Name_Ai\\Generate_Alt_Text_Cli' => $baseDir . '/src/Generate_Alt_Text_Cli.php', 12 14 'Better_File_Name_Ai\\Image' => $baseDir . '/src/Image.php', -
better-file-name/tags/1.4.0/vendor/composer/autoload_static.php
r3024634 r3070233 23 23 public static $classMap = array ( 24 24 'Better_File_Name_Ai\\Admin' => __DIR__ . '/../..' . '/src/Admin.php', 25 'Better_File_Name_Ai\\Alt_Text_Rest_Api' => __DIR__ . '/../..' . '/src/Alt_Text_Rest_Api.php', 25 26 'Better_File_Name_Ai\\Dalle_Image_Generator' => __DIR__ . '/../..' . '/src/Dalle_Image_Generator.php', 27 'Better_File_Name_Ai\\File_Path' => __DIR__ . '/../..' . '/src/File_Path.php', 26 28 'Better_File_Name_Ai\\Generate_Alt_Text_Cli' => __DIR__ . '/../..' . '/src/Generate_Alt_Text_Cli.php', 27 29 'Better_File_Name_Ai\\Image' => __DIR__ . '/../..' . '/src/Image.php', -
better-file-name/tags/1.4.0/vendor/composer/installed.php
r3070148 r3070233 2 2 'root' => array( 3 3 'name' => 'patelutkarsh/better-file-name', 4 'pretty_version' => '1. 3.3',5 'version' => '1. 3.3.0',6 'reference' => ' 140cf8958696f108e92a25a03f8e0d0166f6585a',4 'pretty_version' => '1.4.0', 5 'version' => '1.4.0.0', 6 'reference' => 'd9801337c9412bfda0d7ec7953cb5e25b995d481', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 'patelutkarsh/better-file-name' => array( 14 'pretty_version' => '1. 3.3',15 'version' => '1. 3.3.0',16 'reference' => ' 140cf8958696f108e92a25a03f8e0d0166f6585a',14 'pretty_version' => '1.4.0', 15 'version' => '1.4.0.0', 16 'reference' => 'd9801337c9412bfda0d7ec7953cb5e25b995d481', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../', -
better-file-name/trunk/.gitattributes
r3024634 r3070233 7 7 package.json export-ignore 8 8 package-lock.json export-ignore 9 /.wordpress-org export-ignore -
better-file-name/trunk/better-file-name.php
r3070148 r3070233 7 7 * Author URI: github.com/patelutkarsh 8 8 * Text Domain: better-file-name 9 * Version: 1. 3.39 * Version: 1.4.0 10 10 * Requires PHP: 8.1 11 11 * License: GPL-2.0-or-later … … 35 35 $better_file_name_admin = new Admin( $better_file_name_settings, plugins_url( 'build', __FILE__ ) ); 36 36 $better_file_name_dalle_image_generator = new Dalle_Image_Generator( $better_file_name_settings ); 37 $better_file_name_alt_text_rest_api = new Better_File_Name_Ai\Alt_Text_Rest_Api( $better_file_name_settings ); 37 38 38 39 if ( defined( 'WP_CLI' ) && WP_CLI ) { -
better-file-name/trunk/readme.md
r3024634 r3070233 13 13 </div> 14 14 15 ### Additional features: 15 16 16 ### Additional features: 17 - Allows generating featured image using dall-e-2 or dall-e-3 API. 17 - Allows generating featured image using dall-e-2 or dall-e-3 API. 18 18 19 19 > Note: GPT-4 Vision is in preview, It is not recommended to use this plugin on a production site. 20 20 21 21 ## Demo: 22 22 23 https://github.com/PatelUtkarsh/better-file-name-ai/assets/5015489/1f0ce636-ceeb-4e6e-918b-872d3069d40f 23 24 24 25 25 ## Installation -
better-file-name/trunk/readme.txt
r3070148 r3070233 6 6 Tested up to: 6.4.1 7 7 Requires PHP: 8.1 8 Stable tag: 1. 3.38 Stable tag: 1.4.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
better-file-name/trunk/src/Admin.php
r3024634 r3070233 18 18 return; 19 19 } 20 21 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { 22 return; 23 } 24 20 25 if ( $this->settings->get_rename_file() ) { 21 26 add_filter( 'wp_handle_sideload_prefilter', [ $this, 'rename_new_file' ], 9999 ); … … 24 29 25 30 if ( $this->settings->should_generate_alt_text() ) { 26 add_filter( 'wp_update_attachment_metadata', [ $this, 'update_alt_text' ], 10, 2 ); 31 add_filter( 'wp_update_attachment_metadata', $this->update_alt_text( ... ), 10, 2 ); 32 add_filter( 'attachment_fields_to_edit', $this->attachment_fields_to_edit( ... ), 10, 2 ); 33 add_action( 'wp_enqueue_media', $this->enqueue_media( ... ) ); 27 34 } 28 35 … … 104 111 ); 105 112 } 113 114 /** 115 * Add custom field to media attachment 116 * 117 * @param array $form_fields Form fields. 118 * @param object $post WP_Post object. 119 * 120 * @return array 121 */ 122 public function attachment_fields_to_edit( $form_fields, $post ) { 123 if ( ! str_starts_with( $post->post_mime_type, 'image' ) ) { 124 return $form_fields; 125 } 126 127 $form_fields['alt-text-generator'] = [ 128 'input' => 'html', 129 'html' => sprintf( '<button class="button generate-alt-text" data-media-id="%d">%s</button><span class="generate-alt-text__loading hidden">%s</span><span class="spinner"></span>', $post->ID, __( 'Generate alt text', 'better-file-name' ), esc_html__( 'Generating alt text...', 'better-file-name' ) ), 130 'label' => '', 131 ]; 132 133 return $form_fields; 134 } 135 136 public function enqueue_media() { 137 $version_file = __DIR__ . '/../build/media-alt-text.asset.php'; 138 if ( ! file_exists( $version_file ) ) { 139 return; 140 } 141 $version = include $version_file; 142 wp_enqueue_script( 143 'better-file-name-ai-media', 144 $this->plugin_url . '/media-alt-text.js', 145 $version['dependencies'], 146 $version['version'], 147 [ 148 'in_footer' => true, 149 ] 150 ); 151 152 wp_localize_script( 153 'better-file-name-ai-media', 154 'betterFileName', 155 [ 156 'api' => rest_url( 'better-file-name/v1/alt-text-generator' ), 157 'nonce' => wp_create_nonce( 'wp_rest' ), 158 ] 159 ); 160 } 106 161 } -
better-file-name/trunk/src/Generate_Alt_Text_Cli.php
r3024634 r3070233 57 57 58 58 $attachment_ids_chunks = array_chunk( $attachment_ids, 50 ); 59 $uploads = wp_get_upload_dir(); 60 $base_dir = $uploads['basedir']; 61 unset( $attachment_ids, $query, $uploads ); 59 unset( $attachment_ids, $query ); 62 60 63 61 $open_ai_wrapper = new Openai_Wrapper( $setting->get_openai_api_key(), $setting->get_dell_e_version() ); 64 62 63 $file_path = new File_Path( $use ); 65 64 $generated_alt_text_count = 0; 66 65 foreach ( $attachment_ids_chunks as $attachment_ids ) { 67 66 foreach ( $attachment_ids as $post_id ) { 68 67 WP_CLI::log( 'Processing attachment ID: ' . $post_id ); 69 if ( wp_get_environment_type() !== 'production' || $use === 'data' ) { 70 $attachment_data = wp_get_attachment_metadata( $post_id ); 71 if ( ! isset( $attachment_data['file'] ) ) { 72 continue; 73 } 74 $file_path = str_replace( basename( $attachment_data['file'] ), '', $attachment_data['file'] ); 75 if ( isset( $attachment_data['sizes']['large'] ) ) { 76 $file_path = $base_dir . DIRECTORY_SEPARATOR . $file_path . $attachment_data['sizes']['large']['file']; 77 } else { 78 $file_path = $base_dir . DIRECTORY_SEPARATOR . $file_path . $attachment_data['file']; 79 } 80 } else { 81 [ $file_path ] = image_downsize( $post_id, 'thumbnail' ); 82 if ( ! $file_path ) { 83 [ $file_path ] = image_downsize( $post_id, 'large' ); 84 } 85 if ( ! $file_path ) { 86 $file_path = wp_get_attachment_url( $post_id ); 87 } 88 } 68 $file_path = $file_path->get_image_path( $post_id ); 89 69 if ( ! $dry_run && $setting->get_openai_api_key() ) { 90 70 try { -
better-file-name/trunk/src/Openai_Wrapper.php
r3024634 r3070233 73 73 'headers' => $headers, 74 74 'body' => wp_json_encode( $data ), 75 'timeout' => 10,75 'timeout' => defined( 'WP_CLI' ) && WP_CLI ? 30 : 15, 76 76 ] 77 77 ); -
better-file-name/trunk/vendor/composer/autoload_classmap.php
r3024634 r3070233 8 8 return array( 9 9 'Better_File_Name_Ai\\Admin' => $baseDir . '/src/Admin.php', 10 'Better_File_Name_Ai\\Alt_Text_Rest_Api' => $baseDir . '/src/Alt_Text_Rest_Api.php', 10 11 'Better_File_Name_Ai\\Dalle_Image_Generator' => $baseDir . '/src/Dalle_Image_Generator.php', 12 'Better_File_Name_Ai\\File_Path' => $baseDir . '/src/File_Path.php', 11 13 'Better_File_Name_Ai\\Generate_Alt_Text_Cli' => $baseDir . '/src/Generate_Alt_Text_Cli.php', 12 14 'Better_File_Name_Ai\\Image' => $baseDir . '/src/Image.php', -
better-file-name/trunk/vendor/composer/autoload_static.php
r3024634 r3070233 23 23 public static $classMap = array ( 24 24 'Better_File_Name_Ai\\Admin' => __DIR__ . '/../..' . '/src/Admin.php', 25 'Better_File_Name_Ai\\Alt_Text_Rest_Api' => __DIR__ . '/../..' . '/src/Alt_Text_Rest_Api.php', 25 26 'Better_File_Name_Ai\\Dalle_Image_Generator' => __DIR__ . '/../..' . '/src/Dalle_Image_Generator.php', 27 'Better_File_Name_Ai\\File_Path' => __DIR__ . '/../..' . '/src/File_Path.php', 26 28 'Better_File_Name_Ai\\Generate_Alt_Text_Cli' => __DIR__ . '/../..' . '/src/Generate_Alt_Text_Cli.php', 27 29 'Better_File_Name_Ai\\Image' => __DIR__ . '/../..' . '/src/Image.php', -
better-file-name/trunk/vendor/composer/installed.php
r3070148 r3070233 2 2 'root' => array( 3 3 'name' => 'patelutkarsh/better-file-name', 4 'pretty_version' => '1. 3.3',5 'version' => '1. 3.3.0',6 'reference' => ' 140cf8958696f108e92a25a03f8e0d0166f6585a',4 'pretty_version' => '1.4.0', 5 'version' => '1.4.0.0', 6 'reference' => 'd9801337c9412bfda0d7ec7953cb5e25b995d481', 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 'patelutkarsh/better-file-name' => array( 14 'pretty_version' => '1. 3.3',15 'version' => '1. 3.3.0',16 'reference' => ' 140cf8958696f108e92a25a03f8e0d0166f6585a',14 'pretty_version' => '1.4.0', 15 'version' => '1.4.0.0', 16 'reference' => 'd9801337c9412bfda0d7ec7953cb5e25b995d481', 17 17 'type' => 'wordpress-plugin', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.