Skip to content

Commit

Permalink
Merge pull request #16 from arunbasillal/branch-4.4
Browse files Browse the repository at this point in the history
Branch 4.4
  • Loading branch information
arunbasillal authored Nov 9, 2023
2 parents 35fbec3 + 59466f0 commit 5356e50
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 48 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ With this plugin you can:
* Remove commas from filename.
* Remove all numbers from filename.
* Choose to turn off any of the above mentioned features.
* Display image attributes as columns in Media Library list view.

With the bulk updater you can:

Expand Down Expand Up @@ -85,6 +86,7 @@ With the Image Attributes Pro bulk updater you can:

Other Image Attributes Pro features:

* Bulk edit image attributes from the Media Library quickly and easily. [Read more.](https://imageattributespro.com/media-library-bulk-editing/?utm_source=github&utm_medium=readme.md)
* 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)
* 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)
* Copy image attributes to post HTML while updating in Media Library. Any changes made to image attributes in the media library will be automatically synced to the corresponding post HTML. [Read more.](https://imageattributespro.com/auto-copy-image-attributes-to-post-html-from-media-library/?utm_source=github&utm_medium=readme.md)
Expand Down
39 changes: 38 additions & 1 deletion admin/admin-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,41 @@ function iaff_custom_attribute_tags() {
* @param $available_tags (array) Array containing all custom attribute tags.
*/
return apply_filters( 'iaff_custom_attribute_tags', $available_tags );
}
}

/**
* Activate Image Attributes Pro plugin from the sidebar.
*
* In the basic version, there is a sidebar to up sell Image Attributes Pro. When the pro plugin is installed,
* and not activated, the button to buy is replaced with activate Image Attributes Pro. Activation is handled here.
*
* Using WordPress native activation (using plugins.php?action=activate... link) redirects to the Plugins list after activation.
* There isn't an evident way to control the redirection after plugin activation without using activate_plugin().
*
* @since 4.4
*/
function iaff_activate_image_attributes_pro_plugin() {

// Add a fallback if wp_get_referer() returns false.
$redirect_url = wp_get_referer() === false ? admin_url( 'options-general.php?page=image-attributes-from-filename' ) : wp_get_referer();

// Authentication
if (
! current_user_can( 'manage_options' ) ||
! ( isset( $_GET['iaff_activate_image_attributes_pro_plugin_nonce_name'] ) && wp_verify_nonce( $_GET['iaff_activate_image_attributes_pro_plugin_nonce_name'], 'activate_image_attributes_pro_plugin' ) ) ||
is_plugin_active( 'auto-image-attributes-pro/auto-image-attributes-pro.php' )
) {

// Return to referer if authentication fails or if plugin is already active.
wp_redirect( $redirect_url );
exit;
}

$activation_status = activate_plugin( 'auto-image-attributes-pro/auto-image-attributes-pro.php', $redirect_url );

if ( $activation_status === null ) {
// Show admin notice to inform that the operation was successful.
set_transient( 'iaff_activate_image_attributes_pro_plugin_complete', true, 100 );
}
}
add_action( 'admin_post_iaff_activate_image_attributes_pro_plugin', 'iaff_activate_image_attributes_pro_plugin' );
28 changes: 20 additions & 8 deletions admin/admin-ui-render.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ function iaff_custom_filter_callback() {
<fieldset>

<p><?php printf( __( 'Enter words or characters to filter separated by commas. Filter is case sensitive. <a href="%s" target="_blank">Read more.</a>', 'auto-image-attributes-from-filename-with-bulk-updater' ), 'https://imageattributespro.com/custom-filter-and-regex-filter/?utm_source=iaff-basic&utm_medium=advanced-tab' ); ?></p>
<input type="text" name="iaff_settings[custom_filter]" placeholder="DCIM, img" class="regular-text code" value="<?php if ( isset( $settings['custom_filter'] ) && ( ! empty( $settings['custom_filter'] ) ) ) echo esc_attr( $settings['custom_filter'] ); ?>"/><br><br>
<input type="text" name="iaff_settings[custom_filter]" placeholder="e.g. DCIM, img" class="regular-text code" value="<?php if ( isset( $settings['custom_filter'] ) && ( ! empty( $settings['custom_filter'] ) ) ) echo esc_attr( $settings['custom_filter'] ); ?>"/><br><br>

<p><?php _e('Filter with regular expression', 'auto-image-attributes-from-filename-with-bulk-updater') ?></p>
<input type="text" name="iaff_settings[regex_filter]" placeholder="/regex/" class="regular-text code" value="<?php if ( isset( $settings['regex_filter'] ) && ( ! empty( $settings['regex_filter'] ) ) ) echo esc_attr( $settings['regex_filter'] ); ?>"/><br>
Expand Down Expand Up @@ -334,7 +334,7 @@ function iaff_advanced_image_title_callback() {
<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'] ); ?>/>
<span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>

<input type="text" id="text_custom_attribute_title" class="text_custom_attribute regular-text code" data-attribute="title" name="iaff_settings[custom_attribute_title]" placeholder="%filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_title'] ) && ( ! empty( $settings['custom_attribute_title'] ) ) ) echo esc_attr( $settings['custom_attribute_title'] ); ?>" />
<input type="text" id="text_custom_attribute_title" class="text_custom_attribute regular-text code" data-attribute="title" name="iaff_settings[custom_attribute_title]" placeholder="e.g. %filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_title'] ) && ( ! empty( $settings['custom_attribute_title'] ) ) ) echo esc_attr( $settings['custom_attribute_title'] ); ?>" />

<span class="copy-attribute-link" data-attribute="title" data-copied-text="<?php _e( 'Copied!', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?>"><a href="#"><?php _e( 'Copy to all attributes.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></a></span>
</label><br>
Expand Down Expand Up @@ -373,7 +373,7 @@ function iaff_advanced_image_alt_text_callback() {
<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'] ); ?>/>
<span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>

<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]" placeholder="%filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_alt_text'] ) && ( ! empty( $settings['custom_attribute_alt_text'] ) ) ) echo esc_attr( $settings['custom_attribute_alt_text'] ); ?>" />
<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]" placeholder="e.g. %filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_alt_text'] ) && ( ! empty( $settings['custom_attribute_alt_text'] ) ) ) echo esc_attr( $settings['custom_attribute_alt_text'] ); ?>" />

<span class="copy-attribute-link" data-attribute="alt_text" data-copied-text="<?php _e( 'Copied!', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?>"><a href="#"><?php _e( 'Copy to all attributes.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></a></span>
</label><br>
Expand Down Expand Up @@ -412,7 +412,7 @@ function iaff_advanced_image_caption_callback() {
<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'] ); ?>/>
<span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>

<input type="text" id="text_custom_attribute_caption" class="text_custom_attribute regular-text code" data-attribute="caption" name="iaff_settings[custom_attribute_caption]" placeholder="%filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_caption'] ) && ( ! empty( $settings['custom_attribute_caption'] ) ) ) echo esc_attr( $settings['custom_attribute_caption'] ); ?>" />
<input type="text" id="text_custom_attribute_caption" class="text_custom_attribute regular-text code" data-attribute="caption" name="iaff_settings[custom_attribute_caption]" placeholder="e.g. %filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_caption'] ) && ( ! empty( $settings['custom_attribute_caption'] ) ) ) echo esc_attr( $settings['custom_attribute_caption'] ); ?>" />

<span class="copy-attribute-link" data-attribute="caption" data-copied-text="<?php _e( 'Copied!', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?>"><a href="#"><?php _e( 'Copy to all attributes.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></a></span>
</label><br>
Expand Down Expand Up @@ -451,7 +451,7 @@ function iaff_advanced_image_description_callback() {
<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'] ); ?>/>
<span><?php esc_attr_e( 'Use custom attribute', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></span>

<input type="text" id="text_custom_attribute_description" class="text_custom_attribute regular-text code" data-attribute="description" name="iaff_settings[custom_attribute_description]" placeholder="%filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_description'] ) && ( ! empty( $settings['custom_attribute_description'] ) ) ) echo esc_attr( $settings['custom_attribute_description'] ); ?>" />
<input type="text" id="text_custom_attribute_description" class="text_custom_attribute regular-text code" data-attribute="description" name="iaff_settings[custom_attribute_description]" placeholder="e.g. %filename% - %posttitle%" value="<?php if ( isset( $settings['custom_attribute_description'] ) && ( ! empty( $settings['custom_attribute_description'] ) ) ) echo esc_attr( $settings['custom_attribute_description'] ); ?>" />

<span class="copy-attribute-link" data-attribute="description" data-copied-text="<?php _e( 'Copied!', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?>"><a href="#"><?php _e( 'Copy to all attributes.', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></a></span>
</label><br>
Expand Down Expand Up @@ -1002,11 +1002,23 @@ function iaff_admin_interface_render () {
</div><!-- .iaff-admin-options-main -->

<!-- Upgrade to pro sidebar -->
<?php if ( ! iaff_is_pro() ) { ?>
<?php if ( ! iaff_is_pro() ) {

// Modify sidebar if Image Attributes Pro is installed, but not activated.
if ( file_exists( WP_PLUGIN_DIR . '/auto-image-attributes-pro/auto-image-attributes-pro.php' ) ) {
$button_text = __( 'Activate Image Attributes Pro', 'auto-image-attributes-from-filename-with-bulk-updater' );
$button_link = wp_nonce_url( admin_url( 'admin-post.php?action=iaff_activate_image_attributes_pro_plugin' ), 'activate_image_attributes_pro_plugin', 'iaff_activate_image_attributes_pro_plugin_nonce_name' );
$button_target = '';
} else {
$button_text = __( 'Upgrade to Pro', 'auto-image-attributes-from-filename-with-bulk-updater' );
$button_link = 'https://imageattributespro.com/?utm_source=iaff-basic&utm_medium=coupon-sidebar';
$button_target = '_blank';
}
?>
<div class="iaff-admin-options-sidebar">

<div class="iaff-upgrade-header">
<a href="https://imageattributespro.com/?utm_source=iaff-basic&utm_medium=coupon-sidebar" target="_blank">
<a href="<?php echo $button_link; ?>" target="<?php echo $button_target; ?>">
<div class="iaff-icon"></div>
<h1 class="patua"><?php _e( 'Unlock Traffic', 'auto-image-attributes-from-filename-with-bulk-updater' ); ?></h1>
<ul>
Expand All @@ -1016,7 +1028,7 @@ function iaff_admin_interface_render () {
<li><span class="dashicons dashicons-yes"></span><?php _e('Update attributes within posts', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></li>
<li><span class="dashicons dashicons-yes"></span><?php _e('Build custom attributes and fine tune settings', 'auto-image-attributes-from-filename-with-bulk-updater'); ?></li>
</ul>
<button class="button" style="width:100%">Upgrade to Pro &rarr; </button>
<button class="button" style="width:100%"><?php echo $button_text; ?> &rarr; </button>
</a>
</div><!-- .iaff-upgrade-header -->

Expand Down
11 changes: 10 additions & 1 deletion admin/basic-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function iaff_plugin_row_meta( $links, $file ) {

if ( strpos( $file, 'iaff_image-attributes-from-filename.php' ) !== false ) {
$new_links = array(
'upgrade' => '<a href="https://imageattributespro.com/?utm_source=iaff-basic&utm_medium=plugins-list" target="_blank">Upgrade To Image Attributes Pro</a>',
'upgrade' => '<a href="https://imageattributespro.com/?utm_source=iaff-basic&utm_medium=plugins-list" target="_blank">' . __( 'Upgrade To Image Attributes Pro', 'auto-image-attributes-from-filename-with-bulk-updater' ) . '</a>',
);
$links = array_merge( $links, $new_links );
}
Expand Down Expand Up @@ -104,6 +104,15 @@ function iaff_admin_notices() {
// Delete transient
delete_transient( 'iaff_upgrade_complete_admin_notice' );
}

// Image Attributes Pro activation notice (when activated from basic plugin sidebar)
if ( get_transient( 'iaff_activate_image_attributes_pro_plugin_complete' ) ) {

echo '<div class="notice notice-success is-dismissible"><p>' . __( 'Image Attributes Pro activated', 'auto-image-attributes-from-filename-with-bulk-updater' ) . '</p></div>';

// Delete transient.
delete_transient( 'iaff_activate_image_attributes_pro_plugin_complete' );
}
}
add_action( 'admin_notices', 'iaff_admin_notices' );

Expand Down
66 changes: 66 additions & 0 deletions admin/columns-media-library.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* Display image attributes as columns in the Media Library.
*
* @since 4.4
*/

// Exit if accessed directly
if ( ! defined('ABSPATH') ) exit;

add_filter( 'manage_media_columns', 'iaff_manage_media_columns_add_columns' );
add_action( 'manage_media_custom_column', 'iaff_manage_media_custom_column_add_data', 10, 2 );

/**
* Add columns in Media Library for each of the image attributes.
*
* @since 4.4
*
* @param $columns (array) An array of columns displayed in the Media list table.
*/
function iaff_manage_media_columns_add_columns( $columns ) {

$columns['iaff_image_title'] = esc_html__( 'Title', 'auto-image-attributes-from-filename-with-bulk-updater' );
$columns['iaff_image_alt'] = esc_html__( 'Alternative Text', 'auto-image-attributes-from-filename-with-bulk-updater' );
$columns['iaff_image_caption'] = esc_html__( 'Caption', 'auto-image-attributes-from-filename-with-bulk-updater' );
$columns['iaff_image_description'] = esc_html__( 'Description', 'auto-image-attributes-from-filename-with-bulk-updater' ) . '&nbsp;<a target="_blank" title="Read More." href="https://imageattributespro.com/media-library-bulk-editing/?utm_source=iaff-basic&utm_medium=media-library-info-button"><span class="dashicons dashicons-info"></span></a>';

return $columns;
}

/**
* Add image attributes data to the columns in the Media Library for each of the images.
*
* @since 4.4
*
* @param $column_name (string) Name of the custom column.
* @param $id (int) Attachment ID.
*/
function iaff_manage_media_custom_column_add_data( $column_name, $id ) {

// Retrieve image object from its ID
$image = get_post( $id );

if ( $image === NULL ) {
return '';
}

switch( $column_name ) {
case 'iaff_image_title':
echo $image->post_title;
break;

case 'iaff_image_alt':
$iaff_image_alt = get_post_meta( $id, '_wp_attachment_image_alt', true );
echo ( $iaff_image_alt !== false ) ? $iaff_image_alt : '';
break;

case 'iaff_image_caption':
echo $image->post_excerpt;
break;

case 'iaff_image_description':
echo $image->post_content;
break;
}
}
4 changes: 4 additions & 0 deletions admin/css/iaff-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,8 @@
}
#iaff-pro .copy-attribute-link a:focus {
box-shadow: none;
}

#iaff-pro ::placeholder {
opacity: 0.7;
}
20 changes: 11 additions & 9 deletions admin/do.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,11 @@ function iaff_lcb_restore_title_to_gallery( $content, $id ) {
/**
* Replace commas in filename with hyphens
*
* WordPress removes commas during file upload. This function replaces commas with hyphens 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.
* @since 1.3
* @refer https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter
* WordPress removes commas during file upload. This function replaces commas with hyphens 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.
*
* @since 1.3
* @refer https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter
*/
function iaff_clean_filename( $file ) {

Expand All @@ -614,25 +616,25 @@ function iaff_clean_filename( $file ) {
);

// Return if file is not an image file
if ( ! in_array($file['type'],$image_extensions) )
if ( ! in_array( $file['type'], $image_extensions ) ) {
return $file;
}

// Clean filename with IAFF Pro
if( iaff_is_pro() ) {

return iaffpro_clean_filename($file);
if ( iaff_is_pro() ) {
return iaffpro_clean_filename( $file );
}

// Get Settings
$settings = iaff_get_settings();

if ( isset( $settings['commas'] ) && boolval($settings['commas']) ) {
if ( isset( $settings['commas'] ) && boolval( $settings['commas'] ) ) {
$file['name'] = str_replace( ',', '-', $file['name'] );
}

return $file;
}
add_filter('wp_handle_upload_prefilter', 'iaff_clean_filename' );
add_filter( 'wp_handle_upload_prefilter', 'iaff_clean_filename' );

/**
* Extract, format and return image name from filename.
Expand Down
4 changes: 2 additions & 2 deletions iaff_image-attributes-from-filename.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 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.
* Author: Arun Basil Lal
* Author URI: https://imageattributespro.com/?utm_source=plugin-header&utm_medium=author-uri
* Version: 4.3.1
* Version: 4.4
* Text Domain: auto-image-attributes-from-filename-with-bulk-updater
* Domain Path: /languages
* License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Expand Down Expand Up @@ -65,7 +65,7 @@
* @since 1.3
*/
if ( ! defined( 'IAFF_VERSION_NUM' ) ) {
define( 'IAFF_VERSION_NUM', '4.3.1' );
define( 'IAFF_VERSION_NUM', '4.4' );
}

/**
Expand Down
Loading

0 comments on commit 5356e50

Please sign in to comment.