Forum Replies Created
-
AuthorPosts
-
Tim 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 pageJune 27, 2022 at 12:53 PM in reply to: Set min and max image resolution only on edit-product page #138280Tim KerremansParticipantHi,
I gave them the full explanation, they suggested to debug further so I logged the errors in debug.log file and when uploading I receive two logs in that file, I attached the log to this message.
Also this is what another guy from WP form told me:
You might be able to use data returned by get_current_screen() to check if the correct page is being vistited. Once that check is passed, you can perform your other checks such as is_user_wcmp_vendor(). Note that anything specific to is_user_wcmp_vendor() is out of scope here on WPSE as third-party plugins are not covered. Also, your code is going to cause problems because if the first condition is not met, $file is never returned. Filters should always return a value.Tim KerremansParticipantHi,
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;
}
}Tim KerremansParticipantadd_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 24, 2022 at 2:23 PM in reply to: Set min and max image resolution only on edit-product page #138230Tim KerremansParticipantHi,
They recommended to try debugging REQUEST_URI so I logged this in the errorlog and got the following log:
[24-Jun-2022 08:28:02 UTC] PHP Warning: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ (this will throw an Error in a future version of PHP) in /home/customer/www/staging5.holymowly.com/public_html/wp-content/themes/rehub-theme-child/functions.php on line 408And they also also recommended the following: would it be better to use applicable WP is_* function for checking the current page (ie /edit-post/) ?
-> I already tried getting the page based on template / ID without success.Hope this gives you some additional information to make this work.
Tim KerremansParticipantHi,
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
Tim KerremansParticipantHi,
Not sure about the default flow but in my case the the product is created and saved as draft once vendors are on edit-product page. I can see this as the products can be found in products -> drafts. There I can see in the URL that they do have a post ID assigned to them. Therefore I thought that it should be possible to grab the post id on the edit-product page.
If not, how should I use the hook? Add to the existing function or create a seperate function?
Tim KerremansParticipantYes, ticket is resolved 🙂
Tim KerremansParticipantThis issue has been resolved in the meantime so ticket can be closed 🙂
June 21, 2022 at 3:02 PM in reply to: Set min and max image resolution only on edit-product page #138126Tim KerremansParticipantHi,
Have posted this question on multiple forums in the meantime without any success. How can I do all these things on a WP hook?
I’m definitely willing to reach out to WP support but not sure how to create this hook as I don’t have much experience with PHPTim KerremansParticipantThis reply has been marked as private.Tim KerremansParticipantIt would be even better if the title of the product image is updated to the product ID when the product is submitted on the edit-product page. Maybe this is also easier to achieve?
So when vendor cliks on SUBMIT on edit product page -> Image title has to be change to Product ID
Tim KerremansParticipantThis works perfectly, thanks!
Tim KerremansParticipantHi,
Like I said it is working on WP Admin, but it is not working on the edit-product page from Advanced Frontend Manager plugin. (This is where the vendors upload images)
I think that is clear enough for you to test it, or do you need a video?
Tim KerremansParticipantIt seems like you didn’t understand what I’m trying to do.
This is the flow:
Step 1) Product gets created -> default title ‘Product’ is assigned
Step 2) Vendor edits product but forgets to edit the title and attach an image
Step 3) Vendor tries to submit the product
Step 4) Vendor gets message saying that he must attach image and change the default title before he can publish the productThe code i shared in this forum message was just a code I copy-pasted from another forum topic of this website for you to have a starting point. This code checks if title and image is set to the product.
What I’m asking: I need to check if the title equals ‘Product’, if so, the vendor must receive this error message as he cannot submit product with default title. If not, the vendor can publish the product as usual
-
AuthorPosts