“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

How to make “Upload files”selected by default in Insert Media?

Add this to your functions.php, or preferably a functionality plugin. add_action( ‘admin_footer-post-new.php’, ‘media_manager_default’ ); add_action( ‘admin_footer-post.php’, ‘media_manager_default’ ); function media_manager_default() { ?> <script type=”text/javascript”> jQuery(document).ready(function($){ wp.media.controller.Library.prototype.defaults.contentUserSetting=false; }); </script> <?php }

Using WordPress 3.5 Media Uploader in meta box?

To get you started, the basic functions and overrides as far as I know currently.There might be better solutions, but I only had two days with 3.5 yet: // open modal – bind this to your button if ( typeof wp !== ‘undefined’ && wp.media && wp.media.editor ) wp.media.editor.open( ##unique_id_here## ); // backup of original … Read more

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