WCMp Advanced Frontend Manager
-
AuthorPosts
-
-
June 21, 2022 at 8:22 PM #138148Tim KerremansParticipant
Hi there, so I’m storing my media files in a S3 bucket and have a function that stores certain media files under a different subfolder in my bucket as you can see below:
add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );
function object_meta( $args, $post_id, $image_size, $copy ) {
$extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );// Example places (potentially large) movie files in a different bucket than configured.
// Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
// Change bucket.
$args[‘Bucket’] = ‘media.holymowly.com’;// Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
$filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
$args[‘Key’] = ‘other/’ . $filename;
}// Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
/*
if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
// Note, S3 format trims “-” from header names.
$args[‘ContentDisposition’] = ‘attachment’;
}*/return $args;
}Apart from checking if the media is from a certain type I also need to check for the current page as I only want the product images that are uploaded by the vendors to be placed in a different subfolder. Unfortunately I haven’t been able to do so, this is what I currently have:
add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );
function object_meta( $args, $post_id, $image_size, $copy ) {
if ( is_page_template( ‘dc-woocommerce-multi-vendor/templates/vendor-dashboard/product-manager/edit-product.php’ ) ) {$extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );
// Example places (potentially large) movie files in a different bucket than configured.
// Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
// Change bucket.
$args[‘Bucket’] = ‘media.holymowly.com’;// Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
$filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
$args[‘Key’] = ‘other/’ . $filename;
}// Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
/*
if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
// Note, S3 format trims “-” from header names.
$args[‘ContentDisposition’] = ‘attachment’;
}*/return $args;
}
}Can you provide me with the correct code to also check if current page is: http://www.mydomain.com/dashboard/edit-product/**PRODUCT-ID**
-
June 23, 2022 at 6:24 PM #138207MVX Support NinjaKeymaster
Hi,
You can use below code to check current page edit product page.global $WCMp; $current_endpoint_key = $WCMp->endpoints->get_current_endpoint(); // retrive the actual endpoint name in case admn changes that from settings $current_endpoint = get_wcmp_vendor_settings( 'wcmp_' . str_replace( '-', '_', $current_endpoint_key ) . '_endpoint', 'vendor', 'general', $current_endpoint_key ); // retrive edit-product endpoint name in case admn changes that from settings $edit_product_endpoint = get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' ); //Return if not edit product endpoint if ( $current_endpoint == $edit_product_endpoint ) { // your custom code }
Copyregards,
-
June 23, 2022 at 6:47 PM #138210Tim KerremansParticipant
Hi,
Thanks for this, how would this merge with the code I provided? Just tried combining them but now function seems to be ignored, all content is now uploading to the same bucket
-
June 24, 2022 at 6:20 PM #138232MVX Support NinjaKeymaster
HI,
Kindly share your code.Regards,
-
June 24, 2022 at 6:32 PM #138233Tim KerremansParticipant
add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );
function object_meta( $args, $post_id, $image_size, $copy ) {
$extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );// Example places (potentially large) movie files in a different bucket than configured.
// Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
// Change bucket.
$args[‘Bucket’] = ‘media.holymowly.com’;// Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
$filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
$args[‘Key’] = ‘files/’ . $filename;
}// Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
/*
if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
// Note, S3 format trims “-” from header names.
$args[‘ContentDisposition’] = ‘attachment’;
}*/ -
June 25, 2022 at 6:37 PM #138263MVX Support NinjaKeymaster
HI,
kindly add below code and check.add_filter( 'as3cf_object_meta', array( $this, 'object_meta' ), 10, 4 ); function object_meta( $args, $post_id, $image_size, $copy ) { global $WCMp; $current_endpoint_key = $WCMp->endpoints->get_current_endpoint(); // retrive the actual endpoint name in case admn changes that from settings $current_endpoint = get_wcmp_vendor_settings( 'wcmp_' . str_replace( '-', '_', $current_endpoint_key ) . '_endpoint', 'vendor', 'general', $current_endpoint_key ); // retrive edit-product endpoint name in case admn changes that from settings $edit_product_endpoint = get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' ); //Return if not edit product endpoint if ( $current_endpoint == $edit_product_endpoint ) { $extension = pathinfo( $args['Key'], PATHINFO_EXTENSION ); // Example places (potentially large) movie files in a different bucket than configured. // Also changes path prefix to match that used in CDN behavior's "Path Prefix" for this second origin. if ( in_array( $extension, array( 'pdf', 'csv' ) ) ) { // Change bucket. $args['Bucket'] = 'media.holymowly.com'; // Change key (don't do this for images, thumbnails will not get new prefix and will not be usable). $filename = pathinfo( $args['Key'], PATHINFO_FILENAME ) . '.' . $extension; $args['Key'] = 'files/' . $filename; } // Example sets "Content-Disposition" header to "attachment" so that browsers download rather than play audio files. /* if ( in_array( $extension, array( 'mp3', 'wav' ) ) ) { // Note, S3 format trims "-" from header names. $args['ContentDisposition'] = 'attachment'; }*/ } }
Copy -
June 26, 2022 at 4:33 PM #138268Tim KerremansParticipant
Hi,
I forgot to return $args in the function I shared so I have added it to below code but it still is not working.. The files are not placed in a seperate subfolder, all files go to the same location while CSV and PDF files should go to different folder.
add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );
function object_meta( $args, $post_id, $image_size, $copy ) {
global $WCMp;
$current_endpoint_key = $WCMp->endpoints->get_current_endpoint();
// retrive the actual endpoint name in case admn changes that from settings
$current_endpoint = get_wcmp_vendor_settings( ‘wcmp_’ . str_replace( ‘-‘, ‘_’, $current_endpoint_key ) . ‘_endpoint’, ‘vendor’, ‘general’, $current_endpoint_key );
// retrive edit-product endpoint name in case admn changes that from settings
$edit_product_endpoint = get_wcmp_vendor_settings( ‘wcmp_edit_product_endpoint’, ‘vendor’, ‘general’, ‘edit-product’ );
//Return if not edit product endpoint
if ( $current_endpoint == $edit_product_endpoint ) {$extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );
// Example places (potentially large) movie files in a different bucket than configured.
// Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
// Change bucket.
$args[‘Bucket’] = ‘media.holymowly.com’;// Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
$filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
$args[‘Key’] = ‘files/’ . $filename;
}// Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
/*
if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
// Note, S3 format trims “-” from header names.
$args[‘ContentDisposition’] = ‘attachment’;
}*/return $args;
}
} -
June 27, 2022 at 6:24 PM #138285MVX Support NinjaKeymaster
Hi,
seems like you added your custom code by using other plugins hook, so, it’s batter to ask the plugin author. They will help you.Let me know if you need any WCMp related question.
Regards,
-
June 27, 2022 at 6:30 PM #138286Tim KerremansParticipant
They are not helping me.
They are telling me I need to reach out to you as this is a page that is created by your plugin and therefore I need the correct filter to check for this page -
June 28, 2022 at 6:43 PM #138312NerdySupportExpert MoumitaKeymaster
Kindly ask the plugin author to give a working code snippet that lets the admin place the files in a separate folder.
We will try to modify that code for the vendor dashboard.
-
June 28, 2022 at 7:01 PM #138313Tim KerremansParticipant
I already gave you a working code snippet in my first message.
add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );
function object_meta( $args, $post_id, $image_size, $copy ) {
$extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );// Example places (potentially large) movie files in a different bucket than configured.
// Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
// Change bucket.
$args[‘Bucket’] = ‘media.holymowly.com’;// Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
$filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
$args[‘Key’] = ‘other/’ . $filename;
}// Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
/*
if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
// Note, S3 format trims “-” from header names.
$args[‘ContentDisposition’] = ‘attachment’;
}*/return $args;
} -
June 29, 2022 at 5:55 PM #138330MVX Support NinjaKeymaster
Hi,
WCMp check current page is edit product page using above code, I shared in https://multivendorx.com/support-forum/topic/only-apply-function-on-certain-page/#post-138207regards,
-
June 29, 2022 at 5:58 PM #138332Tim KerremansParticipant
Are you even reading my questions? It is not working, like I already said
-
July 4, 2022 at 3:34 PM #140030NerdySupportExpert MoumitaKeymaster
@Tim Kerremans, as this is third party compatibility, hence we can assist you as far as our hook filter and coding procedure.
Why your code is not working requires further debugging and checking third-party code. I would recommend you to contact your developer or you may hire our service team. They can develop this compatibility for your site. You can contact them via this link : https://multivendorx.com/custom-development/
-
October 22, 2022 at 2:52 PM #144912MVX Support NinjaKeymaster
Hi @Tim, we haven’t heard back from you for a while.
So we presume this issue has been fixed. We are closing this for now.
-
-
AuthorPosts
The topic ‘Only apply function on certain page’ is closed to new replies.