Skip to content

Commit 211f9e5

Browse files
authored
Merge pull request #7 from arunbasillal/branch-3.1
Branch 3.1
2 parents f5e6d2f + da271e9 commit 211f9e5

6 files changed

+153
-39
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ What the pro add-on you get these additional features:
4747
* Use post title as alt text. If image is not attached to a post, image filename will be used instead.
4848
* Use post title as caption. If image is not attached to a post, image filename will be used instead.
4949
* Use post title as description. If image is not attached to a post, image filename will be used instead.
50-
* 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!
50+
* Build your own attributes using custom tags like `%filename%`, `%posttitle%`, `%sitetitle%`, `%category%`, `%tag%`, `%yoastfocuskw%`, `%rankmathfocuskw%`, `%seopresstargetkw%`. Each custom tag will be replaced with it's value. You can combine them as you please!
5151
* Use Yoast Focus Keyword and Rank Math Focus Keyword as image attributes.
5252
* Clear any image attribute by setting it as blank / empty.
5353
* 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.
@@ -68,21 +68,26 @@ What the pro add-on you get these additional features:
6868
* Clean the actual image filename after upload.
6969
* Choose to turn off any of the above mentioned features.
7070

71-
With the pro bulk updater you can:
71+
With the Image Attributes Pro bulk updater you can:
7272

7373
* Update image title and alt text for images inserted into posts and custom post types. Not just the media library. [What is the difference?](https://imageattributespro.com/how-wordpress-store-image-attributes/?utm_source=github&utm_medium=readme.md)
7474
* Fine tune all settings. Choose what to update.
7575
* Update image titles / alt text in media library only. Image titles / alt text in existing posts will be left unchanged.
7676
* Update image titles / alt text in media library and existing posts.
7777
* 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.
7878
* Update image caption and description in the media library. Existing image captions and descriptions can be preserved.
79-
* 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!
79+
* Build your own attributes using custom tags like `%filename%`, `%posttitle%`, `%sitetitle%`, `%category%`, `%tag%`, `%yoastfocuskw%`, `%rankmathfocuskw%`, `%seopresstargetkw%`. Each custom tag will be replaced with it's value. You can combine them as you please!
8080
* Choose to turn off any of the above mentioned features.
8181
* 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).
8282
* 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).
8383
* Disable updating of attributes in media library completely using the [iaffpro_update_media_library filter](https://imageattributespro.com/codex/iaffpro_update_media_library/?utm_source=github&utm_medium=readme.md).
8484
* Add or remove custom image attributes using the [iaffpro_html_image_markup_post_update filter](https://imageattributespro.com/codex/iaffpro_html_image_markup_post_update/?utm_source=github&utm_medium=readme.md)
8585

86+
Other Image Attributes Pro features:
87+
88+
* Bulk Update image attributes from WordPress Media Library. Select images and choose `Update image attributes` Bulk action in Media Library (list view). [Read more.](https://imageattributespro.com/bulk-actions/?utm_source=github&utm_medium=readme.md)
89+
* Bulk Update image attributes from WordPress admin page for Posts, Pages and WooCommerce Products. Select the posts, pages or WooCommerce products in bulk and choose "Update image attributes" Bulk action. [Read more.](https://imageattributespro.com/bulk-actions/?utm_source=github&utm_medium=readme.md)
90+
8691
For screenshots, FAQ and further details, please see the [product website](https://imageattributespro.com/?utm_source=github&utm_medium=readme.md).
8792

8893
## Installation

admin/iaff_image-attributes-from-filename-admin-setup.php

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,14 @@ function iaff_settings_validater_and_sanitizer( $settings ) {
275275
$settings['bu_custom_filter'] = sanitize_text_field( $settings['bu_custom_filter'] );
276276

277277
// Sanitize Custom Attributes
278-
$settings['custom_attribute_title'] = sanitize_text_field( $settings['custom_attribute_title'] );
279-
$settings['custom_attribute_bu_title'] = sanitize_text_field( $settings['custom_attribute_bu_title'] );
280-
$settings['custom_attribute_alt_text'] = sanitize_text_field( $settings['custom_attribute_alt_text'] );
281-
$settings['custom_attribute_bu_alt_text'] = sanitize_text_field( $settings['custom_attribute_bu_alt_text'] );
282-
$settings['custom_attribute_caption'] = sanitize_text_field( $settings['custom_attribute_caption'] );
283-
$settings['custom_attribute_bu_caption'] = sanitize_text_field( $settings['custom_attribute_bu_caption'] );
284-
$settings['custom_attribute_description'] = sanitize_text_field( $settings['custom_attribute_description'] );
285-
$settings['custom_attribute_bu_description'] = sanitize_text_field( $settings['custom_attribute_bu_description'] );
278+
$settings['custom_attribute_title'] = iaff_sanitize_text_field( $settings['custom_attribute_title'] );
279+
$settings['custom_attribute_bu_title'] = iaff_sanitize_text_field( $settings['custom_attribute_bu_title'] );
280+
$settings['custom_attribute_alt_text'] = iaff_sanitize_text_field( $settings['custom_attribute_alt_text'] );
281+
$settings['custom_attribute_bu_alt_text'] = iaff_sanitize_text_field( $settings['custom_attribute_bu_alt_text'] );
282+
$settings['custom_attribute_caption'] = iaff_sanitize_text_field( $settings['custom_attribute_caption'] );
283+
$settings['custom_attribute_bu_caption'] = iaff_sanitize_text_field( $settings['custom_attribute_bu_caption'] );
284+
$settings['custom_attribute_description'] = iaff_sanitize_text_field( $settings['custom_attribute_description'] );
285+
$settings['custom_attribute_bu_description'] = iaff_sanitize_text_field( $settings['custom_attribute_bu_description'] );
286286

287287
// Validating Regex
288288
if( @preg_match( $settings['regex_filter'], null ) === false ) {
@@ -297,6 +297,28 @@ function iaff_settings_validater_and_sanitizer( $settings ) {
297297
return $settings;
298298
}
299299

300+
/**
301+
* Extend sanitize_text_field() to preserve %category% custom attribute tag.
302+
*
303+
* sanitize_text_field() converts %category% to tegory%.
304+
* Here %category% is replaced with IAFF_CATEGORY_CUSTOM_TAG keyword before sanitization.
305+
* Then IAFF_CATEGORY_CUSTOM_TAG is replaced with %category% after sanitization.
306+
*
307+
* @since 3.1
308+
*
309+
* @param (String) $str String to be sanitized.
310+
*
311+
* @return (String) Sanitized string with %category% preserved.
312+
*/
313+
function iaff_sanitize_text_field( $str ) {
314+
315+
$str = str_replace( '%category%', 'IAFF_CATEGORY_CUSTOM_TAG', $str );
316+
$str = sanitize_text_field( $str );
317+
$str = str_replace( 'IAFF_CATEGORY_CUSTOM_TAG', '%category%', $str );
318+
319+
return $str;
320+
}
321+
300322
/**
301323
* Set global default values for settings
302324
*
@@ -379,9 +401,17 @@ function iaff_custom_attribute_tags() {
379401
'filename' => __( 'Image filename', 'auto-image-attributes-from-filename-with-bulk-updater' ),
380402
'posttitle' => __( 'Title of the post, page or product where the image is used', 'auto-image-attributes-from-filename-with-bulk-updater' ),
381403
'sitetitle' => __( 'Site Title defined in WordPress General Settings', 'auto-image-attributes-from-filename-with-bulk-updater' ),
382-
'yoastfocuskw' => __( 'Yoast Focus Keyword', 'auto-image-attributes-from-filename-with-bulk-updater' ),
383-
'rankmathfocuskw' => __( 'Rank Math Focus Keyword', 'auto-image-attributes-from-filename-with-bulk-updater' ),
404+
'category' => __( 'Post or Product Category', 'auto-image-attributes-from-filename-with-bulk-updater' ),
405+
'tag' => __( 'Post or Product Tag', 'auto-image-attributes-from-filename-with-bulk-updater' ),
384406
);
385407

386-
return $available_tags;
408+
/**
409+
* Filter the custom attribute tags.
410+
* Used by Image Attributes Pro to add custom tags like %yoastfocuskw% and %rankmathfocuskw% dynamically.
411+
*
412+
* @since 3.1
413+
*
414+
* @param $available_tags (array) Array containing all custom attribute tags.
415+
*/
416+
return apply_filters( 'iaff_custom_attribute_tags', $available_tags );
387417
}

admin/iaff_image-attributes-from-filename-admin-ui-render.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,13 +1050,21 @@ function iaff_admin_interface_render () {
10501050
<input class="button-secondary iaff-bulk-updater-buttons iaff_stop_bulk_updater_button" type="submit" name="Stop Bulk Updater" value="<?php _e( 'Stop Bulk Updater', 'auto-image-attributes-from-filename-with-bulk-updater' ) ?>" disabled />
10511051
</p>
10521052

1053-
<h2 class="showh2"><?php _e('Reset Counter', 'auto-image-attributes-from-filename-with-bulk-updater') ?></h2>
1053+
<h2 class="showh2"><?php _e('Tools', 'auto-image-attributes-from-filename-with-bulk-updater') ?></h2>
10541054

1055-
<p><?php _e('To restart processing images from the beginning (the oldest upload first), reset the counter.', 'auto-image-attributes-from-filename-with-bulk-updater') ?></p>
1056-
1057-
<span class="reset-counter-button">
1058-
<?php submit_button( __('Reset Counter', 'auto-image-attributes-from-filename-with-bulk-updater'), 'iaff_reset_counter_button' ); ?>
1059-
</span>
1055+
<p><?php _e('To restart processing images from the beginning (the oldest upload first), reset the counter.', 'auto-image-attributes-from-filename-with-bulk-updater') ?></p>
1056+
1057+
<?php if ( apply_filters( 'iaff_debug_mode', false ) ) { ?>
1058+
<p><?php printf( __( 'If Bulk Updater is stuck, refresh the page, skip current image and try running the bulk updater again. <a href="%s" target="_blank">Read more.</a>', 'auto-image-attributes-from-filename-with-bulk-updater' ), 'https://imageattributespro.com/fix-bulk-updater-stuck-on-same-image/?utm_source=iaff-basic&utm_medium=skip-image-button' ); ?></p>
1059+
<?php } ?>
1060+
1061+
<p class="submit">
1062+
<input class="button-secondary iaff-bulk-updater-buttons iaff_reset_counter_button" type="submit" name="Reset Counter" value="<?php _e( 'Reset Counter', 'auto-image-attributes-from-filename-with-bulk-updater' ) ?>" />
1063+
1064+
<?php if ( apply_filters( 'iaff_debug_mode', false ) ) { ?>
1065+
<input class="button-secondary iaff-bulk-updater-buttons iaff_skip_image_button" type="submit" name="Skip Image" value="<?php _e( 'Skip Image', 'auto-image-attributes-from-filename-with-bulk-updater' ) ?>" />
1066+
<?php } ?>
1067+
</p>
10601068

10611069
<!-- Event log -->
10621070
<div id="bulk-updater-results">

admin/iaff_image-attributes-from-filename-do.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ function iaff_rename_old_image() {
8181

8282
// Image Attributes Pro
8383
if ( iaff_is_pro() ) {
84+
85+
// Get the object of the image form image ID.
86+
$image_object = get_post( $image->ID );
8487

8588
// Running the pro module
86-
iaffpro_auto_image_attributes_pro($image, true);
89+
iaffpro_auto_image_attributes_pro( $image_object, true );
8790

8891
} else {
8992

@@ -192,6 +195,11 @@ function iaff_before_bulk_updater() {
192195
// Security Check
193196
check_ajax_referer( 'iaff_before_bulk_updater_nonce', 'security' );
194197

198+
/**
199+
* Action hook that is fired at the start of the Bulk Updater before updating any image.
200+
*
201+
* @link https://imageattributespro.com/codex/iaff_before_bulk_updater/
202+
*/
195203
do_action('iaff_before_bulk_updater');
196204
}
197205
add_action( 'wp_ajax_iaff_before_bulk_updater', 'iaff_before_bulk_updater' );
@@ -206,10 +214,41 @@ function iaff_after_bulk_updater() {
206214
// Security Check
207215
check_ajax_referer( 'iaff_after_bulk_updater_nonce', 'security' );
208216

217+
/**
218+
* Action hook that is fired at the end of the Bulk Updater after updating all images.
219+
*
220+
* @link https://imageattributespro.com/codex/iaff_after_bulk_updater/
221+
*/
209222
do_action('iaff_after_bulk_updater');
210223
}
211224
add_action( 'wp_ajax_iaff_after_bulk_updater', 'iaff_after_bulk_updater');
212225

226+
/**
227+
* Increment the counter by one to skip one image.
228+
*
229+
* @since 3.1
230+
*/
231+
function iaff_bulk_updater_skip_image() {
232+
233+
// Security Check
234+
check_ajax_referer( 'iaff_bulk_updater_skip_image_nonce', 'security' );
235+
236+
// Retrieve Counter
237+
$counter = get_option( 'iaff_bulk_updater_counter' );
238+
$counter = intval ( $counter );
239+
240+
// Increment counter and update it
241+
$counter++;
242+
update_option( 'iaff_bulk_updater_counter', $counter );
243+
244+
$response = array(
245+
'message' => __( 'One image skipped.', 'auto-image-attributes-from-filename-with-bulk-updater' ),
246+
'remaining_images' => iaff_count_remaining_images( true ),
247+
);
248+
wp_send_json( $response );
249+
}
250+
add_action( 'wp_ajax_iaff_bulk_updater_skip_image', 'iaff_bulk_updater_skip_image' );
251+
213252
/**
214253
* Bulk Updater Ajax
215254
*
@@ -396,6 +435,21 @@ function iaff_do_bulk_updater(iaff_test=false) {
396435
});
397436
$('#iaff-reset-counter-dialog').dialog('open');
398437
});
438+
439+
// Skip Image Button
440+
$('.iaff_skip_image_button').click( function() {
441+
442+
data = {
443+
action: 'iaff_bulk_updater_skip_image',
444+
security: '<?php echo wp_create_nonce( "iaff_bulk_updater_skip_image_nonce" ); ?>'
445+
};
446+
447+
$.post(ajaxurl, data, function (response) {
448+
$('#bulk-updater-log').append('<p class="iaff-green"><span class="dashicons dashicons-yes"></span>' + response.message + '</p>');
449+
$('#bulk-updater-log').append('<p>Number of Images Remaining: ' + response.remaining_images + '</p>');
450+
$("#bulk-updater-log").animate({scrollTop:$("#bulk-updater-log")[0].scrollHeight - $("#bulk-updater-log").height()},200);
451+
});
452+
});
399453

400454
});
401455
</script> <?php

iaff_image-attributes-from-filename.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 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.
66
* Author: Arun Basil Lal
77
* Author URI: https://imageattributespro.com/?utm_source=plugin-header&utm_medium=author-uri
8-
* Version: 3.0
8+
* Version: 3.1
99
* Text Domain: auto-image-attributes-from-filename-with-bulk-updater
1010
* Domain Path: /languages
1111
* License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@@ -67,7 +67,7 @@
6767
* @since 1.3
6868
*/
6969
if ( ! defined( 'IAFF_VERSION_NUM' ) ) {
70-
define( 'IAFF_VERSION_NUM', '3.0' );
70+
define( 'IAFF_VERSION_NUM', '3.1' );
7171
}
7272

7373
/**

0 commit comments

Comments
 (0)