Changeset 3329312
- Timestamp:
- 07/17/2025 12:30:14 AM (5 months ago)
- Location:
- alt-text-tools/trunk
- Files:
-
- 6 added
- 2 edited
-
alt-text-tools.php (modified) (10 diffs)
-
assets (added)
-
assets/banner-1544x500.jpg (added)
-
assets/banner-772-250.jpg (added)
-
assets/icon-128x128.png (added)
-
assets/icon-256x256.png (added)
-
assets/screenshot-1.png (added)
-
readme.txt (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
alt-text-tools/trunk/alt-text-tools.php
r2302160 r3329312 3 3 Plugin Name: Alt Text Tools 4 4 Description: Exports a CSV file of all images that are actually used in your content, along with their corresponding alt tags. 5 Version: 0. 2.05 Version: 0.3.0 6 6 Author: NerdPress 7 7 Author URI: https://www.nerdpress.net … … 13 13 14 14 if ( ! defined( 'NP_ATT_VERSION' ) ) 15 define( 'NP_ATT_VERSION', '0. 2.0' );15 define( 'NP_ATT_VERSION', '0.3.0' ); 16 16 17 17 class NerdpressAltTextTools { … … 34 34 new $class; 35 35 } 36 36 37 37 /** 38 38 * Constructor … … 46 46 add_action( 'admin_menu', array( $this, 'settingsPage' ) ); 47 47 add_action( 'wp_ajax_getCsv', array( $this, 'getCsv' ) ); 48 49 } 50 48 49 } 50 51 51 /** 52 52 * Inject JS script(s) into the settings page 53 53 * 54 54 * @since 0.0.1 55 */ 55 */ 56 56 public function injectScripts() { 57 57 wp_register_script( 'np_alt_tools_js', plugins_url( 'js/np_alt_tools.js', __FILE__ ), array( 'jquery' ), NP_ATT_VERSION ); … … 60 60 'nonce' => wp_create_nonce( 'np_alt_tools_secure_me' ) 61 61 ) ); 62 wp_enqueue_script( 'np_alt_tools_js' ); 62 wp_enqueue_script( 'np_alt_tools_js' ); 63 63 } 64 64 … … 94 94 } 95 95 96 private static function quoteIfComma( $fields_array ) {96 private static function escapeCsv( $fields_array ) { 97 97 $result = []; 98 98 foreach( $fields_array as $field => $value ) { 99 if ( strpos( $value, ',' ) !== FALSE ) 100 $result[] = '"' . $value . '"'; 101 else 102 $result[] = $value; 103 } 104 return $result; 99 // Escape double quotes by doubling them. 100 $value = str_replace( '"', '""', $value ); 101 102 // Enclose in double quotes if it contains special characters 103 if ( preg_match( '/[,"\r\n]/', $value ) ) { 104 $value = '"' . $value . '"'; 105 } 106 107 $result[] = $value; 108 } 109 return $result; 105 110 } 106 111 … … 133 138 '_builtin' => FALSE 134 139 ); 135 $postTypes = array_merge( 136 array( 'post', 'page' ), 137 get_post_types( $opts ) 140 $postTypes = array_merge( 141 array( 'post', 'page' ), 142 get_post_types( $opts ) 138 143 ); 139 144 140 145 $posts = []; 141 foreach( $postTypes as $type ) { 146 foreach( $postTypes as $type ) { 142 147 $posts = array_merge( $posts, get_posts( array( 143 148 'posts_per_page' => -1, 144 'post_type' => $type 149 'post_type' => $type 145 150 ) ) ); 146 151 } … … 152 157 $imgElemRegex = '/<img[^>]*>/'; 153 158 $site_url = site_url(); 154 $finds = []; 159 $finds = []; 155 160 foreach( $posts as $post ) { 156 161 $post_link = get_permalink( $post ); 157 162 $post_title = get_the_title( $post ); 158 163 $post_edit_link = get_edit_post_link( $post ); 159 $found = preg_match_all( 160 $imgElemRegex, 164 $found = preg_match_all( 165 $imgElemRegex, 161 166 apply_filters( 'the_content', $post->post_content ), 162 $matches, 163 PREG_PATTERN_ORDER 167 $matches, 168 PREG_PATTERN_ORDER 164 169 ); 165 170 … … 172 177 $media_link = $site_url .'/wp-admin/upload.php?s=' . self::getImageNameFromUrl( $img_url[ 1 ] ); 173 178 else 174 $media_link = ''; 179 $media_link = ''; 175 180 176 181 preg_match( '/alt="([^"]*)"/', $submatch, $alt_tag ); … … 193 198 } 194 199 } 195 200 196 201 /*================================ 197 202 * Create CSV File and AJAX it back 198 203 *=================================*/ 199 $rows = array( implode( ',', [ 200 'post id', 204 $rows = array( implode( ',', [ 205 'post id', 201 206 'post_type', 202 'page title', 203 'page url', 204 'image url', 205 'image alt tag', 207 'page title', 208 'page url', 209 'image url', 210 'image alt tag', 206 211 'edit link', 207 'media library link' 208 ] 212 'media library link' 213 ] 209 214 ) ); 210 215 211 216 foreach( $finds as $find ) { 212 $rows[] = implode( ',', self:: quoteIfComma( $find ) );217 $rows[] = implode( ',', self::escapeCsv( $find ) ); 213 218 } 214 219 215 220 $csvString = implode( '\r\n', $rows ); 216 221 echo $csvString; 217 die(); 222 die(); 218 223 } 219 224 } -
alt-text-tools/trunk/readme.txt
r3056486 r3329312 1 1 === Alt Text Tools === 2 Contributors: nerdpressteam, eatingrules 2 Contributors: nerdpressteam, eatingrules, jchristopher 3 3 Author URI: https://www.nerdpress.net/ 4 Tested Up To: 6. 55 Stable tag: trunk4 Tested Up To: 6.8 5 Stable tag: 0.3.0 6 6 Tags: alt text, accessibility, alternative text, alt tags, fix alt text 7 7 License: GPLv2 … … 15 15 This plugin will provide a CSV (comma separated values) file that lists all of your images used in your content -- and their corresponding Alt attribute. 16 16 17 To use, go to `Tools > Alt Text Tools`, and click the button. Give it a few moments to scan your site, and your download should begin. 17 To use, go to `Tools > Alt Text Tools`, and click the button. Give it a few moments to scan your site, and your download should begin. 18 18 19 19 You can then open the file into your favorite spreadsheet program, and use it to identify images that are missing Alt Texts, or that need other improvement. The file also includes links to edit the post in which the images appear, so you can quickly and easily edit the attribute. … … 41 41 If you add an Alt Text to the image in the media library (_before_ it's inserted into the post content), then it will be inserted with that Alt Text. 42 42 43 **Heads up!** If you're using the Block Editor, and if you use the "Image" block to insert an image and upload it directly into the block (Selecting an "Image" Block and then clicking the "Upload" button), it inserts the image and adds it to the media library _before_ you can add the Alt Text. So you'll end up inserting the image, adding the Alt Text in the sidebar in the editor, and later find that there's no Alt Text set on the image in the media library! 43 **Heads up!** If you're using the Block Editor, and if you use the "Image" block to insert an image and upload it directly into the block (Selecting an "Image" Block and then clicking the "Upload" button), it inserts the image and adds it to the media library _before_ you can add the Alt Text. So you'll end up inserting the image, adding the Alt Text in the sidebar in the editor, and later find that there's no Alt Text set on the image in the media library! 44 44 45 45 The workaround for this is to select the image block, click "Media Library" (instead of "Upload"), and then from the Media Library modal, click the "Upload Files" tab, and upload the image there. Add the Alt Text after you upload the image, and _then_ insert it into the post. … … 55 55 = What's the difference between EMPTY and MISSING? = 56 56 57 An empty (null) alt text, which is expressed like this in the code: `alt=""`, we'll note that they're `EMPTY`. (This is generally considered the best practice for "decorative" images.) 57 An empty (null) alt text, which is expressed like this in the code: `alt=""`, we'll note that they're `EMPTY`. (This is generally considered the best practice for "decorative" images.) 58 58 59 59 If the image has no `alt` attribute at all, then we'll note that it's `MISSING`. … … 89 89 == Changelog == 90 90 91 = 0.3.0 = 92 * Improved CSV formatting when fields contain special characters. 93 91 94 = 0.2.0 = 92 95 * First release.
Note: See TracChangeset
for help on using the changeset viewer.