Auto Image Attributes From Filename With Bulk Updater (Add Alt Text, Image Title For Image SEO) - Version 2.1

Version Description

  • Date: 02.July.2021
  • Enhancement: Compatibility with Image Attributes Pro v2.0.
Download this release

Release Info

Developer arunbasillal
Plugin Icon 128x128 Auto Image Attributes From Filename With Bulk Updater (Add Alt Text, Image Title For Image SEO)
Version 2.1
Comparing to
See all releases

Code changes from version 2.0 to 2.1

README.md CHANGED
@@ -45,6 +45,10 @@ What the pro add-on you get these additional features:
45
  * Use post title as alt text. If image is not attached to a post, image filename will be used instead.
46
  * Use post title as caption. If image is not attached to a post, image filename will be used instead.
47
  * Use post title as description. If image is not attached to a post, image filename will be used instead.
 
 
 
 
48
  * Remove apostrophe ( ' ) from filename
49
  * Remove tilde ( ~ ) from filename
50
  * Remove plus ( + ) from filename
@@ -68,7 +72,9 @@ With the pro bulk updater you can:
68
  * Fine tune all settings. Choose what to update.
69
  * Update image titles / alt text in media library only. Image titles / alt text in existing posts will be left unchanged.
70
  * Update image titles / alt text in media library and existing posts.
71
- * Update image titles / alt text in existing posts only if no title / alt text is set. Existing image titles / alt text will not be changed.
 
 
72
  * Choose to turn off any of the above mentioned features.
73
  * Modify auto generated image attributes using the [iaffpro_image_attributes filter](https://imageattributespro.com/codex/iaffpro_image_attributes/?utm_source=github&utm_medium=readme.md).
74
  * Choose specific post types to bulk update using the [iaffpro_included_post_types filter](https://imageattributespro.com/codex/iaffpro_included_post_types/?utm_source=github&utm_medium=readme.md).
45
  * Use post title as alt text. If image is not attached to a post, image filename will be used instead.
46
  * Use post title as caption. If image is not attached to a post, image filename will be used instead.
47
  * Use post title as description. If image is not attached to a post, image filename will be used instead.
48
+ * Build your own attributes using custom tags like `%filename%`,`%posttitle%`,`%sitetitle%`,`%yoastfocuskw%`,`%rankmathfocuskw%`. Each custom tag will be replaced with it's value. You can combine them as you please!
49
+ * Use Yoast Focus Keyword and Rank Math Focus Keyword as image attributes.
50
+ * Clear any image attribute by setting it as blank / empty.
51
+ * Exclude images from Bulk Updater. A meta box and a checkbox is added to the `Media Library` > `Edit Media` sidebar. When checked, the bulk updater will not update the attributes of that image in the media library or in posts / products where the image is used.
52
  * Remove apostrophe ( ' ) from filename
53
  * Remove tilde ( ~ ) from filename
54
  * Remove plus ( + ) from filename
72
  * Fine tune all settings. Choose what to update.
73
  * Update image titles / alt text in media library only. Image titles / alt text in existing posts will be left unchanged.
74
  * Update image titles / alt text in media library and existing posts.
75
+ * Update image titles / alt text in media library and existing posts only if no title / alt text is set. Existing image titles / alt text will not be changed.
76
+ * Update image caption and description in the media library. Existing image captions and descriptions can be preserved.
77
+ * Build your own attributes using custom tags like `%filename%`,`%posttitle%`,`%sitetitle%`,`%yoastfocuskw%`,`%rankmathfocuskw%`. Each custom tag will be replaced with it's value. You can combine them as you please!
78
  * Choose to turn off any of the above mentioned features.
79
  * Modify auto generated image attributes using the [iaffpro_image_attributes filter](https://imageattributespro.com/codex/iaffpro_image_attributes/?utm_source=github&utm_medium=readme.md).
80
  * Choose specific post types to bulk update using the [iaffpro_included_post_types filter](https://imageattributespro.com/codex/iaffpro_included_post_types/?utm_source=github&utm_medium=readme.md).
admin/css/iaff-style.css CHANGED
@@ -165,4 +165,18 @@
165
  #iaff-pro .iaff-support-block-inner h2, #iaff-pro .iaff-support-block-inner a {
166
  color: #fff;
167
  text-decoration: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
165
  #iaff-pro .iaff-support-block-inner h2, #iaff-pro .iaff-support-block-inner a {
166
  color: #fff;
167
  text-decoration: none;
168
+ }
169
+
170
+ #iaff-pro .iaff-custom-attribute-tags {
171
+ display: inline-block;
172
+ }
173
+
174
+ #iaff-pro .iaff-available-custom-attribute-tags {
175
+ display: inline-block;
176
+ margin-bottom: 0px;
177
+ }
178
+
179
+ #iaff-pro .iaff-custom-attribute-tags li {
180
+ float: left;
181
+ margin-right: 5px;
182
  }
admin/iaff_image-attributes-from-filename-admin-setup.php CHANGED
@@ -271,24 +271,36 @@ add_action( 'admin_init', 'iaff_register_settings' );
271
  /**
272
  * Input validator and sanitizer
273
  *
274
- * @since 1.4
275
- * @param Array $settings An array that contains all the settings
276
- * @return Array Array containing all the settings
 
 
277
  */
278
  function iaff_settings_validater_and_sanitizer( $settings ) {
279
 
280
  // Sanitize Custom Filter
281
- $settings['custom_filter'] = sanitize_text_field($settings['custom_filter']);
282
- $settings['bu_custom_filter'] = sanitize_text_field($settings['bu_custom_filter']);
 
 
 
 
 
 
 
 
 
 
283
 
284
  // Validating Regex
285
- if( @preg_match($settings['regex_filter'], null) === false ) {
286
- unset($settings['regex_filter']);
287
  }
288
 
289
  // Validating Bulk Updater Regex
290
- if( @preg_match($settings['bu_regex_filter'], null) === false ) {
291
- unset($settings['bu_regex_filter']);
292
  }
293
 
294
  return $settings;
@@ -303,33 +315,35 @@ function iaff_settings_validater_and_sanitizer( $settings ) {
303
  function iaff_get_settings() {
304
 
305
  $iaff_defaults = array(
306
- 'global_switch' => '1',
307
- 'image_title' => '1',
308
- 'image_caption' => '1',
309
- 'image_description' => '1',
310
- 'image_alttext' => '1',
311
- 'image_title_to_html' => '1',
312
- 'preview_pro' => '0',
313
- 'hyphens' => '1',
314
- 'under_score' => '1',
315
- 'capitalization' => '0',
316
- 'title_source' => '0',
317
- 'alt_text_source' => '0',
318
- 'caption_source' => '0',
319
- 'description_source' => '0',
320
- 'clean_filename' => '1',
321
- 'bu_image_title' => '1',
322
- 'bu_image_caption' => '1',
323
- 'bu_image_description' => '1',
324
- 'bu_image_alttext' => '1',
325
- 'bu_capitalization' => '0',
326
- 'bu_title_source' => '0',
327
- 'bu_titles_in_post' => '0',
328
- 'bu_alt_text_source' => '0',
329
- 'bu_alt_text_in_post' => '0',
330
- 'bu_caption_source' => '0',
331
- 'bu_description_source' => '0',
332
- );
 
 
333
 
334
  $settings = get_option('iaff_settings', $iaff_defaults);
335
 
@@ -362,4 +376,22 @@ function iaff_enqueue_js_and_css() {
362
  // Google Fonts
363
  wp_enqueue_style('iaff-google-font', 'https://fonts.googleapis.com/css?family=Patua+One', array(), null, 'all');
364
  }
365
- add_action( 'admin_enqueue_scripts', 'iaff_enqueue_js_and_css' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  /**
272
  * Input validator and sanitizer
273
  *
274
+ * @since 1.4
275
+ *
276
+ * @param Array $settings An array that contains all the settings
277
+ *
278
+ * @return Array Array containing all the settings
279
  */
280
  function iaff_settings_validater_and_sanitizer( $settings ) {
281
 
282
  // Sanitize Custom Filter
283
+ $settings['custom_filter'] = sanitize_text_field( $settings['custom_filter'] );
284
+ $settings['bu_custom_filter'] = sanitize_text_field( $settings['bu_custom_filter'] );
285
+
286
+ // Sanitize Custom Attributes
287
+ $settings['custom_attribute_title'] = sanitize_text_field( $settings['custom_attribute_title'] );
288
+ $settings['custom_attribute_bu_title'] = sanitize_text_field( $settings['custom_attribute_bu_title'] );
289
+ $settings['custom_attribute_alt_text'] = sanitize_text_field( $settings['custom_attribute_alt_text'] );
290
+ $settings['custom_attribute_bu_alt_text'] = sanitize_text_field( $settings['custom_attribute_bu_alt_text'] );
291
+ $settings['custom_attribute_caption'] = sanitize_text_field( $settings['custom_attribute_caption'] );
292
+ $settings['custom_attribute_bu_caption'] = sanitize_text_field( $settings['custom_attribute_bu_caption'] );
293
+ $settings['custom_attribute_description'] = sanitize_text_field( $settings['custom_attribute_description'] );
294
+ $settings['custom_attribute_bu_description'] = sanitize_text_field( $settings['custom_attribute_bu_description'] );
295
 
296
  // Validating Regex
297
+ if( @preg_match( $settings['regex_filter'], null ) === false ) {
298
+ unset( $settings['regex_filter'] );
299
  }
300
 
301
  // Validating Bulk Updater Regex
302
+ if( @preg_match( $settings['bu_regex_filter'], null ) === false ) {
303
+ unset( $settings['bu_regex_filter'] );
304
  }
305
 
306
  return $settings;
315
  function iaff_get_settings() {
316
 
317
  $iaff_defaults = array(
318
+ 'global_switch' => '1',
319
+ 'image_title' => '1',
320
+ 'image_caption' => '1',
321
+ 'image_description' => '1',
322
+ 'image_alttext' => '1',
323
+ 'image_title_to_html' => '1',
324
+ 'preview_pro' => '0',
325
+ 'hyphens' => '1',
326
+ 'under_score' => '1',
327
+ 'capitalization' => '0',
328
+ 'title_source' => '0',
329
+ 'alt_text_source' => '0',
330
+ 'caption_source' => '0',
331
+ 'description_source' => '0',
332
+ 'clean_filename' => '1',
333
+ 'bu_image_title' => '1',
334
+ 'bu_image_caption' => '1',
335
+ 'bu_image_description' => '1',
336
+ 'bu_image_alttext' => '1',
337
+ 'bu_capitalization' => '0',
338
+ 'bu_title_source' => '0',
339
+ 'bu_titles_in_post' => '2',
340
+ 'bu_alt_text_source' => '0',
341
+ 'bu_alt_text_in_post' => '2',
342
+ 'bu_caption_source' => '0',
343
+ 'bu_caption_behaviour' => '1',
344
+ 'bu_description_source' => '0',
345
+ 'bu_description_behaviour' => '1',
346
+ );
347
 
348
  $settings = get_option('iaff_settings', $iaff_defaults);
349
 
376
  // Google Fonts
377
  wp_enqueue_style('iaff-google-font', 'https://fonts.googleapis.com/css?family=Patua+One', array(), null, 'all');
378
  }
379
+ add_action( 'admin_enqueue_scripts', 'iaff_enqueue_js_and_css' );
380
+
381
+ /**
382
+ * Tags for custom attribute
383
+ *
384
+ * @since 2.1
385
+ */
386
+ function iaff_custom_attribute_tags() {
387
+
388
+ $available_tags = array(
389
+ 'filename' => __( 'Image filename', 'auto-image-attributes-from-filename-with-bulk-updater' ),
390
+ 'posttitle' => __( 'Title of the post, page or product where the image is used', 'auto-image-attributes-from-filename-with-bulk-updater' ),
391
+ 'sitetitle' => __( 'Site Title defined in WordPress General Settings', 'auto-image-attributes-from-filename-with-bulk-updater' ),
392
+ 'yoastfocuskw' => __( 'Yoast Focus Keyword', 'auto-image-attributes-from-filename-with-bulk-updater' ),
393
+ 'rankmathfocuskw' => __( 'Rank Math Focus Keyword', 'auto-image-attributes-from-filename-with-bulk-updater' ),
394
+ );
395
+
396
+ return $available_tags;
397
+ }
admin/iaff_image-attributes-from-filename-admin-ui-render.php CHANGED
@@ -357,6 +357,15 @@ function iaff_advanced_image_title_callback() {
357
  <span><?php esc_attr_e( 'Use post title as title text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
358
  </label><br>
359
 
 
 
 
 
 
 
 
 
 
360
  </fieldset>
361
 
362
  <?php
@@ -385,6 +394,15 @@ function iaff_advanced_image_alt_text_callback() {
385
  <span><?php esc_attr_e( 'Use post title as alt text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
386
  </label><br>
387
 
 
 
 
 
 
 
 
 
 
388
  </fieldset>
389
 
390
  <?php
@@ -413,6 +431,15 @@ function iaff_advanced_image_caption_callback() {
413
  <span><?php esc_attr_e( 'Use post title as caption. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
414
  </label><br>
415
 
 
 
 
 
 
 
 
 
 
416
  </fieldset>
417
 
418
  <?php
@@ -441,6 +468,15 @@ function iaff_advanced_image_description_callback() {
441
  <span><?php esc_attr_e( 'Use post title as description. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
442
  </label><br>
443
 
 
 
 
 
 
 
 
 
 
444
  </fieldset>
445
 
446
  <?php
@@ -703,6 +739,15 @@ function iaff_bu_image_title_settings_callback() {
703
  <span><?php esc_attr_e( 'Use post title as title text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
704
  </label><br>
705
 
 
 
 
 
 
 
 
 
 
706
  <h4><?php _e('Bulk Updater Behaviour', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></h4>
707
 
708
  <label>
@@ -748,6 +793,15 @@ function iaff_bu_alt_text_settings_callback() {
748
  <span><?php esc_attr_e( 'Use post title as alt text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
749
  </label><br>
750
 
 
 
 
 
 
 
 
 
 
751
  <h4><?php _e('Bulk Updater Behaviour', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></h4>
752
 
753
  <label>
@@ -793,6 +847,27 @@ function iaff_bu_image_caption_settings_callback() {
793
  <span><?php esc_attr_e( 'Use post title as caption. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
794
  </label><br>
795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
796
  </fieldset>
797
 
798
  <?php
@@ -821,11 +896,72 @@ function iaff_bu_image_description_settings_callback() {
821
  <span><?php esc_attr_e( 'Use post title as description. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
822
  </label><br>
823
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
824
  </fieldset>
825
 
826
  <?php
827
  }
828
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829
  /**
830
  * Admin interface renderer
831
  *
357
  <span><?php esc_attr_e( 'Use post title as title text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
358
  </label><br>
359
 
360
+ <label>
361
+ <input type="radio" id="radio_custom_attribute_title" class="radio_custom_attribute" data-attribute="title" name="iaff_settings[title_source]" value="2" <?php if ( isset( $settings['title_source'] ) ) checked( '2', $settings['title_source'] ); ?>/>
362
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
363
+
364
+ <input type="text" id="text_custom_attribute_title" class="text_custom_attribute regular-text code" data-attribute="title" name="iaff_settings[custom_attribute_title]" value="<?php if ( isset( $settings['custom_attribute_title'] ) && ( ! empty( $settings['custom_attribute_title'] ) ) ) echo esc_attr( $settings['custom_attribute_title'] ); ?>" />
365
+ </label><br>
366
+
367
+ <?php iaff_custom_attribute_tags_ui_render( 'title' ); ?>
368
+
369
  </fieldset>
370
 
371
  <?php
394
  <span><?php esc_attr_e( 'Use post title as alt text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
395
  </label><br>
396
 
397
+ <label>
398
+ <input type="radio" id="radio_custom_attribute_alt_text" class="radio_custom_attribute" data-attribute="alt_text" name="iaff_settings[alt_text_source]" value="2" <?php if ( isset( $settings['alt_text_source'] ) ) checked( '2', $settings['alt_text_source'] ); ?>/>
399
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
400
+
401
+ <input type="text" id="text_custom_attribute_alt_text" class="text_custom_attribute regular-text code" data-attribute="alt_text" name="iaff_settings[custom_attribute_alt_text]" value="<?php if ( isset( $settings['custom_attribute_alt_text'] ) && ( ! empty( $settings['custom_attribute_alt_text'] ) ) ) echo esc_attr( $settings['custom_attribute_alt_text'] ); ?>" />
402
+ </label><br>
403
+
404
+ <?php iaff_custom_attribute_tags_ui_render( 'alt_text' ); ?>
405
+
406
  </fieldset>
407
 
408
  <?php
431
  <span><?php esc_attr_e( 'Use post title as caption. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
432
  </label><br>
433
 
434
+ <label>
435
+ <input type="radio" id="radio_custom_attribute_caption" class="radio_custom_attribute" data-attribute="caption" name="iaff_settings[caption_source]" value="2" <?php if ( isset( $settings['caption_source'] ) ) checked( '2', $settings['caption_source'] ); ?>/>
436
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
437
+
438
+ <input type="text" id="text_custom_attribute_caption" class="text_custom_attribute regular-text code" data-attribute="caption" name="iaff_settings[custom_attribute_caption]" value="<?php if ( isset( $settings['custom_attribute_caption'] ) && ( ! empty( $settings['custom_attribute_caption'] ) ) ) echo esc_attr( $settings['custom_attribute_caption'] ); ?>" />
439
+ </label><br>
440
+
441
+ <?php iaff_custom_attribute_tags_ui_render( 'caption' ); ?>
442
+
443
  </fieldset>
444
 
445
  <?php
468
  <span><?php esc_attr_e( 'Use post title as description. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
469
  </label><br>
470
 
471
+ <label>
472
+ <input type="radio" id="radio_custom_attribute_description" class="radio_custom_attribute" data-attribute="description" name="iaff_settings[description_source]" value="2" <?php if ( isset( $settings['description_source'] ) ) checked( '2', $settings['description_source'] ); ?>/>
473
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
474
+
475
+ <input type="text" id="text_custom_attribute_description" class="text_custom_attribute regular-text code" data-attribute="description" name="iaff_settings[custom_attribute_description]" value="<?php if ( isset( $settings['custom_attribute_description'] ) && ( ! empty( $settings['custom_attribute_description'] ) ) ) echo esc_attr( $settings['custom_attribute_description'] ); ?>" />
476
+ </label><br>
477
+
478
+ <?php iaff_custom_attribute_tags_ui_render( 'description' ); ?>
479
+
480
  </fieldset>
481
 
482
  <?php
739
  <span><?php esc_attr_e( 'Use post title as title text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
740
  </label><br>
741
 
742
+ <label>
743
+ <input type="radio" id="radio_custom_attribute_bu_title" class="radio_custom_attribute" data-attribute="bu_title" name="iaff_settings[bu_title_source]" value="2" <?php if ( isset( $settings['bu_title_source'] ) ) checked( '2', $settings['bu_title_source'] ); ?>/>
744
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
745
+
746
+ <input type="text" id="text_custom_attribute_bu_title" class="text_custom_attribute regular-text code" data-attribute="bu_title" name="iaff_settings[custom_attribute_bu_title]" value="<?php if ( isset( $settings['custom_attribute_bu_title'] ) && ( ! empty( $settings['custom_attribute_bu_title'] ) ) ) echo esc_attr( $settings['custom_attribute_bu_title'] ); ?>" />
747
+ </label><br>
748
+
749
+ <?php iaff_custom_attribute_tags_ui_render( 'bu_title' ); ?>
750
+
751
  <h4><?php _e('Bulk Updater Behaviour', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></h4>
752
 
753
  <label>
793
  <span><?php esc_attr_e( 'Use post title as alt text. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
794
  </label><br>
795
 
796
+ <label>
797
+ <input type="radio" id="radio_custom_attribute_bu_alt_text" class="radio_custom_attribute" data-attribute="bu_alt_text" name="iaff_settings[bu_alt_text_source]" value="2" <?php if ( isset( $settings['bu_alt_text_source'] ) ) checked( '2', $settings['bu_alt_text_source'] ); ?>/>
798
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
799
+
800
+ <input type="text" id="text_custom_attribute_bu_alt_text" class="text_custom_attribute regular-text code" data-attribute="bu_alt_text" name="iaff_settings[custom_attribute_bu_alt_text]" value="<?php if ( isset( $settings['custom_attribute_bu_alt_text'] ) && ( ! empty( $settings['custom_attribute_bu_alt_text'] ) ) ) echo esc_attr( $settings['custom_attribute_bu_alt_text'] ); ?>" />
801
+ </label><br>
802
+
803
+ <?php iaff_custom_attribute_tags_ui_render( 'bu_alt_text' ); ?>
804
+
805
  <h4><?php _e('Bulk Updater Behaviour', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></h4>
806
 
807
  <label>
847
  <span><?php esc_attr_e( 'Use post title as caption. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
848
  </label><br>
849
 
850
+ <label>
851
+ <input type="radio" id="radio_custom_attribute_bu_caption" class="radio_custom_attribute" data-attribute="bu_caption" name="iaff_settings[bu_caption_source]" value="2" <?php if ( isset( $settings['bu_caption_source'] ) ) checked( '2', $settings['bu_caption_source'] ); ?>/>
852
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
853
+
854
+ <input type="text" id="text_custom_attribute_bu_caption" class="text_custom_attribute regular-text code" data-attribute="bu_caption" name="iaff_settings[custom_attribute_bu_caption]" value="<?php if ( isset( $settings['custom_attribute_bu_caption'] ) && ( ! empty( $settings['custom_attribute_bu_caption'] ) ) ) echo esc_attr( $settings['custom_attribute_bu_caption'] ); ?>" />
855
+ </label><br>
856
+
857
+ <?php iaff_custom_attribute_tags_ui_render( 'bu_caption' ); ?>
858
+
859
+ <h4><?php _e('Bulk Updater Behaviour', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></h4>
860
+
861
+ <label>
862
+ <input type="radio" name="iaff_settings[bu_caption_behaviour]" value="0" <?php if ( isset($settings['bu_caption_behaviour']) ) checked( '0', $settings['bu_caption_behaviour'] ); ?>/>
863
+ <span><?php esc_attr_e( 'Update all captions in media library. Existing captions will be overwritten.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
864
+ </label><br>
865
+
866
+ <label>
867
+ <input type="radio" name="iaff_settings[bu_caption_behaviour]" value="1" <?php if ( isset($settings['bu_caption_behaviour']) ) checked( '1', $settings['bu_caption_behaviour'] ); ?>/>
868
+ <span><?php esc_attr_e( 'Update captions in media library if no caption is set. Existing captions will not be changed.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
869
+ </label><br>
870
+
871
  </fieldset>
872
 
873
  <?php
896
  <span><?php esc_attr_e( 'Use post title as description. If image is not uploaded to a post, image filename will be used instead.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
897
  </label><br>
898
 
899
+ <label>
900
+ <input type="radio" id="radio_custom_attribute_bu_description" class="radio_custom_attribute" data-attribute="bu_description" name="iaff_settings[bu_description_source]" value="2" <?php if ( isset( $settings['bu_description_source'] ) ) checked( '2', $settings['bu_description_source'] ); ?>/>
901
+ <span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
902
+
903
+ <input type="text" id="text_custom_attribute_bu_description" class="text_custom_attribute regular-text code" data-attribute="bu_description" name="iaff_settings[custom_attribute_bu_description]" value="<?php if ( isset( $settings['custom_attribute_bu_description'] ) && ( ! empty( $settings['custom_attribute_bu_description'] ) ) ) echo esc_attr( $settings['custom_attribute_bu_description'] ); ?>" />
904
+ </label><br>
905
+
906
+ <?php iaff_custom_attribute_tags_ui_render( 'bu_description' ); ?>
907
+
908
+ <h4><?php _e('Bulk Updater Behaviour', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></h4>
909
+
910
+ <label>
911
+ <input type="radio" name="iaff_settings[bu_description_behaviour]" value="0" <?php if ( isset($settings['bu_description_behaviour']) ) checked( '0', $settings['bu_description_behaviour'] ); ?>/>
912
+ <span><?php esc_attr_e( 'Update all descriptions in media library. Existing descriptions will be overwritten.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
913
+ </label><br>
914
+
915
+ <label>
916
+ <input type="radio" name="iaff_settings[bu_description_behaviour]" value="1" <?php if ( isset($settings['bu_description_behaviour']) ) checked( '1', $settings['bu_description_behaviour'] ); ?>/>
917
+ <span><?php esc_attr_e( 'Update description in media library if no description is set. Existing descriptions will not be changed.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>
918
+ </label><br>
919
+
920
  </fieldset>
921
 
922
  <?php
923
  }
924
 
925
+ /**
926
+ * Display the selector UI to show available tags.
927
+ *
928
+ * @since 2.1
929
+ *
930
+ * @param $data_attribute string The attribute for which the UI will be used for.data-attribute will be different for each attribute.
931
+ */
932
+ function iaff_custom_attribute_tags_ui_render( $data_attribute ) {
933
+ ?>
934
+ <div class="iaff-custom-attribute-tags">
935
+ <?php
936
+ $available_tags = iaff_custom_attribute_tags();
937
+
938
+ if ( ! empty( $available_tags ) ) :
939
+ ?>
940
+ <p><?php _e( 'Available tags:' ); ?></p>
941
+ <p><?php _e( 'The following tags when used in a custom attribute will be replaced with their corresponding value.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></p>
942
+ <ul class="iaff-available-custom-attribute-tags" role="list">
943
+ <?php
944
+ foreach ( $available_tags as $tag => $explanation ) {
945
+ ?>
946
+ <li>
947
+ <button type="button"
948
+ class="button button-secondary"
949
+ data-attribute="<? echo $data_attribute; ?>"
950
+ title ="<?php echo esc_attr( $explanation ); ?>"
951
+ aria-label="<?php echo esc_attr( $explanation ); ?>">
952
+ <?php echo '%' . $tag . '%'; ?>
953
+ </button>
954
+ </li>
955
+ <?php
956
+ }
957
+ ?>
958
+ </ul>
959
+ <p><?php _e( 'For example, if you set custom attribute as <code>%posttitle% - Your Name</code>, the <code>%posttitle%</code> will be replaced by the title of the post to which the image is uploaded to. ', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></p>
960
+ <?php endif; ?>
961
+ </div>
962
+ <?php
963
+ }
964
+
965
  /**
966
  * Admin interface renderer
967
  *
admin/js/iaff-js.js CHANGED
@@ -20,4 +20,38 @@ jQuery( document ).ready( function($){
20
  sessionStorage.setItem("iaffCurrentTab", tab); // Store current tab in sessionStorage object
21
  }
22
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  });
20
  sessionStorage.setItem("iaffCurrentTab", tab); // Store current tab in sessionStorage object
21
  }
22
  });
23
+
24
+ // UI JS for the clickable tags to use custom attributes. (%filename% %posttitle% etc.)
25
+ var $availableAttributeTags = $( '#iaff-pro .iaff-custom-attribute-tags button' );
26
+ var $customAttribute = $( '.text_custom_attribute' );
27
+
28
+ // Check the radio button on clicking the textbox.
29
+ $customAttribute.on( 'click input', function() {
30
+ $attribute = $( this ).attr( 'data-attribute' );
31
+ $( '#radio_custom_attribute_' + $attribute ).prop( 'checked', true );
32
+ } );
33
+
34
+ $availableAttributeTags.on( 'click', function() {
35
+
36
+ $attribute = $( this ).attr( 'data-attribute' );
37
+ $customAttribute = $( '#text_custom_attribute_' + $attribute );
38
+
39
+ var customAttributeValue = $customAttribute.val(),
40
+ selectionStart = $customAttribute[ 0 ].selectionStart,
41
+ selectionEnd = $customAttribute[ 0 ].selectionEnd,
42
+ textToAppend = $( this ).text().trim(),
43
+ newSelectionStart;
44
+
45
+ $( '#radio_custom_attribute_' + $attribute ).prop( 'checked', true );
46
+
47
+ // Insert structure tag at the specified position.
48
+ $customAttribute.val( customAttributeValue.substr( 0, selectionStart ) + textToAppend + customAttributeValue.substr( selectionEnd ) );
49
+
50
+ // Give focus back with cursor right after appended text.
51
+ if ( $customAttribute[0].setSelectionRange ) {
52
+ newSelectionStart = ( customAttributeValue.substr( 0, selectionStart ) + textToAppend ).length;
53
+ $customAttribute[0].setSelectionRange( newSelectionStart, newSelectionStart );
54
+ $customAttribute.trigger( 'focus' );
55
+ }
56
+ } );
57
  });
iaff_image-attributes-from-filename.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Automatically Add Image Title, Image Caption, Description And Alt Text From Image Filename. Since this plugin includes a bulk updater this can update both existing images in the Media Library and new images.
6
  * Author: Arun Basil Lal
7
  * Author URI: https://imageattributespro.com/?utm_source=plugin-header&utm_medium=author-uri
8
- * Version: 2.0
9
  * Text Domain: auto-image-attributes-from-filename-with-bulk-updater
10
  * Domain Path: /languages
11
  * License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@@ -67,7 +67,7 @@ if ( ! defined( 'IAFF_IMAGE_ATTRIBUTES_FROM_FILENAME_URL' ) ) {
67
  * @since 1.3
68
  */
69
  if ( ! defined( 'IAFF_VERSION_NUM' ) ) {
70
- define( 'IAFF_VERSION_NUM', '2.0' );
71
  }
72
 
73
  /**
@@ -89,6 +89,21 @@ function iaff_upgrader() {
89
  return;
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  /**
93
  * Upgrade database settings when upgrading from 1.3 or lower
94
  * A global swith with setting name global_switch was introduce in 1.4
5
  * Description: Automatically Add Image Title, Image Caption, Description And Alt Text From Image Filename. Since this plugin includes a bulk updater this can update both existing images in the Media Library and new images.
6
  * Author: Arun Basil Lal
7
  * Author URI: https://imageattributespro.com/?utm_source=plugin-header&utm_medium=author-uri
8
+ * Version: 2.1
9
  * Text Domain: auto-image-attributes-from-filename-with-bulk-updater
10
  * Domain Path: /languages
11
  * License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
67
  * @since 1.3
68
  */
69
  if ( ! defined( 'IAFF_VERSION_NUM' ) ) {
70
+ define( 'IAFF_VERSION_NUM', '2.1' );
71
  }
72
 
73
  /**
89
  return;
90
  }
91
 
92
+ /**
93
+ * @since 2.1
94
+ * Bulk Updater Behaviour was added for image caption and description.
95
+ */
96
+ if ( version_compare( $current_ver, '2.0', '<=' ) ) {
97
+
98
+ $settings = get_option( 'iaff_settings' );
99
+
100
+ if ( $settings !== false ) {
101
+ $settings['bu_caption_behaviour'] = 1;
102
+ $settings['bu_description_behaviour'] = 1;
103
+ update_option('iaff_settings', $settings);
104
+ }
105
+ }
106
+
107
  /**
108
  * Upgrade database settings when upgrading from 1.3 or lower
109
  * A global swith with setting name global_switch was introduce in 1.4
readme.txt CHANGED
@@ -69,6 +69,10 @@ What the pro add-on you get these additional features:
69
  * Use post title as alt text. If image is not attached to a post, image filename will be used instead.
70
  * Use post title as caption. If image is not attached to a post, image filename will be used instead.
71
  * Use post title as description. If image is not attached to a post, image filename will be used instead.
 
 
 
 
72
  * Remove apostrophe ( ' ) from filename
73
  * Remove tilde ( ~ ) from filename
74
  * Remove plus ( + ) from filename
@@ -92,7 +96,9 @@ With the pro bulk updater you can:
92
  * Fine tune all settings. Choose what to update.
93
  * Update image titles / alt text in media library only. Image titles / alt text in existing posts will be left unchanged.
94
  * Update image titles / alt text in media library and existing posts.
95
- * Update image titles / alt text in existing posts only if no title / alt text is set. Existing image titles / alt text will not be changed.
 
 
96
  * Choose to turn off any of the above mentioned features.
97
  * Modify auto generated image attributes using the [iaffpro_image_attributes filter](https://imageattributespro.com/codex/iaffpro_image_attributes/?utm_source=wordpress.org&utm_medium=readme).
98
  * Choose specific post types to bulk update using the [iaffpro_included_post_types filter](https://imageattributespro.com/codex/iaffpro_included_post_types/?utm_source=wordpress.org&utm_medium=readme).
@@ -136,6 +142,10 @@ I am glad to hear that! You can either [upgrade to pro](https://imageattributesp
136
 
137
  == Changelog ==
138
 
 
 
 
 
139
  = 2.0 =
140
  * Date: 18.June.2021
141
  * Tested with WordPress 5.7.2.
@@ -197,6 +207,10 @@ I am glad to hear that! You can either [upgrade to pro](https://imageattributesp
197
 
198
  == Upgrade Notice ==
199
 
 
 
 
 
200
  = 2.0 =
201
  * Tested with WordPress 5.7.2.
202
  * UI Enhancement: Changed order of `General Settings` to match the order in `Media Library`.
69
  * Use post title as alt text. If image is not attached to a post, image filename will be used instead.
70
  * Use post title as caption. If image is not attached to a post, image filename will be used instead.
71
  * Use post title as description. If image is not attached to a post, image filename will be used instead.
72
+ * Build your own attributes using custom tags like `%filename%`,`%posttitle%`,`%sitetitle%`,`%yoastfocuskw%`,`%rankmathfocuskw%`. Each custom tag will be replaced with it's value. You can combine them as you please!
73
+ * Use Yoast Focus Keyword and Rank Math Focus Keyword as image attributes.
74
+ * Clear any image attribute by setting it as blank / empty.
75
+ * Exclude images from Bulk Updater. A meta box and a checkbox is added to the `Media Library` > `Edit Media` sidebar. When checked, the bulk updater will not update the attributes of that image in the media library or in posts / products where the image is used.
76
  * Remove apostrophe ( ' ) from filename
77
  * Remove tilde ( ~ ) from filename
78
  * Remove plus ( + ) from filename
96
  * Fine tune all settings. Choose what to update.
97
  * Update image titles / alt text in media library only. Image titles / alt text in existing posts will be left unchanged.
98
  * Update image titles / alt text in media library and existing posts.
99
+ * Update image titles / alt text in media library and existing posts only if no title / alt text is set. Existing image titles / alt text will not be changed.
100
+ * Update image caption and description in the media library. Existing image captions and descriptions can be preserved.
101
+ * Build your own attributes using custom tags like `%filename%`,`%posttitle%`,`%sitetitle%`,`%yoastfocuskw%`,`%rankmathfocuskw%`. Each custom tag will be replaced with it's value. You can combine them as you please!
102
  * Choose to turn off any of the above mentioned features.
103
  * Modify auto generated image attributes using the [iaffpro_image_attributes filter](https://imageattributespro.com/codex/iaffpro_image_attributes/?utm_source=wordpress.org&utm_medium=readme).
104
  * Choose specific post types to bulk update using the [iaffpro_included_post_types filter](https://imageattributespro.com/codex/iaffpro_included_post_types/?utm_source=wordpress.org&utm_medium=readme).
142
 
143
  == Changelog ==
144
 
145
+ = 2.1 =
146
+ * Date: 02.July.2021
147
+ * Enhancement: Compatibility with Image Attributes Pro v2.0.
148
+
149
  = 2.0 =
150
  * Date: 18.June.2021
151
  * Tested with WordPress 5.7.2.
207
 
208
  == Upgrade Notice ==
209
 
210
+ = 2.1 =
211
+ * Date: 02.July.2021
212
+ * Enhancement: Compatibility with Image Attributes Pro v2.0.
213
+
214
  = 2.0 =
215
  * Tested with WordPress 5.7.2.
216
  * UI Enhancement: Changed order of `General Settings` to match the order in `Media Library`.