Rename image during upload using date and time stamp?

You could e.g. check the filename and extension from the pathinfo, after your custom sanitization. Example: If the filename is empty and extension non-empty, then add the formatted current time as the filename part: $info = pathinfo( $file[‘name’] ); if( empty( $info[‘filename’] ) && ! empty( $info[‘extension’] ) ) $file[‘name’] = sprintf( ‘%s.%s’, current_time( ‘Y-m-d-H-i-s’ … Read more

Any way to define WP_UPLOADS_URL (like WP_CONTENT_URL)?

Since version 3.5 you can define constant ‘UPLOADS’ like: define(‘UPLOADS’,’myfiles’); where ‘myfiles’ is a folder location relative to ABSPATH. If the folder does not exist, it will be automatically created. EDIT: It will only work, if a new folder is located below website’s Document Root folder ( ABSPATH ). To put it outside of ABSPATH … Read more

How to upload all media to one folder, with no year/month subfolders

Pop this tiny code snippet into a file located here: wp-content/mu-plugins/upload-dir.php (a must use plugin file). Create the mu-plugins directory if it does not exist already. <?php add_filter( ‘pre_option_uploads_use_yearmonth_folders’, ‘__return_zero’); What you’re doing here is filtering an option value at runtime, which is picked up internally by _wp_upload_dir() and therefore uploads are no longer nested … Read more

Add media attachment filter to custom wp.media frame

You need to make use of filterable property. To do that, you can extend the library and use that as a custom state. // Create state var myCustomState = wp.media.controller.Library.extend({ defaults : _.defaults({ id: ‘my-custom-state’, title: ‘Upload Image’, allowLocalEdits: true, displaySettings: true, filterable: ‘all’, // This is the property you need. Accepts ‘all’, ‘uploaded’, or … Read more

why when I try to insert an image attachment along with a post does wp_get_attachment_url give me a very wrong file path?

It turns out I was barking up the wrong (or at least a slightly different) tree by using wp_insert_attachment. media_sideload_image managed to pull attachments from other blogs on the same multisite install, copy them to the aggregating blog’s uploads directory, and generate thumbnails, while wp_insert_attachment was doing what it was supposed to, which just happened … Read more

Limit upload by file type only for certain custom post type

function wpse_59621_mimes_filter( $mimes ) { return array( ‘pdf’ => ‘application/pdf’ ); } function wpse_59621_delay_mimes_filter( $value ) { if ( isset( $_REQUEST[‘post_id’] ) && get_post_type( $_REQUEST[‘post_id’] ) === ‘my_post_type’ ) add_filter( ‘upload_mimes’, ‘wpse_59621_mimes_filter’ ); else remove_filter( ‘upload_mimes’, ‘wpse_59621_mimes_filter’ ); return $value; } add_filter( ‘wp_handle_upload_prefilter’, ‘wpse_59621_delay_mimes_filter’ ); Let us know how it goes – this is untested, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)