Change upload directory on custom plugin page

After working on this for a bit and checking the GLOBALS variable for anything useful, it looks like the referring URL inside of the media modal is the same URL as my custom plugin page. Using that and splitting it up a bit I was able to confirm that I am on the approrpriate page. … Read more

how to upload image using wp_handle_upload

here’s my example of how to upload multiple images: add_action( ‘add_meta_boxes’, ‘my_test_metabox’ ); function my_test_metabox() { add_meta_box( ‘my_test_metabox’, ‘File upload’, ‘my_test_metabox_out’, ‘post’ ); } add_action(‘post_edit_form_tag’, ‘update_edit_form’ ); function update_edit_form() { echo ‘ enctype=”multipart/form-data”‘; } function my_test_metabox_out( $post ) { $files = get_post_meta( $post->ID, ‘my_files’, true ); if( ! empty( $files ) ) { echo ‘Files … Read more

admin-ajax.php returns 0. How do I debug it and fix it?

Enable Debugging WordPress has constants defined in wp-config.php where you can print errors to the screen and log them in a separate file located /wp-content/debug.log. It looks like this: define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_DISPLAY’, true ); define( ‘WP_DEBUG_LOG’, true ); You can then print your own information to the debug log at specific point … Read more

How to Reduce the Maximum Upload File Size?

You can forbid uploads of a specific size (or for other reasons) in the wp_handle_upload_prefilter hook that is used in the wp_handle_upload() function. It get’s the file array passed, it’s a single item in the PHP standard superglobal $_FILES one that is documented in the PHP Manual: POST method uploads. Just create a function and … Read more

Multisite, upload images directly to Amazon S3

If you are running on a dedicated linux server and are comfortable with the command line, you could install s3fs. This is a program that allows you to actually mount your Amazon s3 Bucket as a directory on you server. In the standard multisite environment, media uploads for all sites but the main site are … Read more

How to register images uploaded via FTP in media library?

It’s because you’re not registering them as a media type. Every upload is a WordPress post of the attachment type. To start, it would be something like this: $file_name=”Some Name”; $file_path=”/path/to/uploads/2012/08/04/newfile.jpg”; $file_url=”http://url/to/uploads/2012/08/04/newfile.jpg”; $wp_filetype = wp_check_filetype($file, null); $attachment = array( ‘guid’ => $file_url, ‘post_mime_type’ => $wp_filetype[‘type’], ‘post_title’ => $file_name, ‘post_status’ => ‘inherit’, ‘post_date’ => date(‘Y-m-d H:i:s’) … Read more

There’s a way to scale media (images) at 50%?

You can use image_downsize filter and to catch when WordPress wants a downscaled image and not original, and actually a size what doesn’t exist. add_filter( ‘image_downsize’, ‘wpse_60890_retina_scale’, 10, 3 ); function wpse_60890_retina_scale( $value, $id, $size ) { if ( $size == ‘wpse_60890_retina_scaled’ ) { if ( !is_array( $imagedata = wp_get_attachment_metadata( $id ) ) ) return … Read more

Refresh wp.media after ajax call

So, I followed your links and this is working for me. This test works the same for my upload callbacks so hopefully it works for you. In the iframe function myTab_save_frame() { global $redir_tab; $redir_tab = ‘mytab’; media_upload_header(); ?> <button>Test Trigger</button> <script> var switchAndReload = function() { // get wp outside iframe var wp = … Read more

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