Limit generation per user
-
Hey clem301 !
Thanks first for your question. I’m gonna develop this functionnality wich is useful for everyone. Should be something like that :
in the shortcode 2 news params:
– “user_limit”: number, default 0 (no limitation)
– “user_limit_duration”: number, default 0 (no refresh) = refreshed every X hours
The functionnality will check IPs to handle both connected / non connected users.
I’ll let you know here asap in the next daysHello Clem301,
I did the development. Let me know if it works for you :1. update AIG to v1.1.2
2. in the shorcode, set the parameter : user_limit=”3″ for 3 requests only
3. set the parameter : user_limit_duration=”3600″ for 3 requests only per hour for example. The value needs to be in seconds
By default user_limit = “0” (unlimited) and user_limit_duration = “0” (lifetime), so you can set limitations the way you want.
The limitation is checked by IP if not connected, and by ID else. Datas are saved inside transients in database. Transients expiration = user_limit_duration.Transients will be deleted by WordPress automatically when expired, except when user_limit_duration is set as “0” (lifetime).
The limitation is global and not by shortcode, let me know if you need the limitation by shortcode ??
Hope it will works ! Feel free to rate the plugin on WordPress, to give more visibility !“Thank you,
I didn’t expect to receive such a quick response. Thank you again for this fast update.
One more thing, if you have any ideas on how to download the generated images to a server folder and be able to reuse them later (for example, through a command) while disabling the download button at the same time, I would be interested.
Thanks again, I will test it right away.”
en fait plus tot que je peuisse enregistrer dans la miadiateque en options comme manual. Mais que je puisse possiblement ajouter une metadata a la photo avec le nom de la personne ou ip
Hello Clem301,
I’m answering in english as it will be useful for everyone
I can’t edit the plugin to do such a task as it is verify specific to you. Anyways, here is a workaround. The idea is to override the download buttons event on data-download=”manual” form, and bind another event which will do an ajax request to save the image. You can do that in javascript.
So, to have a clean code you need to edit the function.php file of your child-theme (as it will keep the code after theme updates) then add / edit this script and reload.
Please visit the Github link and copy/paste the entire code :https://github.com/Immolare/artist-image-generator/discussions/29
It will do the following things :
– Handle download buttons events if the “aig” shortcode is present on the page and the shortcode is set as “manual download”
– Remove current listeners and bind new ones
– In each new listeners, on click, trigger “custom_aig_manual_download” function through an ajax request on the server
– Next, “custom_aig_manual_download” will get the image url and save it via “media_sideload_image” to the WordPress Media Library
– Then, get the current_user_id or the user_ip and set it as media metadata.
– Hide the button when the image is downloaded inside WordPress
Currently the metadata is saved with the name “downloaded_by“, but you can change it as you need. You can also retrieve it later this way for each media :$attachment_id = {your_media_id};
$user_ip_or_id = get_post_meta($attachment_id, 'downloaded_by', true);
Is it working for you ? ??
Note: You can adapt the code as you want, but the process still the same for all cases
If your issue is resolved, feel free to rate this plugin ! Have a nice day,a super thank you for your speed, I will test it right away and I think that for your support I will buy the paid version
I’m sorry to be so annoying but I would like to retrieve the images to be able to add them as attributes to the customer’s order (thus different for each customer) and therefore retrieve the person’s IP and look at the last image in the media library that corresponds to them Do you have an idea ? And thank you again for helping me
No problem, glad to help !
I see what you are trying to do when visiting your website and your Woocommerce product page.
Do you need to add a customization field to the product you sell ? E.g, AI generation tool which let the user to generate images and use 1 image as a customized attribute for each product, then retrieve it in each product order ?
If so, i don’t know the way you want to handle it, but I can provide you a solution that you can adapt in your code (add CSS, customize, that’s an exemple)
https://github.com/Immolare/artist-image-generator/discussions/30-> If not working, try adding and attribute “custom image” with value “foo” inside your product, then retry with the same code
If the solution does not match, the code provide an exemple of all the functions you need to upload the AIG image of the user, set media metadatas and woocommerce metadata, and retrieve theses meta inside each order.
Basically to set WooCommerce metadata for each product, you need to work with :// Add custom metadata to the order item when creating the order add_action('woocommerce_checkout_create_order_line_item', function($item, $cart_item_key, $values, $order) { if (isset($values['custom_aig_image_id'])) { $item->add_meta_data('custom_aig_image_id', $values['custom_aig_image_id']); $image_src = wp_get_attachment_image_src($values['custom_aig_image_id'], 'full'); if ($image_src) { $item->add_meta_data('custom_image', esc_url($image_src[0])); } } }, 10, 4);
To retrieve an image by IP in WC dashboard order, just edit the function “display_custom_image_in_admin_order“, get the order IP and loop images which have same (downloaded_by or ip_address)
Have a nice day ! And thanks for your rating ??un grand merci a vous pour tout ce que vous avez fait
jai changer ca mais ca ne changer rien
// Add shortcode inside WooCommerce product page
function display_custom_shortcode() {
echo do_shortcode(‘[aig prompt=”Painting of {public_prompt}, including following criterias: {topics}” user_limit=”5″ user_limit_duration=”3600″ topics=”impressionnisme, Surréalisme, Portraits, Peinture de paysages , Aquarelle, Peinture a l\’huile, Street Art, Hyperréalisme, chat, chien, oiseau, personnes” model=”dall-e-3″ size=”1024×1792″ download=”manual”]’);finalement résolu merci a vous si vous voulez voir
- This reply was modified 8 months, 1 week ago by clem301.
- This reply was modified 8 months, 1 week ago by James Huff. Reason: redundant link removed
Super ! ?a m’a l’air de bien fonctionner ?? Au plaisir d’avoir pu vous aider. Je vous souhaite de bonnes ventes, et merci encore d’utiliser Artist Image Generator !
Hello, I’m sorry to bother you again. Would it be possible for it to record automatically after each generation instead of pressing the button. Of course, when we add to the cart, it takes the last image. And what does your paid version add?
thankHello clem301 !
I’ll try to do an update soon for AIG because it needs some improvment and code adaptation. Could be a new parameter in the shortcode but not in the snippet.
For the paid version, I wrapped it up inside a wordpress plugin, improved the code, the UX and i did a “live preview version” which works like this:
- You have a blank frame or a t-shirt to sell
- You can set up a basic customization area inside the main image of the product (via a mask build on photoshop or directly throught AIG premium)
- And on the front product page when the user generate images, he can click on each image to preview the rendering on the product itself
It is globally a very simple “live product designer”.
Note that if you need more than 1 image per request with dall-e 3 and the tool to create the mask you need an AIG Licence key too. I bundled this 2 products inside 1 on AIG website so you can setup all this independant things together.
Have a nice day,
thank you very much, I think I will buy because your work is just spectacular and I think we should support you too
- The topic ‘Limit generation per user’ is closed to new replies.