Version Description
- Improved the architecture of the plugin laying foundation for future updates. Utilizing my starter plugin framework
- Bug fix: For images that had EXIF data, EXIF data was used instead of filename. Props to @mathieupellegrin for reporting this.
- NEW: Added option to Insert Image Title into HTML. WordPress stopped including image titles since 3.5. Code from Restore Image Title plugin was used.
- NEW: Remove full stops ( . ) from filename.
- NEW: Remove commas ( , ) from filename.
- NEW: Remove all numbers ( 0-9 ) from filename.
- NEW: Added a warning and user confirmation before while clicking "Run Bulk Updater" button to prevent accidental clicks.
- UI Improvement: Cleaned up the interface and moved the Bulk Updater to its own tab.
- UI Improvement: Bulk updater log is now displayed in a neat box instead of just printing the results on the page.
- Parts of the code was updated for more efficiency and faster processing.
- Tested on WordPress 4.8.1. Result
Download this release
Release Info
Developer | arunbasillal |
Plugin | Auto Image Attributes From Filename With Bulk Updater (Add Alt Text, Image Title For Image SEO) |
Version | 1.3 |
Comparing to | |
See all releases |
Code changes from version 1.2 to 1.3
- admin/css/iaff-style.css +54 -0
- admin/css/index.php +3 -0
- admin/iaff_image-attributes-from-filename-admin-setup.php +102 -0
- admin/iaff_image-attributes-from-filename-admin-ui-render.php +209 -0
- admin/iaff_image-attributes-from-filename-basic-setup.php +117 -0
- admin/iaff_image-attributes-from-filename-do.php +359 -0
- admin/iaff_image-attributes-from-filename-loader.php +25 -0
- admin/index.php +3 -0
- iaff_image-attributes-from-filename.php +63 -478
- includes/index.php +3 -0
- index.php +3 -0
- languages/image-attributes-from-filename.pot +0 -0
- public/index.php +3 -0
- readme.txt +39 -4
- uninstall.php +26 -0
admin/css/iaff-style.css
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#iaff-pro .reset-counter-button .submit {
|
2 |
+
margin-top: 0px !important;
|
3 |
+
padding-top: 0px !important;
|
4 |
+
}
|
5 |
+
|
6 |
+
#iaff-pro .backup-warning {
|
7 |
+
position: relative;
|
8 |
+
margin: 5px 0 15px;
|
9 |
+
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
|
10 |
+
background: #fff none repeat scroll 0 0;
|
11 |
+
border-left: 4px solid #DC3232;
|
12 |
+
|
13 |
+
}
|
14 |
+
|
15 |
+
#iaff-pro .backup-warning p {
|
16 |
+
margin: 0.5em 0;
|
17 |
+
padding: 15px;
|
18 |
+
}
|
19 |
+
|
20 |
+
#iaff-pro #bulk-updater-results {
|
21 |
+
max-width: 1200px;
|
22 |
+
}
|
23 |
+
|
24 |
+
#iaff-pro #bulk-updater-log-wrapper {
|
25 |
+
border: 1px solid #aaa;
|
26 |
+
margin: 10px auto;
|
27 |
+
}
|
28 |
+
|
29 |
+
#iaff-pro fieldset {
|
30 |
+
padding: 20px;
|
31 |
+
}
|
32 |
+
|
33 |
+
#iaff-pro #bulk-updater-log {
|
34 |
+
border: 1px solid #aaaaaa;
|
35 |
+
height: 300px;
|
36 |
+
overflow: auto;
|
37 |
+
}
|
38 |
+
|
39 |
+
#iaff-pro #bulk-updater-log > p {
|
40 |
+
margin: 0;
|
41 |
+
padding: 3px 5px;
|
42 |
+
}
|
43 |
+
|
44 |
+
#iaff-pro #bulk-updater-log > p:nth-child(even) {
|
45 |
+
background: #DFDFDF;
|
46 |
+
}
|
47 |
+
|
48 |
+
#iaff-pro p.iaff-green {
|
49 |
+
color: #46B450;
|
50 |
+
}
|
51 |
+
|
52 |
+
#iaff-pro p.iaff-red {
|
53 |
+
color: #DC3232;
|
54 |
+
}
|
admin/css/index.php
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden
|
3 |
+
?>
|
admin/iaff_image-attributes-from-filename-admin-setup.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Admin setup for the plugin
|
4 |
+
*
|
5 |
+
* @since 1.3
|
6 |
+
* @function iaff_add_menu_links() Add admin menu pages
|
7 |
+
* @function iaff_register_settings() Register Settings
|
8 |
+
* @function iaff_enqueue_js_and_css() Load Admin Side Js and CSS
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
// Exit if accessed directly
|
13 |
+
if ( !defined('ABSPATH') ) exit;
|
14 |
+
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Add admin menu pages
|
18 |
+
*
|
19 |
+
* @since 1.0
|
20 |
+
* @refer https://developer.wordpress.org/plugins/administration-menus/
|
21 |
+
*/
|
22 |
+
function iaff_add_menu_links() {
|
23 |
+
add_options_page( __('Auto Image Attributes','abl_iaff_td'), __('Image Attributes','abl_iaff_td'), 'manage_options', 'image-attributes-from-filename','iaff_admin_interface_render' );
|
24 |
+
}
|
25 |
+
add_action( 'admin_menu', 'iaff_add_menu_links' );
|
26 |
+
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Register Settings
|
30 |
+
*
|
31 |
+
* @since 1.0
|
32 |
+
*/
|
33 |
+
function iaff_register_settings() {
|
34 |
+
|
35 |
+
// Register Setting
|
36 |
+
register_setting(
|
37 |
+
'iaff_settings_group', // Group Name
|
38 |
+
'iaff_settings' // Setting Name = HTML form <input> name on settings form
|
39 |
+
);
|
40 |
+
|
41 |
+
// Register A New Section
|
42 |
+
add_settings_section(
|
43 |
+
'iaff_auto_image_attributes_settings', // ID
|
44 |
+
__('Image Attribute Settings For New Uploads', 'abl_iaff_td'), // Title
|
45 |
+
'iaff_auto_image_attributes_callback', // Callback Function
|
46 |
+
'image-attributes-from-filename' // Page slug
|
47 |
+
);
|
48 |
+
|
49 |
+
// General Settings
|
50 |
+
add_settings_field(
|
51 |
+
'iaff_general_settings', // ID
|
52 |
+
__('General Settings', 'abl_iaff_td'), // Title
|
53 |
+
'iaff_auto_image_attributes_settings_field_callback', // Callback function
|
54 |
+
'image-attributes-from-filename', // Page slug
|
55 |
+
'iaff_auto_image_attributes_settings' // Settings Section ID
|
56 |
+
);
|
57 |
+
|
58 |
+
// Filter Settings
|
59 |
+
add_settings_field(
|
60 |
+
'iaff_filter_settings', // ID
|
61 |
+
__('Filter Settings', 'abl_iaff_td'), // Title
|
62 |
+
'iaff_auto_image_attributes_filter_settings_callback', // Callback function
|
63 |
+
'image-attributes-from-filename', // Page slug
|
64 |
+
'iaff_auto_image_attributes_settings' // Settings Section ID
|
65 |
+
);
|
66 |
+
|
67 |
+
}
|
68 |
+
add_action( 'admin_init', 'iaff_register_settings' );
|
69 |
+
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Set default values for settings
|
73 |
+
*
|
74 |
+
* @since 1.0
|
75 |
+
*/
|
76 |
+
// Default Values For Settings
|
77 |
+
$defaults = array(
|
78 |
+
'image_title' => '1',
|
79 |
+
'image_caption' => '1',
|
80 |
+
'image_description' => '1',
|
81 |
+
'image_alttext' => '1',
|
82 |
+
'image_title_to_html' => '0',
|
83 |
+
'hyphens' => '1',
|
84 |
+
'under_score' => '1',
|
85 |
+
'full_stop' => '0',
|
86 |
+
'commas' => '0',
|
87 |
+
'all_numbers' => '0',
|
88 |
+
);
|
89 |
+
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Load Admin Side Js and CSS
|
93 |
+
*
|
94 |
+
* Used for styling the plugin pages and bulk updater.
|
95 |
+
* @since 1.3
|
96 |
+
*/
|
97 |
+
function iaff_enqueue_js_and_css() {
|
98 |
+
wp_register_style( 'iaff-style', plugins_url( '/css/iaff-style.css', __FILE__ ), '', IAFF_VERSION_NUM );
|
99 |
+
}
|
100 |
+
add_action( 'admin_enqueue_scripts', 'iaff_enqueue_js_and_css' );
|
101 |
+
|
102 |
+
?>
|
admin/iaff_image-attributes-from-filename-admin-ui-render.php
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Admin UI setup and render
|
4 |
+
*
|
5 |
+
* @since 1.3
|
6 |
+
* @function iaff_general_settings_section_callback() Callback function for General Settings section
|
7 |
+
* @function iaff_general_settings_field_callback() Callback function for General Settings field
|
8 |
+
* @function iaff_admin_interface_render() Admin interface renderer
|
9 |
+
*/
|
10 |
+
|
11 |
+
|
12 |
+
// Exit if accessed directly
|
13 |
+
if ( !defined('ABSPATH') ) exit;
|
14 |
+
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Callback function for General Settings section
|
18 |
+
*
|
19 |
+
* @since 1.0
|
20 |
+
*/
|
21 |
+
function iaff_auto_image_attributes_callback() {
|
22 |
+
echo '<p>' . __('Automatically add Image attributes such as Image Title, Image Caption, Description And Alt Text from Image Filename for new uploads.', 'abl_iaff_td') . '</p>';
|
23 |
+
}
|
24 |
+
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Callback function for General Settings field
|
28 |
+
*
|
29 |
+
* @since 1.0
|
30 |
+
*/
|
31 |
+
function iaff_auto_image_attributes_settings_field_callback() {
|
32 |
+
|
33 |
+
// Default Values For Settings
|
34 |
+
global $defaults;
|
35 |
+
|
36 |
+
// Get Settings
|
37 |
+
$settings = get_option('iaff_settings', $defaults);
|
38 |
+
|
39 |
+
// General Settings. Name of form element should be same as the setting name in register_setting(). ?>
|
40 |
+
|
41 |
+
<!-- Auto Add Image Title -->
|
42 |
+
<input type="checkbox" name="iaff_settings[image_title]" id="iaff_settings[image_title]" value="1"
|
43 |
+
<?php if ( isset( $settings['image_title'] ) ) { checked( '1', $settings['image_title'] ); } ?>>
|
44 |
+
<label for="iaff_settings[image_title]"><?php _e('Set Image Title from filename for new uploads', 'abl_iaff_td') ?></label>
|
45 |
+
<br>
|
46 |
+
|
47 |
+
<!-- Auto Add Image Caption -->
|
48 |
+
<input type="checkbox" name="iaff_settings[image_caption]" id="iaff_settings[image_caption]" value="1"
|
49 |
+
<?php if ( isset( $settings['image_caption'] ) ) { checked( '1', $settings['image_caption'] ); } ?>>
|
50 |
+
<label for="iaff_settings[image_caption]"><?php _e('Set Image Caption from filename for new uploads', 'abl_iaff_td') ?></label>
|
51 |
+
<br>
|
52 |
+
|
53 |
+
<!-- Auto Add Image Description -->
|
54 |
+
<input type="checkbox" name="iaff_settings[image_description]" id="iaff_settings[image_description]" value="1"
|
55 |
+
<?php if ( isset( $settings['image_description'] ) ) { checked( '1', $settings['image_description'] ); } ?>>
|
56 |
+
<label for="iaff_settings[image_description]"><?php _e('Set Image Description from filename for new uploads', 'abl_iaff_td') ?></label>
|
57 |
+
<br>
|
58 |
+
|
59 |
+
<!-- Auto Add Alt Text -->
|
60 |
+
<input type="checkbox" name="iaff_settings[image_alttext]" id="iaff_settings[image_alttext]" value="1"
|
61 |
+
<?php if ( isset( $settings['image_alttext'] ) ) { checked( '1', $settings['image_alttext'] ); } ?>>
|
62 |
+
<label for="iaff_settings[image_alttext]"><?php _e('Set Image Alt Text from filename for new uploads', 'abl_iaff_td') ?></label>
|
63 |
+
<br>
|
64 |
+
|
65 |
+
<!-- Insert Image Title Into Post HTML -->
|
66 |
+
<input type="checkbox" name="iaff_settings[image_title_to_html]" id="iaff_settings[image_title_to_html]" value="1"
|
67 |
+
<?php if ( isset( $settings['image_title_to_html'] ) ) { checked( '1', $settings['image_title_to_html'] ); } ?>>
|
68 |
+
<label for="iaff_settings[image_title_to_html]"><?php _e('Insert Image Title into post HTML. This will add title="Image Title" in the <img> tag.', 'abl_iaff_td') ?></label>
|
69 |
+
<br>
|
70 |
+
|
71 |
+
<?php
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Filter Settings field callback
|
77 |
+
*
|
78 |
+
* @since 1.0
|
79 |
+
*/
|
80 |
+
function iaff_auto_image_attributes_filter_settings_callback() {
|
81 |
+
|
82 |
+
// Default Values For Settings
|
83 |
+
global $defaults;
|
84 |
+
|
85 |
+
// Get Settings
|
86 |
+
$settings = get_option('iaff_settings', $defaults); ?>
|
87 |
+
|
88 |
+
<!-- Filter Hyphens -->
|
89 |
+
<input type="checkbox" name="iaff_settings[hyphens]" id="iaff_settings[hyphens]" value="1"
|
90 |
+
<?php if ( isset( $settings['hyphens'] ) ) { checked( '1', $settings['hyphens'] ); } ?>>
|
91 |
+
<label for="iaff_settings[hyphens]"><?php _e('Remove hyphens ( - ) from filename', 'abl_iaff_td') ?></label>
|
92 |
+
<br>
|
93 |
+
|
94 |
+
<!-- Filter Underscore -->
|
95 |
+
<input type="checkbox" name="iaff_settings[under_score]" id="iaff_settings[under_score]" value="1"
|
96 |
+
<?php if ( isset( $settings['under_score'] ) ) { checked( '1', $settings['under_score'] ); } ?>>
|
97 |
+
<label for="iaff_settings[under_score]"><?php _e('Remove underscores ( _ ) from filename', 'abl_iaff_td') ?></label>
|
98 |
+
<br>
|
99 |
+
|
100 |
+
<!-- Filter Full stops -->
|
101 |
+
<input type="checkbox" name="iaff_settings[full_stop]" id="iaff_settings[full_stop]" value="1"
|
102 |
+
<?php if ( isset( $settings['full_stop'] ) ) { checked( '1', $settings['full_stop'] ); } ?>>
|
103 |
+
<label for="iaff_settings[full_stop]"><?php _e('Remove full stops ( . ) from filename', 'abl_iaff_td') ?></label>
|
104 |
+
<br>
|
105 |
+
|
106 |
+
<!-- Filter Commas -->
|
107 |
+
<input type="checkbox" name="iaff_settings[commas]" id="iaff_settings[commas]" value="1"
|
108 |
+
<?php if ( isset( $settings['commas'] ) ) { checked( '1', $settings['commas'] ); } ?>>
|
109 |
+
<label for="iaff_settings[commas]"><?php _e('Remove commas ( , ) from filename', 'abl_iaff_td') ?></label>
|
110 |
+
<br>
|
111 |
+
|
112 |
+
<!-- Filter Numbers -->
|
113 |
+
<input type="checkbox" name="iaff_settings[all_numbers]" id="iaff_settings[all_numbers]" value="1"
|
114 |
+
<?php if ( isset( $settings['all_numbers'] ) ) { checked( '1', $settings['all_numbers'] ); } ?>>
|
115 |
+
<label for="iaff_settings[all_numbers]"><?php _e('Remove all numbers ( 0-9 ) from filename', 'abl_iaff_td') ?></label>
|
116 |
+
<br>
|
117 |
+
|
118 |
+
<?php
|
119 |
+
}
|
120 |
+
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Admin interface renderer
|
124 |
+
*
|
125 |
+
* @since 1.0
|
126 |
+
*/
|
127 |
+
function iaff_admin_interface_render () {
|
128 |
+
|
129 |
+
if ( ! current_user_can( 'manage_options' ) ) {
|
130 |
+
return;
|
131 |
+
} ?>
|
132 |
+
|
133 |
+
<div id="iaff-pro" class="wrap">
|
134 |
+
<h1>Auto Image Attributes From Filename With Bulk Updater</h1>
|
135 |
+
|
136 |
+
<?php
|
137 |
+
// Get the tab query variable. If it's not set, set it to the first tab
|
138 |
+
$active_tab = isset( $_GET[ 'tab' ] ) ? $_GET[ 'tab' ] : 'new-upload-settings';
|
139 |
+
?>
|
140 |
+
|
141 |
+
<h2 class="nav-tab-wrapper">
|
142 |
+
<a class="nav-tab <?php echo $active_tab == 'new-upload-settings' ? 'nav-tab-active' : ''; ?>" href="?page=image-attributes-from-filename&tab=new-upload-settings" style="margin-left: 0px;">New Upload Settings</a>
|
143 |
+
<a class="nav-tab <?php echo $active_tab == 'bulk-updater' ? 'nav-tab-active' : ''; ?>" href="?page=image-attributes-from-filename&tab=bulk-updater">Bulk Updater</a>
|
144 |
+
</h2>
|
145 |
+
|
146 |
+
<?php
|
147 |
+
// New Upload Settings Tab
|
148 |
+
if( $active_tab == 'new-upload-settings' ) { ?>
|
149 |
+
|
150 |
+
<form action="options.php" method="post">
|
151 |
+
<?php
|
152 |
+
// Output nonce, action, and option_page fields for a settings page.
|
153 |
+
settings_fields( 'iaff_settings_group' );
|
154 |
+
|
155 |
+
// Prints out all settings sections added to a particular settings page.
|
156 |
+
do_settings_sections( 'image-attributes-from-filename' ); // Page slug
|
157 |
+
|
158 |
+
// Output save settings button
|
159 |
+
submit_button( __('Save Settings', 'abl_iaff_td') );
|
160 |
+
?>
|
161 |
+
</form>
|
162 |
+
<?php
|
163 |
+
}
|
164 |
+
|
165 |
+
// Bulk Updater Tab
|
166 |
+
else if( $active_tab == 'bulk-updater' ) { ?>
|
167 |
+
|
168 |
+
<?php // Load Admin CSS
|
169 |
+
wp_enqueue_style( 'iaff-style' ); ?>
|
170 |
+
|
171 |
+
<h2><?php _e('Update Existing Images In Media Library', 'abl_iaff_td') ?></h2>
|
172 |
+
|
173 |
+
<p><?php _e('Run this bulk updater to update Image Title, Caption, Description and Alt Text from image filename for existing images in the media library.', 'abl_iaff_td') ?></p>
|
174 |
+
|
175 |
+
<div class="backup-warning">
|
176 |
+
<p><strong><?php _e('IMPORTANT: Please backup your database before running the bulk updater. <br>If your image is named a-lot-like_love.jpg, your Image Title, Caption, Description and Alt Text will be: A Lot Like Love. All attributes are updated regardless of the settings for NEW uploads.', 'abl_iaff_td') ?></strong></p>
|
177 |
+
</div>
|
178 |
+
|
179 |
+
<?php submit_button( __('Run Bulk Updater', 'abl_iaff_td'), 'button-primary iaff_run_bulk_updater_button' ); ?>
|
180 |
+
|
181 |
+
<h2><?php _e('Reset Counter', 'abl_iaff_td') ?></h2>
|
182 |
+
|
183 |
+
<p><?php _e('To restart processing images from the beginning (the oldest upload first), reset the counter.', 'abl_iaff_td') ?></p>
|
184 |
+
|
185 |
+
<span class="reset-counter-button">
|
186 |
+
<?php submit_button( __('Reset Counter', 'abl_iaff_td'), 'iaff_reset_counter_button' ); ?>
|
187 |
+
</span>
|
188 |
+
|
189 |
+
<div id="bulk-updater-results">
|
190 |
+
<fieldset id="bulk-updater-log-wrapper">
|
191 |
+
<legend><span class="dashicons dashicons-welcome-write-blog"></span> <strong>Event Log</strong> </legend>
|
192 |
+
|
193 |
+
<div id="bulk-updater-log">
|
194 |
+
<p id="iaff_remaining_images_text"><?php _e('Number of Images Remaining: ', 'abl_iaff_td') ?><?php echo iaff_count_remaining_images(); ?></p>
|
195 |
+
|
196 |
+
<p><?php _e('Number of Images Updated: ', 'abl_iaff_td') ?><?php echo iaff_number_of_images_updated(); ?></p>
|
197 |
+
</div>
|
198 |
+
</fieldset>
|
199 |
+
|
200 |
+
</div>
|
201 |
+
|
202 |
+
<?php
|
203 |
+
} ?>
|
204 |
+
|
205 |
+
</div>
|
206 |
+
<?php
|
207 |
+
}
|
208 |
+
|
209 |
+
?>
|
admin/iaff_image-attributes-from-filename-basic-setup.php
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Basic setup functions for the plugin
|
4 |
+
*
|
5 |
+
* @since 1.3
|
6 |
+
* @function iaff_activate_plugin() Plugin activatation todo list
|
7 |
+
* @function iaff_load_plugin_textdomain() Load plugin text domain
|
8 |
+
* @function iaff_settings_link() Print direct link to plugin settings in plugins list in admin
|
9 |
+
* @function iaff_plugin_row_meta() Add donate and other links to plugins list
|
10 |
+
* @function iaff_footer_text() Admin footer text
|
11 |
+
* @function iaff_footer_version() Admin footer version
|
12 |
+
*/
|
13 |
+
|
14 |
+
|
15 |
+
// Exit if accessed directly
|
16 |
+
if ( !defined('ABSPATH') ) exit;
|
17 |
+
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Plugin activatation todo list
|
21 |
+
*
|
22 |
+
* This function runs when user activates the plugin
|
23 |
+
* @since 1.0
|
24 |
+
*/
|
25 |
+
function iaff_activate_plugin() {
|
26 |
+
add_option( 'iaff_bulk_updater_counter', '0' ); // Setting numer of images processed as zero
|
27 |
+
}
|
28 |
+
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Load plugin text domain
|
32 |
+
*
|
33 |
+
* @since 1.0
|
34 |
+
*/
|
35 |
+
function iaff_load_plugin_textdomain() {
|
36 |
+
load_plugin_textdomain( 'abl_iaff_td', FALSE, IAFF_STARTER_PLUGIN_DIR . '/languages/' );
|
37 |
+
}
|
38 |
+
add_action( 'plugins_loaded', 'iaff_load_plugin_textdomain' );
|
39 |
+
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Print direct link to plugin settings in plugins list in admin
|
43 |
+
*
|
44 |
+
* @since 1.0
|
45 |
+
*/
|
46 |
+
function iaff_settings_link( $links ) {
|
47 |
+
return array_merge(
|
48 |
+
array(
|
49 |
+
'settings' => '<a href="' . admin_url( 'options-general.php?page=image-attributes-from-filename' ) . '">' . __( 'Settings', 'abl_iaff_td' ) . '</a>'
|
50 |
+
),
|
51 |
+
$links
|
52 |
+
);
|
53 |
+
}
|
54 |
+
add_filter( 'plugin_action_links_' . IAFF_STARTER_PLUGIN . '/iaff_image-attributes-from-filename.php', 'iaff_settings_link' );
|
55 |
+
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Add donate and other links to plugins list
|
59 |
+
*
|
60 |
+
* @since 1.0
|
61 |
+
*/
|
62 |
+
function iaff_plugin_row_meta( $links, $file ) {
|
63 |
+
if ( strpos( $file, 'iaff_image-attributes-from-filename.php' ) !== false ) {
|
64 |
+
$new_links = array(
|
65 |
+
'donate' => '<a href="http://millionclues.com/donate/" target="_blank">Donate</a>',
|
66 |
+
'hireme' => '<a href="http://millionclues.com/portfolio/" target="_blank">Hire Me For A Project</a>',
|
67 |
+
);
|
68 |
+
$links = array_merge( $links, $new_links );
|
69 |
+
}
|
70 |
+
return $links;
|
71 |
+
}
|
72 |
+
add_filter( 'plugin_row_meta', 'iaff_plugin_row_meta', 10, 2 );
|
73 |
+
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Admin footer text
|
77 |
+
*
|
78 |
+
* A function to add footer text to the settings page of the plugin. Footer text contains plugin rating and donation links.
|
79 |
+
* Note: Remove the rating link if the plugin doesn't have a WordPress.org directory listing yet. (i.e. before initial approval)
|
80 |
+
* @since 1.0
|
81 |
+
* @refer https://codex.wordpress.org/Function_Reference/get_current_screen
|
82 |
+
*/
|
83 |
+
function iaff_footer_text($default) {
|
84 |
+
|
85 |
+
// Retun default on non-plugin pages
|
86 |
+
$screen = get_current_screen();
|
87 |
+
if ( $screen->id !== "settings_page_image-attributes-from-filename" ) {
|
88 |
+
return $default;
|
89 |
+
}
|
90 |
+
|
91 |
+
$iaff_footer_text = sprintf( __( 'If you like this plugin, please <a href="%s" target="_blank">make a donation</a> or leave a <a href="%s" target="_blank">★★★★★</a> rating to support continued development. Thanks a bunch!', 'abl_iaff_td' ),
|
92 |
+
'http://millionclues.com/donate/',
|
93 |
+
'https://wordpress.org/support/plugin/auto-image-attributes-from-filename-with-bulk-updater/reviews/?rate=5#new-post'
|
94 |
+
);
|
95 |
+
|
96 |
+
return $iaff_footer_text;
|
97 |
+
}
|
98 |
+
add_filter('admin_footer_text', 'iaff_footer_text');
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Admin footer version
|
102 |
+
*
|
103 |
+
* @since 1.3
|
104 |
+
*/
|
105 |
+
function iaff_footer_version($default) {
|
106 |
+
|
107 |
+
// Retun default on non-plugin pages
|
108 |
+
$screen = get_current_screen();
|
109 |
+
if ( $screen->id !== "settings_page_image-attributes-from-filename" ) {
|
110 |
+
return $default;
|
111 |
+
}
|
112 |
+
|
113 |
+
return 'Plugin version ' . IAFF_VERSION_NUM;
|
114 |
+
}
|
115 |
+
add_filter( 'update_footer', 'iaff_footer_version', 11 );
|
116 |
+
|
117 |
+
?>
|
admin/iaff_image-attributes-from-filename-do.php
ADDED
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Operations of the plugin are included here.
|
4 |
+
*
|
5 |
+
* @since 1.3
|
6 |
+
* @function iaff_auto_image_attributes() Auto add image attributes from image filename for new uploads
|
7 |
+
* @function iaff_rename_old_image() Auto add image attributes from image filename for existing uploads
|
8 |
+
* @function iaff_number_of_images_updated() Count number of images updated by the bulk updater
|
9 |
+
* @function iaff_total_number_of_images() Count total number of images in the database
|
10 |
+
* @function iaff_count_remaining_images() Count remaining number of images to process
|
11 |
+
* @function iaff_reset_bulk_updater_counter() Reset counter to zero so that bulk updating starts from scratch
|
12 |
+
* @function iaff_image_bulk_updater() Bulk Updater Ajax
|
13 |
+
* @function iaff_lcb_restore_image_title() Insert Image Title Into Post HTML
|
14 |
+
* @function iaff_upload_comma_prefilter() Replace commas in filename with -_-
|
15 |
+
*/
|
16 |
+
|
17 |
+
|
18 |
+
// Exit if accessed directly
|
19 |
+
if ( !defined('ABSPATH') ) exit;
|
20 |
+
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Auto add image attributes from image filename for new uploads
|
24 |
+
*
|
25 |
+
* @since 1.0
|
26 |
+
*/
|
27 |
+
function iaff_auto_image_attributes( $post_ID ) {
|
28 |
+
|
29 |
+
// Default Values For Settings
|
30 |
+
global $defaults;
|
31 |
+
|
32 |
+
// Get Settings
|
33 |
+
$settings = get_option('iaff_settings', $defaults);
|
34 |
+
|
35 |
+
$attachment = get_post( $post_ID );
|
36 |
+
|
37 |
+
// Extract the image name from the image url
|
38 |
+
$image_extension = pathinfo($attachment->guid);
|
39 |
+
$attachment_title = basename($attachment->guid, '.'.$image_extension['extension']);
|
40 |
+
|
41 |
+
$filter_chars = array();
|
42 |
+
|
43 |
+
if ( isset( $settings['hyphens'] ) && boolval($settings['hyphens']) ) {
|
44 |
+
$filter_chars[] = '-'; // Hypen
|
45 |
+
}
|
46 |
+
if ( isset( $settings['under_score'] ) && boolval($settings['under_score']) ) {
|
47 |
+
$filter_chars[] = '_'; // Underscore
|
48 |
+
}
|
49 |
+
if ( isset( $settings['full_stop'] ) && boolval($settings['full_stop']) ) {
|
50 |
+
$filter_chars[] = '.'; // Full stops
|
51 |
+
}
|
52 |
+
if ( isset( $settings['commas'] ) && boolval($settings['commas']) ) {
|
53 |
+
$filter_chars[] = '-_-'; // WordPress removes commas during file upload. iaff_upload_comma_prefilter() replaces commas with -_- so that we can process commas here.
|
54 |
+
}
|
55 |
+
|
56 |
+
// Remove characters
|
57 |
+
if ( !empty($filter_chars) ) {
|
58 |
+
$attachment_title = str_replace( $filter_chars, ' ', $attachment_title );
|
59 |
+
}
|
60 |
+
|
61 |
+
// Remove all numbers
|
62 |
+
if ( isset( $settings['all_numbers'] ) && boolval($settings['all_numbers']) ) {
|
63 |
+
$attachment_title = preg_replace('/[0-9]+/', '', $attachment_title);
|
64 |
+
}
|
65 |
+
|
66 |
+
// Final cleanup
|
67 |
+
$attachment_title = preg_replace('/\s\s+/', ' ', $attachment_title); // Replace multiple spaces with a single spaces
|
68 |
+
$attachment_title = trim($attachment_title); // Remove white spaces from both ends
|
69 |
+
$attachment_title = ucwords( $attachment_title ); // Capitalize First Word
|
70 |
+
|
71 |
+
$uploaded_image = array();
|
72 |
+
$uploaded_image['ID'] = $post_ID;
|
73 |
+
|
74 |
+
if ( isset( $settings['image_title'] ) && boolval($settings['image_title']) ) {
|
75 |
+
$uploaded_image['post_title'] = $attachment_title; // Image Title
|
76 |
+
}
|
77 |
+
if ( isset( $settings['image_caption'] ) && boolval($settings['image_caption']) ) {
|
78 |
+
$uploaded_image['post_excerpt'] = $attachment_title; // Image Caption
|
79 |
+
}
|
80 |
+
if ( isset( $settings['image_description'] ) && boolval($settings['image_description']) ) {
|
81 |
+
$uploaded_image['post_content'] = $attachment_title; // Image Description
|
82 |
+
}
|
83 |
+
if ( isset( $settings['image_alttext'] ) && boolval($settings['image_alttext']) ) {
|
84 |
+
update_post_meta( $post_ID, '_wp_attachment_image_alt', $attachment_title ); // Image Alt Text
|
85 |
+
}
|
86 |
+
|
87 |
+
wp_update_post( $uploaded_image );
|
88 |
+
|
89 |
+
}
|
90 |
+
add_action( 'add_attachment', 'iaff_auto_image_attributes' );
|
91 |
+
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Auto add image attributes from image filename for existing uploads
|
95 |
+
*
|
96 |
+
* @since 1.0
|
97 |
+
*/
|
98 |
+
function iaff_rename_old_image() {
|
99 |
+
|
100 |
+
// Security Check
|
101 |
+
check_ajax_referer( 'iaff_rename_old_image_nonce', 'security' );
|
102 |
+
|
103 |
+
// Retrieve Counter
|
104 |
+
$counter = get_option('iaff_bulk_updater_counter');
|
105 |
+
$counter = intval ($counter);
|
106 |
+
|
107 |
+
global $wpdb;
|
108 |
+
$image = $wpdb->get_row("SELECT ID,guid FROM {$wpdb->prefix}posts WHERE post_type='attachment' ORDER BY post_date LIMIT 1 OFFSET {$counter}");
|
109 |
+
|
110 |
+
// Die If No Image
|
111 |
+
if ($image === NULL) {
|
112 |
+
wp_die();
|
113 |
+
}
|
114 |
+
|
115 |
+
// Extract the image name from the image url
|
116 |
+
$image_extension = pathinfo($image->guid);
|
117 |
+
$image_name = basename($image->guid, '.'.$image_extension['extension']);
|
118 |
+
|
119 |
+
// Process the image name and neatify it
|
120 |
+
$image_name = str_replace( '-', ' ', $image_name ); // replace hyphens with spaces
|
121 |
+
$image_name = str_replace( '_', ' ', $image_name ); // replace underscores with spaces
|
122 |
+
$image_name = ucwords( $image_name ); // Capitalize each word
|
123 |
+
|
124 |
+
// Update the image Title, Caption and Description with the image name
|
125 |
+
$updated_image = array(
|
126 |
+
'ID' => $image->ID,
|
127 |
+
'post_title' => $image_name, // Image Title
|
128 |
+
'post_excerpt' => $image_name, // Image Caption
|
129 |
+
'post_content' => $image_name, // Image Description
|
130 |
+
);
|
131 |
+
wp_update_post( $updated_image );
|
132 |
+
|
133 |
+
// Update Image Alt Text (stored in post_meta table)
|
134 |
+
update_post_meta( $image->ID, '_wp_attachment_image_alt', $image_name ); // Image Alt Text
|
135 |
+
|
136 |
+
// Increment Counter And Update It
|
137 |
+
$counter++;
|
138 |
+
update_option( 'iaff_bulk_updater_counter', $counter );
|
139 |
+
|
140 |
+
echo __('Image Attributes Updated For: ', 'abl_iaff_td') . $image->guid;
|
141 |
+
wp_die();
|
142 |
+
}
|
143 |
+
add_action( 'wp_ajax_iaff_rename_old_image', 'iaff_rename_old_image' );
|
144 |
+
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Print number of images updated by the bulk updater
|
148 |
+
*
|
149 |
+
* @since 1.0
|
150 |
+
*/
|
151 |
+
function iaff_number_of_images_updated() {
|
152 |
+
|
153 |
+
$iaff_images_updated_counter = get_option('iaff_bulk_updater_counter');
|
154 |
+
return $iaff_images_updated_counter;
|
155 |
+
}
|
156 |
+
|
157 |
+
|
158 |
+
/**
|
159 |
+
* Count total number of images in the database
|
160 |
+
*
|
161 |
+
* @since 1.0
|
162 |
+
*/
|
163 |
+
function iaff_total_number_of_images() {
|
164 |
+
|
165 |
+
global $wpdb;
|
166 |
+
$total_no_of_images = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->prefix}posts WHERE post_type='attachment'");
|
167 |
+
|
168 |
+
return $total_no_of_images;
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Count remaining number of images to process
|
173 |
+
*
|
174 |
+
* @since 1.0
|
175 |
+
* @return integer Returns the number of remaining images to process.
|
176 |
+
* @param $force_return When set as true the function will always return a value even when called from ajax.
|
177 |
+
*/
|
178 |
+
function iaff_count_remaining_images( $force_return = false ) {
|
179 |
+
|
180 |
+
$total_no_of_images = iaff_total_number_of_images();
|
181 |
+
|
182 |
+
$no_of_images_processed = get_option('iaff_bulk_updater_counter');
|
183 |
+
$no_of_images_processed = intval ($no_of_images_processed);
|
184 |
+
|
185 |
+
$reamining_images = $total_no_of_images - $no_of_images_processed;
|
186 |
+
|
187 |
+
// If called from Ajax echo the result. Else return as an integer.
|
188 |
+
// :TODO: Calling iaff_count_remaining_images() from Ajax for ignores the default value of $force_return for some reason. When I set if ( wp_doing_ajax() && $force_return === false ) this does not work even though they are logically equivalent. If you know why it is so, please email me - arunbasillal@gmail.com
|
189 |
+
if ( wp_doing_ajax() && $force_return !== true ) {
|
190 |
+
echo $reamining_images;
|
191 |
+
wp_die();
|
192 |
+
} else {
|
193 |
+
return $reamining_images;
|
194 |
+
}
|
195 |
+
}
|
196 |
+
add_action( 'wp_ajax_iaff_count_remaining_images', 'iaff_count_remaining_images' );
|
197 |
+
|
198 |
+
|
199 |
+
/**
|
200 |
+
* Reset counter to zero so that bulk updating starts from scratch
|
201 |
+
*
|
202 |
+
* @since 1.0
|
203 |
+
*/
|
204 |
+
function iaff_reset_bulk_updater_counter() {
|
205 |
+
|
206 |
+
// Security Check
|
207 |
+
check_ajax_referer( 'iaff_reset_counter_nonce', 'security' );
|
208 |
+
|
209 |
+
update_option( 'iaff_bulk_updater_counter', '0' );
|
210 |
+
|
211 |
+
$response = array(
|
212 |
+
'message' => __('Counter reset. The bulk updater will start from scratch in the next run.', 'abl_iaff_td'),
|
213 |
+
'remaining_images' => iaff_count_remaining_images(true),
|
214 |
+
);
|
215 |
+
wp_send_json($response);
|
216 |
+
}
|
217 |
+
add_action( 'wp_ajax_iaff_reset_bulk_updater_counter', 'iaff_reset_bulk_updater_counter' );
|
218 |
+
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Bulk Updater Ajax
|
222 |
+
*
|
223 |
+
* @since 1.0
|
224 |
+
*/
|
225 |
+
function iaff_image_bulk_updater() {
|
226 |
+
|
227 |
+
// Load Ajax Only On Plugin Page
|
228 |
+
$screen = get_current_screen();
|
229 |
+
if ( $screen->id !== "settings_page_image-attributes-from-filename" ) {
|
230 |
+
return;
|
231 |
+
}?>
|
232 |
+
|
233 |
+
<script type="text/javascript" >
|
234 |
+
jQuery(document).ready(function($) {
|
235 |
+
// Reset Bulk Updater Counter
|
236 |
+
$('.iaff_reset_counter_button').click(function() {
|
237 |
+
data = {
|
238 |
+
action: 'iaff_reset_bulk_updater_counter',
|
239 |
+
security: '<?php echo wp_create_nonce( "iaff_reset_counter_nonce" ); ?>'
|
240 |
+
};
|
241 |
+
|
242 |
+
$.post(ajaxurl, data, function (response) {
|
243 |
+
$('#bulk-updater-log').append('<p>Number of Images Remaining: ' + response.remaining_images + '</p>');
|
244 |
+
$('#bulk-updater-log').append('<p>Number of Images Updated: 0</p>');
|
245 |
+
$("#bulk-updater-log").animate({scrollTop:$("#bulk-updater-log")[0].scrollHeight - $("#bulk-updater-log").height()},200);
|
246 |
+
alert(response.message);
|
247 |
+
});
|
248 |
+
});
|
249 |
+
|
250 |
+
// Run Bulk Updater
|
251 |
+
$('.iaff_run_bulk_updater_button').click(function() {
|
252 |
+
// Re-confirm from the user
|
253 |
+
var r = confirm("You are about to update all images in the Media Library. This cannot be undone.\nPress OK to confirm.");
|
254 |
+
if (r !== true) {
|
255 |
+
$('#bulk-updater-log').append('<p class="iaff-red">Operation aborted by user.</p>');
|
256 |
+
$("#bulk-updater-log").animate({scrollTop:$("#bulk-updater-log")[0].scrollHeight - $("#bulk-updater-log").height()},200);
|
257 |
+
return;
|
258 |
+
}
|
259 |
+
|
260 |
+
// Notice to the user
|
261 |
+
$('#bulk-updater-log').append('<p class="iaff-green">Initializing bulk updater. Be Patient and do not close the browser while it\'s running. In case you do, you can always resume by returning to this page later.</p>');
|
262 |
+
$("#bulk-updater-log").animate({scrollTop:$("#bulk-updater-log")[0].scrollHeight - $("#bulk-updater-log").height()},200);
|
263 |
+
|
264 |
+
// Count Remaining Images To Process
|
265 |
+
data = {
|
266 |
+
action: 'iaff_count_remaining_images',
|
267 |
+
};
|
268 |
+
|
269 |
+
var remaining_images = null;
|
270 |
+
|
271 |
+
var reamining_images_count = $.post(ajaxurl, data, function (response) {
|
272 |
+
remaining_images = response;
|
273 |
+
console.log(remaining_images);
|
274 |
+
});
|
275 |
+
|
276 |
+
// Loop For Each Image And Update Its Attributes
|
277 |
+
reamining_images_count.done(function iaff_rename_image() {
|
278 |
+
|
279 |
+
if(remaining_images > 0){
|
280 |
+
data = {
|
281 |
+
action: 'iaff_rename_old_image',
|
282 |
+
security: '<?php echo wp_create_nonce( "iaff_rename_old_image_nonce" ); ?>'
|
283 |
+
};
|
284 |
+
|
285 |
+
var rename_image = $.post(ajaxurl, data, function (response) {
|
286 |
+
$('#bulk-updater-log').append('<p>' + response + '</p>');
|
287 |
+
$('#bulk-updater-log').append('<p>Images remaining: ' + (remaining_images-1) + '</p>');
|
288 |
+
$("#bulk-updater-log").animate({scrollTop:$("#bulk-updater-log")[0].scrollHeight - $("#bulk-updater-log").height()},100);
|
289 |
+
console.log(response);
|
290 |
+
});
|
291 |
+
|
292 |
+
rename_image.done(function() {
|
293 |
+
remaining_images--;
|
294 |
+
iaff_rename_image();
|
295 |
+
});
|
296 |
+
}
|
297 |
+
else {
|
298 |
+
$('#bulk-updater-log').append('<p class="iaff-green"><span class="dashicons dashicons-yes"></span>All done!</p>');
|
299 |
+
$("#bulk-updater-log").animate({scrollTop:$("#bulk-updater-log")[0].scrollHeight - $("#bulk-updater-log").height()},200);
|
300 |
+
}
|
301 |
+
});
|
302 |
+
});
|
303 |
+
});
|
304 |
+
</script> <?php
|
305 |
+
}
|
306 |
+
add_action( 'admin_footer', 'iaff_image_bulk_updater' );
|
307 |
+
|
308 |
+
|
309 |
+
/**
|
310 |
+
* Insert Image Title Into Post HTML
|
311 |
+
*
|
312 |
+
* Since WordPress 3.5 images inserted into posts do not have the title attribute with the image tag.
|
313 |
+
* The following functions were written by Les Bessant in his Restore Image Title plugin to restore the pre 3.5 feature.
|
314 |
+
* @since 1.3
|
315 |
+
* @author Les Bessant - https://profiles.wordpress.org/lesbessant
|
316 |
+
* @refer https://wordpress.org/plugins/restore-image-title/
|
317 |
+
*/
|
318 |
+
function iaff_lcb_restore_image_title( $html, $id ) {
|
319 |
+
$attachment = get_post($id);
|
320 |
+
if (strpos($html, "title=")) {
|
321 |
+
return $html;
|
322 |
+
} else {
|
323 |
+
$mytitle = esc_attr($attachment->post_title);
|
324 |
+
return str_replace('<img', '<img title="' . $mytitle . '" ' , $html);
|
325 |
+
}
|
326 |
+
}
|
327 |
+
function iaff_lcb_restore_title_to_gallery( $content, $id ) {
|
328 |
+
$thumb_title = get_the_title($id);
|
329 |
+
return str_replace('<a', '<a title="' . esc_attr($thumb_title) . '" ', $content);
|
330 |
+
}
|
331 |
+
|
332 |
+
// Insert image title to post HTML only if it is enabled in the settings. Disabled by default.
|
333 |
+
$settings = get_option('iaff_settings');
|
334 |
+
if ( isset($settings['image_title_to_html']) && ($settings['image_title_to_html'] == 1) ) {
|
335 |
+
add_filter( 'media_send_to_editor', 'iaff_lcb_restore_image_title', 15, 2 );
|
336 |
+
add_filter('wp_get_attachment_link', 'iaff_lcb_restore_title_to_gallery', 10, 4);
|
337 |
+
}
|
338 |
+
|
339 |
+
|
340 |
+
/**
|
341 |
+
* Replace commas in filename with -_-
|
342 |
+
*
|
343 |
+
* WordPress removes commas during file upload. This function replaces commas with -_- so that we can replace them later. Without this red,pill.jpg will become redpill.jpg and we cannot extract the word 'Red Pill' with the space out of it.
|
344 |
+
* @since 1.3
|
345 |
+
* @refer https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter
|
346 |
+
*/
|
347 |
+
function iaff_upload_comma_prefilter( $file ){
|
348 |
+
$settings = get_option('iaff_settings');
|
349 |
+
|
350 |
+
if ( isset($settings['commas']) && ($settings['commas'] == 1) ) {
|
351 |
+
$file['name'] = str_replace( ',', '-_-', $file['name'] );
|
352 |
+
return $file;
|
353 |
+
} else {
|
354 |
+
return $file;
|
355 |
+
}
|
356 |
+
}
|
357 |
+
add_filter('wp_handle_upload_prefilter', 'iaff_upload_comma_prefilter' );
|
358 |
+
|
359 |
+
?>
|
admin/iaff_image-attributes-from-filename-loader.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Loads the plugin files
|
4 |
+
*
|
5 |
+
* @since 1.3
|
6 |
+
*/
|
7 |
+
|
8 |
+
|
9 |
+
// Exit if accessed directly
|
10 |
+
if ( !defined('ABSPATH') ) exit;
|
11 |
+
|
12 |
+
|
13 |
+
// Load basic setup. Plugin list links, text domain, footer links etc.
|
14 |
+
require_once( IAFF_STARTER_PLUGIN_DIR . '/admin/iaff_image-attributes-from-filename-basic-setup.php');
|
15 |
+
|
16 |
+
// Load admin setup. Register menus and settings
|
17 |
+
require_once( IAFF_STARTER_PLUGIN_DIR . '/admin/iaff_image-attributes-from-filename-admin-setup.php');
|
18 |
+
|
19 |
+
// Render Admin UI
|
20 |
+
require_once( IAFF_STARTER_PLUGIN_DIR . '/admin/iaff_image-attributes-from-filename-admin-ui-render.php');
|
21 |
+
|
22 |
+
// Do plugin operations
|
23 |
+
require_once( IAFF_STARTER_PLUGIN_DIR . '/admin/iaff_image-attributes-from-filename-do.php');
|
24 |
+
|
25 |
+
?>
|
admin/index.php
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden
|
3 |
+
?>
|
iaff_image-attributes-from-filename.php
CHANGED
@@ -1,495 +1,80 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
Plugin Name: Auto Image Attributes From Filename With Bulk Updater
|
4 |
-
Plugin URI: http://millionclues.com/
|
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: http://millionclues.com
|
8 |
-
Version: 1.
|
9 |
-
Text Domain: abl_iaff_td
|
10 |
-
Domain Path: /languages
|
11 |
-
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
12 |
-
*/
|
13 |
|
14 |
-
|
15 |
-
/*------------------------------------------*/
|
16 |
-
/* Plugin Setup Functions */
|
17 |
-
/*------------------------------------------*/
|
18 |
-
|
19 |
-
// Exit If Accessed Directly
|
20 |
-
if ( ! defined( 'ABSPATH' ) ) exit;
|
21 |
-
|
22 |
-
|
23 |
-
// Add Admin Menu Pages
|
24 |
-
// Refer: https://developer.wordpress.org/plugins/administration-menus/
|
25 |
-
function iaff_add_menu_links() {
|
26 |
-
add_options_page( __('Auto Image Attributes','abl_iaff_td'), __('Image Attributes','abl_iaff_td'), 'manage_options', 'image-attributes-from-filename','iaff_admin_interface_render' );
|
27 |
-
}
|
28 |
-
add_action( 'admin_menu', 'iaff_add_menu_links' );
|
29 |
-
|
30 |
-
|
31 |
-
// Print Direct Link To Plugin Settings In Plugins List In Admin
|
32 |
-
function iaff_settings_link( $links ) {
|
33 |
-
return array_merge(
|
34 |
-
array(
|
35 |
-
'settings' => '<a href="' . admin_url( 'options-general.php?page=image-attributes-from-filename' ) . '">' . __( 'Settings', 'abl_iaff_td' ) . '</a>'
|
36 |
-
),
|
37 |
-
$links
|
38 |
-
);
|
39 |
-
}
|
40 |
-
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'iaff_settings_link' );
|
41 |
-
|
42 |
-
|
43 |
-
// Add Donate Link to Plugins list
|
44 |
-
function iaff_plugin_row_meta( $links, $file ) {
|
45 |
-
if ( strpos( $file, 'iaff_image-attributes-from-filename.php' ) !== false ) {
|
46 |
-
$new_links = array(
|
47 |
-
'donate' => '<a href="http://millionclues.com/donate/" target="_blank">Donate</a>',
|
48 |
-
'kuttappi' => '<a href="http://kuttappi.com/" target="_blank">My Travelogue</a>',
|
49 |
-
);
|
50 |
-
$links = array_merge( $links, $new_links );
|
51 |
-
}
|
52 |
-
return $links;
|
53 |
-
}
|
54 |
-
add_filter( 'plugin_row_meta', 'iaff_plugin_row_meta', 10, 2 );
|
55 |
-
|
56 |
-
|
57 |
-
// Load Text Domain
|
58 |
-
function iaff_load_plugin_textdomain() {
|
59 |
-
load_plugin_textdomain( 'abl_iaff_td', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
|
60 |
-
}
|
61 |
-
add_action( 'plugins_loaded', 'iaff_load_plugin_textdomain' );
|
62 |
-
|
63 |
-
|
64 |
-
// Do Stuff On Plugin Activation
|
65 |
-
function iaff_activate_plugin() {
|
66 |
-
add_option( 'iaff_bulk_updater_counter', '0' ); // Setting numer of images processed as zero
|
67 |
-
}
|
68 |
-
register_activation_hook( __FILE__, 'iaff_activate_plugin' );
|
69 |
-
|
70 |
-
|
71 |
-
// Register Settings
|
72 |
-
function iaff_register_settings() {
|
73 |
-
|
74 |
-
// Register Setting
|
75 |
-
register_setting(
|
76 |
-
'iaff_settings_group', // Group Name
|
77 |
-
'iaff_settings' // Setting Name = HTML form <input> name on settings form
|
78 |
-
);
|
79 |
-
|
80 |
-
// Register A New Section
|
81 |
-
add_settings_section(
|
82 |
-
'iaff_auto_image_attributes_settings', // ID
|
83 |
-
__('Auto Image Attributes For New Uploads', 'abl_iaff_td'), // Title
|
84 |
-
'iaff_auto_image_attributes_callback', // Callback Function
|
85 |
-
'image-attributes-from-filename' // Page slug
|
86 |
-
);
|
87 |
-
|
88 |
-
// General Settings
|
89 |
-
add_settings_field(
|
90 |
-
'iaff_general_settings', // ID
|
91 |
-
__('General Settings', 'abl_iaff_td'), // Title
|
92 |
-
'iaff_auto_image_attributes_settings_field_callback', // Callback function
|
93 |
-
'image-attributes-from-filename', // Page slug
|
94 |
-
'iaff_auto_image_attributes_settings' // Settings Section ID
|
95 |
-
);
|
96 |
-
|
97 |
-
// Filter Settings
|
98 |
-
add_settings_field(
|
99 |
-
'iaff_filter_settings', // ID
|
100 |
-
__('Filter Settings', 'abl_iaff_td'), // Title
|
101 |
-
'iaff_auto_image_attributes_filter_settings_callback', // Callback function
|
102 |
-
'image-attributes-from-filename', // Page slug
|
103 |
-
'iaff_auto_image_attributes_settings' // Settings Section ID
|
104 |
-
);
|
105 |
-
|
106 |
-
}
|
107 |
-
add_action( 'admin_init', 'iaff_register_settings' );
|
108 |
-
|
109 |
-
|
110 |
-
// Do Stuff On Plugin Uninstall
|
111 |
-
function iaff_uninstall_plugin() {
|
112 |
-
delete_option( 'iaff_settings' );
|
113 |
-
delete_option( 'iaff_bulk_updater_counter' );
|
114 |
-
delete_option( 'iaff_image_attributes_from_filename_settings' ); // Used in Ver 1.0 of the plugin. Simpler days.
|
115 |
-
}
|
116 |
-
register_uninstall_hook(__FILE__, 'iaff_uninstall_plugin' );
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
/*--------------------------------------*/
|
121 |
-
/* Admin Options Page */
|
122 |
-
/*--------------------------------------*/
|
123 |
-
|
124 |
-
function iaff_auto_image_attributes_callback() {
|
125 |
-
echo '<p>' . __('Automatically add Image attributes such as Image Title, Image Caption, Description And Alt Text from Image Filename for new uploads.', 'abl_iaff_td') . '</p>';
|
126 |
-
}
|
127 |
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
'image_title' => '1',
|
134 |
-
'image_caption' => '1',
|
135 |
-
'image_description' => '1',
|
136 |
-
'image_alttext' => '1'
|
137 |
-
);
|
138 |
-
|
139 |
-
// Get Settings
|
140 |
-
$settings = get_option('iaff_settings', $defaults);
|
141 |
-
|
142 |
-
// General Settings. Name of form element should be same as the setting name in register_setting(). ?>
|
143 |
-
|
144 |
-
<!-- Auto Add Image Title -->
|
145 |
-
<input type="checkbox" name="iaff_settings[image_title]" id="iaff_settings[image_title]" value="1"
|
146 |
-
<?php if ( isset( $settings['image_title'] ) ) { checked( '1', $settings['image_title'] ); } ?>>
|
147 |
-
<label for="iaff_settings[image_title]"><?php _e('Set Image Title from filename for new uploads', 'abl_iaff_td') ?></label>
|
148 |
-
<br>
|
149 |
-
|
150 |
-
<!-- Auto Add Image Caption -->
|
151 |
-
<input type="checkbox" name="iaff_settings[image_caption]" id="iaff_settings[image_caption]" value="1"
|
152 |
-
<?php if ( isset( $settings['image_caption'] ) ) { checked( '1', $settings['image_caption'] ); } ?>>
|
153 |
-
<label for="iaff_settings[image_caption]"><?php _e('Set Image Caption from filename for new uploads', 'abl_iaff_td') ?></label>
|
154 |
-
<br>
|
155 |
-
|
156 |
-
<!-- Auto Add Image Description -->
|
157 |
-
<input type="checkbox" name="iaff_settings[image_description]" id="iaff_settings[image_description]" value="1"
|
158 |
-
<?php if ( isset( $settings['image_description'] ) ) { checked( '1', $settings['image_description'] ); } ?>>
|
159 |
-
<label for="iaff_settings[image_description]"><?php _e('Set Image Description from filename for new uploads', 'abl_iaff_td') ?></label>
|
160 |
-
<br>
|
161 |
-
|
162 |
-
<!-- Auto Add Alt Text -->
|
163 |
-
<input type="checkbox" name="iaff_settings[image_alttext]" id="iaff_settings[image_alttext]" value="1"
|
164 |
-
<?php if ( isset( $settings['image_alttext'] ) ) { checked( '1', $settings['image_alttext'] ); } ?>>
|
165 |
-
<label for="iaff_settings[image_alttext]"><?php _e('Set Image Alt Text from filename for new uploads', 'abl_iaff_td') ?></label>
|
166 |
-
<br>
|
167 |
-
|
168 |
-
<?php
|
169 |
-
}
|
170 |
-
|
171 |
-
// Filter Settings Field Callback
|
172 |
-
function iaff_auto_image_attributes_filter_settings_callback() {
|
173 |
-
|
174 |
-
// Default Values For Settings
|
175 |
-
$defaults = array(
|
176 |
-
'hyphens' => '1',
|
177 |
-
'under_score' => '1',
|
178 |
-
);
|
179 |
-
|
180 |
-
// Get Settings
|
181 |
-
$settings = get_option('iaff_settings', $defaults); ?>
|
182 |
-
|
183 |
-
<!-- Filter Hyphens -->
|
184 |
-
<input type="checkbox" name="iaff_settings[hyphens]" id="iaff_settings[hyphens]" value="1"
|
185 |
-
<?php if ( isset( $settings['hyphens'] ) ) { checked( '1', $settings['hyphens'] ); } ?>>
|
186 |
-
<label for="iaff_settings[hyphens]"><?php _e('Remove hyphens ( - ) from filename', 'abl_iaff_td') ?></label>
|
187 |
-
<br>
|
188 |
-
|
189 |
-
<!-- Filter Underscore -->
|
190 |
-
<input type="checkbox" name="iaff_settings[under_score]" id="iaff_settings[under_score]" value="1"
|
191 |
-
<?php if ( isset( $settings['under_score'] ) ) { checked( '1', $settings['under_score'] ); } ?>>
|
192 |
-
<label for="iaff_settings[under_score]"><?php _e('Remove underscores ( _ ) from filename', 'abl_iaff_td') ?></label>
|
193 |
-
<br>
|
194 |
-
|
195 |
-
<?php
|
196 |
-
}
|
197 |
-
|
198 |
-
// Admin Interface Renderer
|
199 |
-
function iaff_admin_interface_render () {
|
200 |
-
|
201 |
-
if ( ! current_user_can( 'manage_options' ) ) {
|
202 |
-
return;
|
203 |
-
}
|
204 |
-
|
205 |
-
/* Commented out after moving menu location to Settings pages instead of Media as originally deisigned.
|
206 |
-
// https://core.trac.wordpress.org/ticket/31000
|
207 |
-
// Check if the user have submitted the settings
|
208 |
-
// WordPress will add the "settings-updated" $_GET parameter to the url
|
209 |
-
if ( isset( $_GET['settings-updated'] ) ) {
|
210 |
-
// Add settings saved message with the class of "updated"
|
211 |
-
add_settings_error( 'iaff_settings_saved_message', 'iaff_settings_saved_message', __( 'Settings are Saved', 'abl_iaff_td' ), 'updated' );
|
212 |
-
}
|
213 |
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
// Output save settings button
|
229 |
-
submit_button( __('Save Settings', 'abl_iaff_td') );
|
230 |
-
?>
|
231 |
-
</form>
|
232 |
-
|
233 |
-
<h2><?php _e('Update Existing Images In Media Library', 'abl_iaff_td') ?></h2>
|
234 |
-
|
235 |
-
<p style="color:red"><?php _e('IMPORTANT: Please backup your database before running the bulk updater.', 'abl_iaff_td') ?></p>
|
236 |
-
<p><?php _e('Run this bulk updater to update Image Title, Caption, Description and Alt Text from image filename for existing images in the media library.', 'abl_iaff_td') ?></p>
|
237 |
-
<p><?php _e('If your image is named a-lot-like-love.jpg, your Image Title, Caption, Description and Alt Text will be: A Lot Like Love. All attributes are updated regardless of the settings for NEW uploads.', 'abl_iaff_td') ?></p>
|
238 |
-
<p><?php _e('Be Patient and do not close the browser while it\'s running. In case you do, you can always resume by returning to this page later.', 'abl_iaff_td') ?></p> <?php
|
239 |
-
|
240 |
-
submit_button( __('Run Bulk Updater', 'abl_iaff_td'), 'iaff_run_bulk_updater_button' ); ?>
|
241 |
-
|
242 |
-
<p><?php _e('To restart processing images from the beginning (the oldest upload first), reset the counter.', 'abl_iaff_td') ?></p> <?php
|
243 |
-
submit_button( __('Reset Counter', 'abl_iaff_td'), 'iaff_reset_counter_button' ); ?>
|
244 |
-
|
245 |
-
<p><?php _e('Number of Images Updated: ', 'abl_iaff_td') ?><span id="iaff_updated_counter"><?php iaff_number_of_images_updated(); ?></span></p>
|
246 |
-
<p id="iaff_remaining_images_text" style="display: none;"><?php _e('Number of Images Remaining: ', 'abl_iaff_td') ?><span id="iaff_remaining_counter"><?php echo iaff_total_number_of_images(); ?></span></p>
|
247 |
-
|
248 |
-
<span id="iaff_bulk_updater_results"></span>
|
249 |
-
|
250 |
-
</div>
|
251 |
-
<?php
|
252 |
-
}
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
/*--------------------------------------*/
|
257 |
-
/* Plugin Operations */
|
258 |
-
/*--------------------------------------*/
|
259 |
-
|
260 |
-
|
261 |
-
// Auto Add Image Attributes From Image Filename For New Uploads
|
262 |
-
function iaff_auto_image_attributes( $post_ID ) {
|
263 |
-
|
264 |
-
// Default Values For Settings
|
265 |
-
$defaults = array(
|
266 |
-
'image_title' => '1',
|
267 |
-
'image_caption' => '1',
|
268 |
-
'image_description' => '1',
|
269 |
-
'image_alttext' => '1',
|
270 |
-
'hyphens' => '1',
|
271 |
-
'under_score' => '1',
|
272 |
-
);
|
273 |
-
// Get Settings
|
274 |
-
$settings = get_option('iaff_settings', $defaults);
|
275 |
-
|
276 |
-
$attachment = get_post( $post_ID );
|
277 |
-
$attachment_title = $attachment->post_title;
|
278 |
-
|
279 |
-
if ( isset( $settings['hyphens'] ) && boolval($settings['hyphens']) ) {
|
280 |
-
$attachment_title = str_replace( '-', ' ', $attachment_title ); // Hyphen Removal
|
281 |
-
}
|
282 |
-
if ( isset( $settings['under_score'] ) && boolval($settings['under_score']) ) {
|
283 |
-
$attachment_title = str_replace( '_', ' ', $attachment_title ); // Underscore Removal
|
284 |
-
}
|
285 |
-
|
286 |
-
$attachment_title = ucwords( $attachment_title ); // Capitalize First Word
|
287 |
-
|
288 |
-
$uploaded_image = array();
|
289 |
-
$uploaded_image['ID'] = $post_ID;
|
290 |
-
|
291 |
-
if ( isset( $settings['image_title'] ) && boolval($settings['image_title']) ) {
|
292 |
-
$uploaded_image['post_title'] = $attachment_title; // Image Title
|
293 |
-
}
|
294 |
-
if ( isset( $settings['image_caption'] ) && boolval($settings['image_caption']) ) {
|
295 |
-
$uploaded_image['post_excerpt'] = $attachment_title; // Image Caption
|
296 |
-
}
|
297 |
-
if ( isset( $settings['image_description'] ) && boolval($settings['image_description']) ) {
|
298 |
-
$uploaded_image['post_content'] = $attachment_title; // Image Description
|
299 |
-
}
|
300 |
-
if ( isset( $settings['image_alttext'] ) && boolval($settings['image_alttext']) ) {
|
301 |
-
update_post_meta( $post_ID, '_wp_attachment_image_alt', $attachment_title ); // Image Alt Text
|
302 |
-
}
|
303 |
-
|
304 |
-
wp_update_post( $uploaded_image );
|
305 |
-
|
306 |
-
}
|
307 |
-
add_action( 'add_attachment', 'iaff_auto_image_attributes' );
|
308 |
-
|
309 |
-
|
310 |
-
// Auto Add Image Attributes From Image Filename For Existing Uploads
|
311 |
-
function iaff_rename_old_image() {
|
312 |
-
|
313 |
-
// Security Check
|
314 |
-
check_ajax_referer( 'iaff_rename_old_image_nonce', 'security' );
|
315 |
-
|
316 |
-
// Retrieve Counter
|
317 |
-
$counter = get_option('iaff_bulk_updater_counter');
|
318 |
-
$counter = intval ($counter);
|
319 |
-
|
320 |
-
global $wpdb;
|
321 |
-
$image = $wpdb->get_row("SELECT ID,guid FROM {$wpdb->prefix}posts WHERE post_type='attachment' ORDER BY post_date LIMIT 1 OFFSET {$counter}");
|
322 |
-
|
323 |
-
// Die If No Image
|
324 |
-
if ($image === NULL) {
|
325 |
-
wp_die();
|
326 |
-
}
|
327 |
-
|
328 |
-
// Extract the image name from the image url
|
329 |
-
$image_extension = pathinfo($image->guid);
|
330 |
-
$image_name = basename($image->guid, '.'.$image_extension['extension']);
|
331 |
-
|
332 |
-
// Process the image name and neatify it
|
333 |
-
$image_name = str_replace( '-', ' ', $image_name ); // replace hyphens with spaces
|
334 |
-
$image_name = str_replace( '_', ' ', $image_name ); // replace underscores with spaces
|
335 |
-
$image_name = ucwords( $image_name ); // Capitalize each word
|
336 |
-
|
337 |
-
// Update the image Title, Caption and Description with the image name
|
338 |
-
$updated_image = array(
|
339 |
-
'ID' => $image->ID,
|
340 |
-
'post_title' => $image_name, // Image Title
|
341 |
-
'post_excerpt' => $image_name, // Image Caption
|
342 |
-
'post_content' => $image_name, // Image Description
|
343 |
-
);
|
344 |
-
wp_update_post( $updated_image );
|
345 |
-
|
346 |
-
// Update Image Alt Text (stored in post_meta table)
|
347 |
-
update_post_meta( $image->ID, '_wp_attachment_image_alt', $image_name ); // Image Alt Text
|
348 |
-
|
349 |
-
// Increment Counter And Update It
|
350 |
-
$counter++;
|
351 |
-
update_option( 'iaff_bulk_updater_counter', $counter );
|
352 |
-
|
353 |
-
echo __('Image Attributes Updated For Image: ', 'abl_iaff_td') . $image->guid;
|
354 |
-
wp_die();
|
355 |
-
}
|
356 |
-
add_action( 'wp_ajax_iaff_rename_old_image', 'iaff_rename_old_image' );
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
|
359 |
-
// Print Number Of Images Updated By The Bulk Updater
|
360 |
-
function iaff_number_of_images_updated() {
|
361 |
-
|
362 |
-
$iaff_images_updated_counter = get_option('iaff_bulk_updater_counter');
|
363 |
-
echo $iaff_images_updated_counter;
|
364 |
-
}
|
365 |
|
|
|
|
|
366 |
|
367 |
-
// Count Total Number Of Images In The Database
|
368 |
-
function iaff_total_number_of_images() {
|
369 |
-
|
370 |
-
global $wpdb;
|
371 |
-
$total_no_of_images = $wpdb->get_var("SELECT COUNT(ID) FROM {$wpdb->prefix}posts WHERE post_type='attachment'");
|
372 |
-
|
373 |
-
return $total_no_of_images;
|
374 |
-
}
|
375 |
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
echo $reamining_images;
|
386 |
-
|
387 |
-
wp_die();
|
388 |
-
}
|
389 |
-
add_action( 'wp_ajax_iaff_count_remaining_images', 'iaff_count_remaining_images' );
|
390 |
|
|
|
|
|
391 |
|
392 |
-
// Reset Counter To Zero So That Bulk Updating Starts From Scratch
|
393 |
-
function iaff_reset_bulk_updater_counter() {
|
394 |
-
|
395 |
-
// Security Check
|
396 |
-
check_ajax_referer( 'iaff_reset_counter_nonce', 'security' );
|
397 |
-
|
398 |
-
update_option( 'iaff_bulk_updater_counter', '0' );
|
399 |
-
echo __('Counter reset. The bulk updater will start from scratch in the next run.', 'abl_iaff_td');
|
400 |
-
|
401 |
-
wp_die();
|
402 |
-
}
|
403 |
-
add_action( 'wp_ajax_iaff_reset_bulk_updater_counter', 'iaff_reset_bulk_updater_counter' );
|
404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
-
// Bulk Updater Ajax
|
407 |
-
function iaff_image_bulk_updater() {
|
408 |
-
|
409 |
-
// Load Ajax Only On Plugin Page
|
410 |
-
$screen = get_current_screen();
|
411 |
-
if ( $screen->id !== "settings_page_image-attributes-from-filename" ) {
|
412 |
-
return;
|
413 |
-
}?>
|
414 |
|
415 |
-
|
416 |
-
|
417 |
-
// Reset Bulk Updater Counter
|
418 |
-
$('.iaff_reset_counter_button').click(function() {
|
419 |
-
data = {
|
420 |
-
action: 'iaff_reset_bulk_updater_counter',
|
421 |
-
security: '<?php echo wp_create_nonce( "iaff_reset_counter_nonce" ); ?>'
|
422 |
-
};
|
423 |
-
|
424 |
-
$.post(ajaxurl, data, function (response) {
|
425 |
-
alert(response);
|
426 |
-
$('#iaff_updated_counter').text('0');
|
427 |
-
});
|
428 |
-
});
|
429 |
-
|
430 |
-
// Run Bulk Updater
|
431 |
-
$('.iaff_run_bulk_updater_button').click(function() {
|
432 |
-
// Count Remaining Images To Process
|
433 |
-
data = {
|
434 |
-
action: 'iaff_count_remaining_images'
|
435 |
-
};
|
436 |
-
|
437 |
-
var remaining_images = null;
|
438 |
-
|
439 |
-
var reamining_images_count = $.post(ajaxurl, data, function (response) {
|
440 |
-
remaining_images = response;
|
441 |
-
console.log(remaining_images);
|
442 |
-
});
|
443 |
-
|
444 |
-
// Loop For Each Image And Update Its Attributes
|
445 |
-
reamining_images_count.done(function iaff_rename_image() {
|
446 |
-
|
447 |
-
if(remaining_images > 0){
|
448 |
-
|
449 |
-
$('#iaff_remaining_images_text').show(); // Show the text for remaining images
|
450 |
-
|
451 |
-
data = {
|
452 |
-
action: 'iaff_rename_old_image',
|
453 |
-
security: '<?php echo wp_create_nonce( "iaff_rename_old_image_nonce" ); ?>'
|
454 |
-
};
|
455 |
-
|
456 |
-
var rename_image = $.post(ajaxurl, data, function (response) {
|
457 |
-
$('#iaff_bulk_updater_results').append('<p>' + response + '</p>');
|
458 |
-
var updated_counter = parseInt($('#iaff_updated_counter').text());
|
459 |
-
$('#iaff_updated_counter').text(updated_counter+1); // Update total number of images updated
|
460 |
-
$('#iaff_remaining_counter').text(remaining_images-1); // Update total number of images remaining
|
461 |
-
console.log(response);
|
462 |
-
});
|
463 |
-
|
464 |
-
rename_image.done(function() {
|
465 |
-
remaining_images--;
|
466 |
-
iaff_rename_image();
|
467 |
-
});
|
468 |
-
}
|
469 |
-
else {
|
470 |
-
$('#iaff_bulk_updater_results').append('<p>All done!</p>')
|
471 |
-
$('#iaff_remaining_counter').text('All done!')
|
472 |
-
}
|
473 |
-
});
|
474 |
-
});
|
475 |
-
});
|
476 |
-
</script> <?php
|
477 |
-
}
|
478 |
-
add_action( 'admin_footer', 'iaff_image_bulk_updater' );
|
479 |
|
|
|
|
|
480 |
|
481 |
-
// Admin Footer Text - Ask For 5 Star Rating.
|
482 |
-
function iaff_footer_text($default) {
|
483 |
-
|
484 |
-
// Retun Default On Non-plugin Pages
|
485 |
-
$screen = get_current_screen();
|
486 |
-
if ( $screen->id !== "settings_page_image-attributes-from-filename" ) {
|
487 |
-
return $default;
|
488 |
-
}
|
489 |
-
|
490 |
-
$iaff_footer_text = sprintf( __( 'If you like this plugin please leave me a %s rating. Thanks a bunch!', 'abl_iaff_td' ), '<a href="https://wordpress.org/support/plugin/auto-image-attributes-from-filename-with-bulk-updater/reviews/?rate=5#new-post" target="_blank">★★★★★</a>' );
|
491 |
-
|
492 |
-
return $iaff_footer_text;
|
493 |
-
}
|
494 |
-
add_filter('admin_footer_text', 'iaff_footer_text');
|
495 |
?>
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: Auto Image Attributes From Filename With Bulk Updater
|
4 |
+
* Plugin URI: http://millionclues.com/
|
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: http://millionclues.com
|
8 |
+
* Version: 1.3
|
9 |
+
* Text Domain: abl_iaff_td
|
10 |
+
* Domain Path: /languages
|
11 |
+
* License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
12 |
+
*/
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
/**
|
16 |
+
* This plugin was developed using the WordPress starter plugin template by Arun Basil Lal <arunbasillal@gmail.com>
|
17 |
+
* Please leave this credit and the directory structure intact for future developers who might read the code.
|
18 |
+
* @Github https://github.com/arunbasillal/WordPress-Starter-Plugin
|
19 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
|
22 |
+
/**
|
23 |
+
* ~ Directory Structure ~
|
24 |
+
*
|
25 |
+
* /admin/ - Plugin backend stuff.
|
26 |
+
* /includes/ - External third party classes and libraries.
|
27 |
+
* /languages/ - Translation files go here.
|
28 |
+
* /public/ - Front end files go here.
|
29 |
+
* index.php - Dummy file.
|
30 |
+
* license.txt - GPL v2
|
31 |
+
* iaff_starter-plugin.php - File containing plugin name and other version info for WordPress.
|
32 |
+
* readme.txt - Readme for WordPress plugin repository. https://wordpress.org/plugins/files/2017/03/readme.txt
|
33 |
+
* uninstall.php - Fired when the plugin is uninstalled.
|
34 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
|
37 |
+
/**
|
38 |
+
* :TODO:
|
39 |
+
*
|
40 |
+
* - Update IAFF_VERSION_NUM in iaff_starter-plugin.php (keep this line for future updates)
|
41 |
+
*/
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
// Exit if accessed directly
|
45 |
+
if ( !defined('ABSPATH') ) exit;
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
/**
|
49 |
+
* Plugin name and directory constants
|
50 |
+
*
|
51 |
+
* @since 1.3
|
52 |
+
* @constant IAFF_STARTER_PLUGIN The name of the plugin - 'starter-plugin'
|
53 |
+
* @constant IAFF_STARTER_PLUGIN_DIR The absolute path to the plugin directory without the trailing slash - C:\xampp\htdocs\wp/wp-content/plugins/starter-plugin
|
54 |
+
*/
|
55 |
+
if (!defined('IAFF_STARTER_PLUGIN'))
|
56 |
+
define('IAFF_STARTER_PLUGIN', trim(dirname(plugin_basename(__FILE__)), '/'));
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
if (!defined('IAFF_STARTER_PLUGIN_DIR'))
|
59 |
+
define('IAFF_STARTER_PLUGIN_DIR', WP_PLUGIN_DIR . '/' . IAFF_STARTER_PLUGIN);
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
/**
|
63 |
+
* Add plugin version to database
|
64 |
+
*
|
65 |
+
* @since 1.3
|
66 |
+
* @constant IAFF_VERSION_NUM the version number of the current version
|
67 |
+
* @refer https://www.smashingmagazine.com/2011/03/ten-things-every-wordpress-plugin-developer-should-know/
|
68 |
+
*/
|
69 |
+
if (!defined('IAFF_VERSION_NUM'))
|
70 |
+
define('IAFF_VERSION_NUM', '1.3');
|
71 |
+
update_option('abl_iaff_version', IAFF_VERSION_NUM); // Change to add_option when we need to check installed version at some later point.
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
+
// Load everything
|
75 |
+
require_once( IAFF_STARTER_PLUGIN_DIR . '/admin/iaff_image-attributes-from-filename-loader.php');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
// Register activation hook (this has to be in the main plugin file.)
|
78 |
+
register_activation_hook( __FILE__ , 'iaff_activate_plugin' );
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
?>
|
includes/index.php
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden
|
3 |
+
?>
|
index.php
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden
|
3 |
+
?>
|
languages/image-attributes-from-filename.pot
ADDED
File without changes
|
public/index.php
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden
|
3 |
+
?>
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: arunbasillal
|
3 |
Donate link: http://millionclues.com/donate/
|
4 |
Tags: image title, image caption, image description, alt text, bulk edit images, bulk rename images, auto image attributes, auto image alt text, remove underscores
|
5 |
-
Requires at least: 3.0
|
6 |
-
Tested up to: 4.8
|
7 |
Stable tag: trunk
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -21,9 +21,13 @@ With this plugin you can:
|
|
21 |
* Set the image filename as the image Title.
|
22 |
* Set the image filename as the image Caption.
|
23 |
* Set the image filename as the image Description.
|
24 |
-
* Set the image filename as the image Alt Text.
|
|
|
25 |
* Remove hyphens from the image filename.
|
26 |
* Remove underscores from the image filename.
|
|
|
|
|
|
|
27 |
* Choose to turn off any of the above mentioned features.
|
28 |
|
29 |
With the bulk updater you can:
|
@@ -55,12 +59,30 @@ Yes, the plugin will update image Title, Caption, Description And Alt Text from
|
|
55 |
|
56 |
Yes! Please [get in touch via my contact form](http://millionclues.com/contact/) with a brief description of your requirement and budget for the project. I will be in touch shortly.
|
57 |
|
|
|
|
|
|
|
|
|
58 |
== Screenshots ==
|
59 |
|
60 |
-
1. The settings page in WordPress Admin > Settings > Image Attributes
|
|
|
61 |
|
62 |
== Changelog ==
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
= 1.2 =
|
65 |
* Added: Character filter options. Plugin now removes hyphens and underscores.
|
66 |
* Bug Fix: Minor bug fix.
|
@@ -73,6 +95,19 @@ Yes! Please [get in touch via my contact form](http://millionclues.com/contact/)
|
|
73 |
|
74 |
== Upgrade Notice ==
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
= 1.2 =
|
77 |
* Added: Character filter options. Plugin now removes hyphens and underscores.
|
78 |
* Bug Fix: Minor bug fix.
|
2 |
Contributors: arunbasillal
|
3 |
Donate link: http://millionclues.com/donate/
|
4 |
Tags: image title, image caption, image description, alt text, bulk edit images, bulk rename images, auto image attributes, auto image alt text, remove underscores
|
5 |
+
Requires at least: 3.5.0
|
6 |
+
Tested up to: 4.8.1
|
7 |
Stable tag: trunk
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
21 |
* Set the image filename as the image Title.
|
22 |
* Set the image filename as the image Caption.
|
23 |
* Set the image filename as the image Description.
|
24 |
+
* Set the image filename as the image Alt Text. This was a default feature in WordPress before 4.7. This option restores this essential feature which is great for SEO.
|
25 |
+
* Insert Image Title into post HTML. WordPress stopped adding Image Titles to images since WordPress 3.5. This option restores it.
|
26 |
* Remove hyphens from the image filename.
|
27 |
* Remove underscores from the image filename.
|
28 |
+
* Remove full stops from filename.
|
29 |
+
* Remove commas from filename.
|
30 |
+
* Remove all numbers from filename.
|
31 |
* Choose to turn off any of the above mentioned features.
|
32 |
|
33 |
With the bulk updater you can:
|
59 |
|
60 |
Yes! Please [get in touch via my contact form](http://millionclues.com/contact/) with a brief description of your requirement and budget for the project. I will be in touch shortly.
|
61 |
|
62 |
+
= This plugin saved me a lot of time, how can I show my appreciation? =
|
63 |
+
|
64 |
+
I am glad to hear that! You can either [make a donation](http://millionclues.com/donate/) or leave a [rating](https://wordpress.org/support/plugin/auto-image-attributes-from-filename-with-bulk-updater/reviews/?rate=5#new-post) to motivate me to keep working on the plugin.
|
65 |
+
|
66 |
== Screenshots ==
|
67 |
|
68 |
+
1. The settings page in WordPress Admin > Settings > Image Attributes with default settings.
|
69 |
+
2. Bulk Updater
|
70 |
|
71 |
== Changelog ==
|
72 |
|
73 |
+
= 1.3 =
|
74 |
+
* Improved the architecture of the plugin laying foundation for future updates. Utilizing my [starter plugin framework](http://millionclues.com/lab/wordpress-starter-plugin-a-framework-for-quick-plugin-development/)
|
75 |
+
* Bug fix: For images that had EXIF data, EXIF data was used instead of filename. Props to @mathieupellegrin for reporting this.
|
76 |
+
* NEW: Added option to Insert Image Title into HTML. WordPress stopped including image titles since 3.5. Code from [Restore Image Title](https://wordpress.org/plugins/restore-image-title/) plugin was used.
|
77 |
+
* NEW: Remove full stops ( . ) from filename.
|
78 |
+
* NEW: Remove commas ( , ) from filename.
|
79 |
+
* NEW: Remove all numbers ( 0-9 ) from filename.
|
80 |
+
* NEW: Added a warning and user confirmation before while clicking "Run Bulk Updater" button to prevent accidental clicks.
|
81 |
+
* UI Improvement: Cleaned up the interface and moved the Bulk Updater to its own tab.
|
82 |
+
* UI Improvement: Bulk updater log is now displayed in a neat box instead of just printing the results on the page.
|
83 |
+
* Parts of the code was updated for more efficiency and faster processing.
|
84 |
+
* Tested on WordPress 4.8.1. Result = pass.
|
85 |
+
|
86 |
= 1.2 =
|
87 |
* Added: Character filter options. Plugin now removes hyphens and underscores.
|
88 |
* Bug Fix: Minor bug fix.
|
95 |
|
96 |
== Upgrade Notice ==
|
97 |
|
98 |
+
= 1.3 =
|
99 |
+
* Improved the architecture of the plugin laying foundation for future updates. Utilizing my [starter plugin framework](http://millionclues.com/lab/wordpress-starter-plugin-a-framework-for-quick-plugin-development/)
|
100 |
+
* Bug fix: For images that had EXIF data, EXIF data was used instead of filename. Props to @mathieupellegrin for reporting this.
|
101 |
+
* NEW: Added option to Insert Image Title into HTML. WordPress stopped including image titles since 3.5. Code from [Restore Image Title](https://wordpress.org/plugins/restore-image-title/) plugin was used.
|
102 |
+
* NEW: Remove full stops ( . ) from filename.
|
103 |
+
* NEW: Remove commas ( , ) from filename.
|
104 |
+
* NEW: Remove all numbers ( 0-9 ) from filename.
|
105 |
+
* NEW: Added a warning and user confirmaton before while clicking "Run Bulk Updater" button to prevent accidental clicks.
|
106 |
+
* UI Improvement: Cleaned up the interface and moved the Bulk Updater to its own tab.
|
107 |
+
* UI Improvement: Bulk updater log is now displayed in a neat box instead of just printing the results on the page.
|
108 |
+
* Parts of the code was updated for more efficiency and faster processing.
|
109 |
+
* Tested on WordPress 4.8.1. Result = pass.
|
110 |
+
|
111 |
= 1.2 =
|
112 |
* Added: Character filter options. Plugin now removes hyphens and underscores.
|
113 |
* Bug Fix: Minor bug fix.
|
uninstall.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Fired when the plugin is uninstalled.
|
4 |
+
*
|
5 |
+
* Everything in uninstall.php will be executed when user decides to delete the plugin.
|
6 |
+
* @since 1.3
|
7 |
+
*/
|
8 |
+
|
9 |
+
|
10 |
+
// Exit if accessed directly
|
11 |
+
if ( !defined('ABSPATH') ) exit;
|
12 |
+
|
13 |
+
// If uninstall not called from WordPress, then die.
|
14 |
+
if ( !defined('WP_UNINSTALL_PLUGIN') ) die;
|
15 |
+
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Delete database entries
|
19 |
+
*
|
20 |
+
* @since 1.0
|
21 |
+
*/
|
22 |
+
delete_option( 'iaff_settings' );
|
23 |
+
delete_option( 'iaff_bulk_updater_counter' );
|
24 |
+
delete_option( 'abl_iaff_version' );
|
25 |
+
|
26 |
+
?>
|