Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arunbasillal/5ba2d5a3bd56259eed242e2938f0ed06 to your computer and use it in GitHub Desktop.
Save arunbasillal/5ba2d5a3bd56259eed242e2938f0ed06 to your computer and use it in GitHub Desktop.
Add Image Attributes Pro features to Classified Listing.
/**
* Add Image Attributes Pro features to Classified Listing.
*
* Note: Classified Listing plugin hides gallery images from the WordPress Media Library. However these images are simply hidden
* and the Bulk Updater of Image Attributes Pro will be able to discover them.
* If you wish to display them in the Media Library, please add this snippet to
* your functions.php as well - https://wordpress.org/support/topic/about-adding-gallery-images-to-media-library/#post-16643698
*
* @link https://imageattributespro.com
* @link https://wordpress.org/plugins/classified-listing/
*/
if ( defined( 'IAFFPRO_VERSION_NUM' ) ) {
/**
* Add Image Attributes Pro bulk actions to classifieds listings.
* @link https://imageattributespro.com/add-bulk-action-to-any-post-type/
*/
add_filter( 'bulk_actions-edit-rtcl_listing', 'iaffpro_add_bulk_action_update_image_attributes_to_posts' );
add_filter( 'handle_bulk_actions-edit-rtcl_listing', 'iaffpro_handle_posts_bulk_action_update_image_attributes', 10, 3 );
// Add Image Attributes Pro meta box into Classifieds listing editor.
add_action( 'add_meta_boxes_rtcl_listing', 'iaffpro_add_meta_box_posts_pages' );
// Update attributes of images in Classifieds Gallery while updating attributes of listing.
add_action( 'iaffpro_after_update_attributes_in_post', 'iaffpro_cl_update_classifieds_gallery_image_attributes' );
/**
* Update attributes of images in Classifieds Gallery while updating attributes of listing.
*
* @param $post_id (integer) ID of the post that is being updated in iaffpro_update_attributes_in_post_by_post_id()
*/
function iaffpro_cl_update_classifieds_gallery_image_attributes( $post_id ) {
$gallery_images = get_post_meta( $post_id, '_rtcl_attachments_order', true );
foreach( $gallery_images as $image ) {
// Generate image attributes
$attributes = iaffpro_generate_image_attributes( $image, $post_id, true );
// Update image attributes in media library
iaffpro_update_image( $image, $attributes, true );
}
}
}
@arunbasillal
Copy link
Author

To unhide images added to listing gallery from the Media Library, add this to functions.php

remove_action( 'ajax_query_attachments_args', [ \Rtcl\Controllers\Hooks\ActionHooks::class, 'remove_ajax_query_attachments_args' ] );
remove_action( 'load-upload.php', [ \Rtcl\Controllers\Hooks\ActionHooks::class, 'remove_attachments_load_media' ] );

Source: https://wordpress.org/support/topic/about-adding-gallery-images-to-media-library/#post-16643698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment