trying to use wp_handle_upload with ajax

You need to include a few files to get wp_handle_upload to work, and i have a function just for that : function My_wp_handle_upload($file_handler,$overrides) { // check to make sure its a successful upload if ($_FILES[$file_handler][‘error’] !== UPLOAD_ERR_OK) __return_false(); require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/file.php’); require_once(ABSPATH . “wp-admin” . ‘/includes/media.php’); $upload = … Read more

Get most recent media upload

I don’t think that you can use get_the_post_thumbnail function to get last uploaded media, but you can use get_post to get latest attachment and then wp_get_attachment_image to display images. $attachments = get_posts( array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 1, ‘post_status’ => null, ‘post_mime_type’ => ‘image’ ) ); foreach ( $attachments as $attachment ) { echo … Read more

HTML tags in WordPress image caption

I’m glad that better support should be added in version 3.4 but for now I’ve fixed the issue by changing the behaviour of image insertion so that it doesn’t use the shortcode. Here’s what I added to functions.php: add_filter( ‘disable_captions’, create_function(‘$a’, ‘return true;’) ); function image_send_to_editor_2($html, $id, $caption, $title, $align, $url, $size, $alt) { if … Read more

What types of files can I upload with the WordPress Uploader?

From http://codex.wordpress.org/Uploading_Files : WordPress supports uploading the following file types: Images .jpg .jpeg .png .gif Documents .pdf (Portable Document Format; Adobe Acrobat) .doc, .docx (Microsoft Word Document) .ppt, .pptx, .pps, .ppsx (Microsoft PowerPoint Presentation) .odt (OpenDocument Text Document) .xls, .xlsx (Microsoft Excel Document) Audio .mp3 .m4a .ogg .wav Video .mp4, .m4v (MPEG-4) .mov (QuickTime) .wmv … Read more

add_image_size() to crop images into squares?

If you pass true for the last $crop argument then so called “hard” crop mode is used. This will make WP produce results at exact size specified, except few edge cases (if image uploaded is smaller than specified size for example). Note that original image is still retained as is. If you need to actually … Read more

Unable to Upload Images on Local Windows Install

After trying many things with permissions, I found my problem. I uses a plugin called Duplicator to move WordPress installs around from server to server, it handles changing URLS’s and Paths. So in settings => Media => Store uploads in this folder it was setting the Full Filepath to my Uploads folder. I changed it … Read more

Placing assets for external use

I have used symbolic links for convenience for awhile on a dev server but they are not 100% reliable as some PHP functions will return the filesystem path of the target instead of the path to the symlink itself. The most notable example (though not really a function) is the magic constant __FILE__. (Also https://bugs.php.net/bug.php?id=46260) … Read more

How do I modify the url of uploaded media content?

Use a plugin like Deploy Helper. Essentially, it allows you to swap out all instances of one URL with another, and will also handle serialized data. Just enter the old URL as media.detailsofmylife.net/uploads and the new one as www.detailsofmylife.net/wp-content/uploads. Make sure you also reset your custom upload paths. If you’d defined constants like WP_CONTENT_URL or … Read more

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