2

I am using WooCommerce & dokan as multivendor plugin. Sadly, by default Dokan don’t have the option to add Media files in product description like in WooCommerce.

It looks like this: enter image description here

I found a way to add “Add Media” option that exists in the normal WooCommerce description editor to here as well using this code:

add_action(‘dokan_product_short_description’, ‘add_demo_description’);
function add_demo_description(){
   update_post_meta( get_the_ID(), '_desc', 'Lorem ipsum text' );
}

Now it looks like this: enter image description here

It actually works, I can add media library items and upload new ones through the Dokan vendor dashboard, and they also appear on the product page description, which is exactly what I need.

Look on product page: enter image description here

So now that users can add their Media in product description, I understood there is a new problem. the problem is that they can upload any file type here, which is not good because I don’t want people uploading weird stuff to the product description, the only relevant file in my case is MP3, That’s the only file type I want people to be able to insert into the product description.

It's also important to be able to limit file size and file amount, so trolls & bots won't be able to upload 10k files at 10gb each and destroy my server.

Any idea what I can do to ensure people can’t insert anything other than MP3 to the product description?

P.S: If you know of ways to style / change that default mp3 media player to something better that would be great.

Thank you!

5
  • can you remove the offsite links to imgur and embed the images directly into the question using the image button in the toolbar? Use the edit link to adjust your question. Also your dokan code block just has // code here. There's a Very high chance though that what you want to do requires Dokan specific knowledge that isn't solvable using general WordPress knowledge, which would make this question offtopic. 3rd party plugin/theme dev questions are offtopic on this stack. Update your question with the missing code and fix the image embeds
    – Tom J Nowell
    Oct 4, 2022 at 12:45
  • 1
    @TomJNowell Ok. Updating it. Oct 4, 2022 at 13:07
  • Hello @DavidMclauren, Welcome to the community. As per my understanding, you want to do 2 tasks. first, restrict the file upload size & second give styling to the mp3 player. I saw your code here, however, I want to suggest you different approach to add a file upload button to the description with your requirements. Should I share my solution with you? Oct 4, 2022 at 13:20
  • Yes of course Ashok!!! You can share here. Oct 4, 2022 at 13:21
  • I see you have in one of your screenshots a "added by functions.php" but it's not clear what you did in functions.php and your filter only updates post meta it doesn't modify anything else
    – Tom J Nowell
    Oct 4, 2022 at 13:46

2 Answers 2

1

The code you have added has an undefined constant which might create an issue with the latest PHP versions. Instead, you may use the code given below which will allow you to add media to the short description and description.

add_filter('dokan_product_short_description', 'add_media_button');
add_filter('dokan_product_description', 'add_media_button');

function add_media_button(){
  return array(
    'media_buttons' => true
  );
}

After adding these codes, you shall see the add media button on your vendor dashboard product short and long description fields.

Now, to remove the file type and size upload problem, you may use a third-party plugin rather than using a hard code. You can also restrict file type and size upload by user roles. I would suggest using WP Upload Restriction plugin. With this plugin, you can limit upload size and type. Though this is not tested by me since it’s a third-party plugin but it should work.

To change the default media player style, you may take the help of this article: https://www.cssigniter.com/css-style-guide-for-the-default-wordpress-media-player/

Hope this helps.

0

Thank you i put this code in my child theme function.php and it works.

add_filter('dokan_product_short_description', 'add_media_button');
add_filter('dokan_product_description', 'add_media_button');

function add_media_button(){
  return array(
    'media_buttons' => true
  );
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.