How to disable generation of default image sizes for some custom post types?

I think the only solution you have at the moment is to disable all intermediate image sizes: add_filter( ‘intermediate_image_sizes’, ‘__return_empty_array’, 99 ); And then manually generate them, depending on the post type, by hooking into ‘wp_generate_attachment_metadata’, where you do have access to the attachment id (and therefore to it’s parent post): function do_your_stuff( $data, $attachment_id … Read more

“Add Media” button in custom plugin

If you want to add a add media button to your admin panels: You need to use wp_enqueue_media(); add_action ( ‘admin_enqueue_scripts’, function () { if (is_admin ()) wp_enqueue_media (); } ); Then use this js: jQuery(document).ready(function() { var $ = jQuery; if ($(‘.set_custom_images’).length > 0) { if ( typeof wp !== ‘undefined’ && wp.media && … Read more

Get $image_id after uploading with media_sideload_image()

Here is an example of how to bypass this limitation using actions/hooks: function new_attachment( $att_id ){ // the post this was sideloaded into is the attachments parent! // fetch the attachment post $att = get_post( $att_id ); // grab it’s parent $post_id = $att->post_parent; // set the featured post set_post_thumbnail( $post_id, $att_id ); } // … Read more

Specific upload folder for PDFs in custom Post type in WP multisite

you might consider using if(get_post_mime_type($id) == ‘application/pdf’){ … } to check for pdf files. http://codex.wordpress.org/Function_Reference/get_post_mime_type You might also take a look at the code behind the wp_delete_attachment() function and you can hook into it with the delete attachment action. To remove the files you can use unlink() http://php.net/manual/en/function.unlink.php

Load minimum WordPress environment

Disabling plugins entirely means you loose many advantages. There are distributions of wordpress that go further and rip out posts and links etc, but they’ll always lag behind WordPress core and tend not to survive as long. Here are some things that could be done Short Init Putting this in your wp-config.php: define( ‘SHORTINIT’, TRUE … Read more

Change upload directory for PDF files

Following Justice Is Cheap lead, I ended adapting the functions from this plugin: http://wordpress.org/extend/plugins/custom-upload-dir/ <?php /* * Change upload directory for PDF files * Only works in WordPress 3.3+ */ add_filter(‘wp_handle_upload_prefilter’, ‘wpse47415_pre_upload’); add_filter(‘wp_handle_upload’, ‘wpse47415_post_upload’); function wpse47415_pre_upload($file){ add_filter(‘upload_dir’, ‘wpse47415_custom_upload_dir’); return $file; } function wpse47415_post_upload($fileinfo){ remove_filter(‘upload_dir’, ‘wpse47415_custom_upload_dir’); return $fileinfo; } function wpse47415_custom_upload_dir($path){ $extension = substr(strrchr($_POST[‘name’],’.’),1); if(!empty($path[‘error’]) || … Read more