Filter by post category in Media Library

You can use pre_get_posts to filter the query. So you can retrieve a category from query vars the retrieve the post with that category set the media query to include only post having that posts as parent To give an UI you can use restrict_manage_posts hook to output a category dropdown. add_action(‘pre_get_posts’, ‘my_filter_media_by_cat’); add_action( ‘restrict_manage_posts’, … Read more

How to wp_upload_bits() to a sub-folder?

wp_upload_bits() uses wp_upload_dir() which fires the upload_dir filter allowing you to modify the upload directory’s path, sub-directory and URL. So you can use that filter to “force” wp_upload_bits() to use a custom path by doing something like: // Demo to get the image data. $url=”https://logo.clearbit.com/starcomww.com”; $content = file_get_contents( $url ); $_filter = true; // For … Read more

Can I use the wp media uploader for my own plugin?

You can use wp_enqueue_media() in your admin_enqueue_scripts hook. In a javascript file hook it into a button and use insert event to capture the selected image’s details $(‘.media-button’).click(function() { var media_uploader = wp.media({ frame: “post”, text : “Add image”, state: “insert”, multiple: false }); media_uploader.on(“insert”, function(){ var json = media_uploader.state().get(“selection”).first().toJSON(); var image_name = json.filename; var … Read more

Protecting direct access to PDF and ZIP unless user logged in (without plugin)

RewriteCond %{REQUEST_FILENAME} -s RewriteRule ^wp-content/uploads/([^/]*\.(pdf|zip))$ filecheck.php?file=$1 [QSA,L] This actually looks OK, except if you have additional subdirectories within the /uploads directory? An alternative is to include an additional condition on the original rule that only rewrites the request if the request ends in .pdf or .zip. For example: RewriteCond %{REQUEST_URI} \.(pdf|zip)$ [NC] RewriteCond %{REQUEST_FILENAME} -s … Read more

Add inline uploader to plugin option page

Okay, here is what I came up with: It’s all about using the plupload library that comes shipped with WP. 1. Add a <div> to your plugin’s option page that later becomes the drag’n’drop area <div class=”your-plugin-uploader multiple”> <input id=”your-plugin-uploader-button” type=”button” value=”<?php esc_attr_e( ‘Select Files’ ); ?>” class=”your-plugin-uploader-button button”> <span class=”ajaxnonce” id=”<?php echo wp_create_nonce( __FILE__ … Read more

Filter for changing MediaElement.js Settings

Copy wp-includes/js/mediaelement/wp-mediaelement.js into your theme or plugin and make your modifications there. For example, I added some settings to force the use of native video controls on iOS & Android devices, like so: (function ($) { // add mime-type aliases to MediaElement plugin support mejs.plugins.silverlight[0].types.push(‘video/x-ms-wmv’); mejs.plugins.silverlight[0].types.push(‘audio/x-ms-wma’); $(function () { var settings = { // Put … Read more

Image upload callback in new 3.5 media

There is a FileUploaded event being fired in wp-includes/js/plupload/wp-plupload.js. Alternatively (and propably the better way) you may want extend wp.Uploader with your own success callback . (function($){ $.extend( wp.Uploader.prototype, { success : function( file_attachment ){ console.log( file_attachment ); } }); })(jQuery);

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