anonymized-13171256
(@anonymized-13171256)
Add this to your theme’s functions.php or create an mu-plugin:
/**
* Custom upload directory for Strong Testimonials
*
* @param array $uploads
*
* @return array
*/
function my_testimonials_upload_dir( $uploads ) {
if ( isset( $_REQUEST['wpmtst_submit_testimonial'] ) ) {
$uploads['path'] .= '/testimonials';
$uploads['subdir'] = 'testimonials';
}
return $uploads;
}
add_filter( 'upload_dir', 'my_testimonials_upload_dir' );
anonymized-13171256
(@anonymized-13171256)
This code works for both the post editor and the front-end form.
/**
* Custom upload directory for Strong Testimonials
*
* @param array $uploads
*
* @return array
*/
function my_testimonials_upload_dir( $uploads ) {
// In the post editor or through the front-end form
if ( ( isset( $_REQUEST['post_id'] ) && 'wpm-testimonial' == get_post_type( $_REQUEST['post_id'] ) )
|| isset( $_REQUEST['wpmtst_submit_testimonial'] ) )
{
$uploads['path'] .= '/testimonials';
$uploads['subdir'] = 'testimonials';
}
return $uploads;
}
add_filter( 'upload_dir', 'my_testimonials_upload_dir' );
Hi Chris, thank you this works well but the “uploads/2017/05/testimonials” directory is inside the current year folder in uploads, can it be “uploads/testimonials”
anonymized-13171256
(@anonymized-13171256)
Sorry about that. I have not used the month/year option in so long, I did not consider that.
<?php
/**
* Custom upload directory for Strong Testimonials
*
* @param array $uploads
*
* @return array
*/
function my_testimonials_upload_dir( $uploads ) {
// In the post editor or through the front-end form
if ( ( isset( $_REQUEST['post_id'] ) && 'wpm-testimonial' == get_post_type( $_REQUEST['post_id'] ) )
|| isset( $_REQUEST['wpmtst_submit_testimonial'] ) )
{
$uploads['subdir'] = '/testimonials';
$uploads['path'] = $uploads['basedir'] . $uploads['subdir'];
$uploads['url'] = $uploads['baseurl'] . $uploads['subdir'];
}
return $uploads;
}
add_filter( 'upload_dir', 'my_testimonials_upload_dir' );