Writing a plugin for WordPress and cannot manage to set the upload folder. Found this when I googled:
$upload_dir = "images/objects" . (isset($_REQUEST['ObjectNo']) ? "/{$_REQUEST['ObjectNo']}" : "");
$plugin_dir = WP_PLUGIN_DIR . '/' . BGREAL_PLUGIN_NAME;
$plugin_url = WP_PLUGIN_URL . '/' . BGREAL_PLUGIN_NAME;
function sss_configure_upload_dir($path_data)
{
global $upload_dir;
global $plugin_dir;
global $plugin_url;
$path_data['path'] = $plugin_dir . "/" . $upload_dir;
$path_data['url'] = $plugin_url . "/" . $upload_dir;
$path_data['subdir'] = "/" . $upload_dir;
$path_data['basedir'] = $plugin_dir;
$path_data['baseurl'] = $plugin_url;
return $path_data;
}
add_filter('upload_dir', 'sss_configure_upload_dir');
On the page where the uploader frame opens, I have got the following:
$upl = wp_upload_dir();
echo $upl['path'];`
Which echoes C:PATHTOHTDOCSpublic_html/wp-content/plugins/bg_real/images/objects/11212
The problem is, when I open the media upload frame and uploads an image, it save into /wp-content/plugins/bg_real/images/objects
since the $_REQUEST['ObjectNo']
is missing in the async-upload
function.
I need the images organized in folders after the querystring ObjectNo
.
Any ideas? Spent hours on Google etc. and tried different approaches but none seems to work.
Thanks,
I maintain the Custom Upload Dir-plugin for WordPress. It enables users to have context-aware upload paths (eg: folders named after the current post or author, datetimes etc). It’d be trivial to modify my filters to include your querystring.
In case someone stumbles upon this, you can use the
UPLOADS
directory constant from within yourwp-config.php
file:That’s it. The rest gets cared about automatically.