Setting the uploads directory

You can use the ‘upload_dir’ filter add_filter(‘upload_dir’, ‘set_upload_folder’, 999); function set_upload_folder( $upload_data ) { // absolute dir path, must be writable by wordpress $upload_data[‘basedir’] = trailingslashit(ABSPATH). ‘/files’; $upload_data[‘baseurl’] = ‘http://subdomain.wptest.com/files’; $subdir = $upload_data[‘subdir’]; $upload_data[‘path’] = $upload_data[‘basedir’] . $subdir; $upload_data[‘url’] = $upload_data[‘baseurl’] . $subdir; return wp_parse_args($upload_data, $upload_data); } This code will works no matter if year/month … Read more

.epub file blocked despite ALLOW_UNFILTERED_UPLOADS set to true

You probably need to allow the mime types for them to be allowed to upload. https://www.robertwent.com/blog/adding-custom-mime-types-for-wordpress-uploads/ //The following goes in a themes functions file or a custom hooks plugin function so_387865_custom_upload_mimes ( $existing_mimes ) { $existing_mimes[‘epub’] = ‘application/epub+zip’; $existing_mimes[‘mobi’] = ‘application/x-mobipocket-ebook’; return $existing_mimes; } add_filter(‘upload_mimes’, ‘so_387865_custom_upload_mimes’);

Accessing a random image via ajax

There is an error in your src; <img src=”http://example.com//wp-admin/admin-ajax.php?action=random_banner”> Try this one: <img src=”http://example.com/wp-admin/admin-ajax.php?action=random_banner”> or <img src=”https://wordpress.stackexchange.com/questions/215158/<?php echo admin_url(“admin-ajax.php?action=random_banner’ ); ?>”> You can also use a query to get a random image. AJAX add_action( ‘wp_ajax_random_banner’, ‘random_banner’ ); add_action( ‘wp_ajax_nopriv_random_banner’, ‘random_banner’ ); function random_banner() { // search for 1 random image $image_ids = get_posts( array( ‘post_type’ … Read more

File exceeds upload_max_filesize, despite max filesize being large enough

Apparently there’s an upload_size_limit filter in WordPress. To check what your site’s upload limit is set to, add this to your theme’s functions.php: add_action( ‘shutdown’, ‘wpse115322_upload_sizes’, 99 ); function wpse115322_upload_sizes() { $size = wp_max_upload_size(); $kb = $size/1024; $mb = $size/(1024*1024); echo( “$kb KB / $mb MB<br />\n” ); } That’ll print your site’s actual max … Read more