How to force Media manager to overwrite files of same name?

Here is something i cooked up which was taken mainly from the plugin Overwrite Uploads but without the extra stuff add_filter(‘wp_handle_upload_overrides’,’noneUniqueFilename’); function noneUniqueFilename($overrides){ $overrides[‘test_form’] = false; $overrides[‘unique_filename_callback’] = ‘nonUniqueFilenameCallback’; return $overrides; } function nonUniqueFilenameCallback($directory, $name, $extension){ $filename = $name . strtolower($extension); //remove old attachment removeOldAttach($filename); return $filename; } function removeOldAttach($filename){ $arguments = array( ‘numberposts’ => … Read more

media_sideload_image file name?

When I started using media_sideload_image(), I found it pretty useless as it returned a full html tag, instead of the attachment ID, so I created my own version of it which replicates all the functionality of media_sideload_image() and adds some very useful stuff, like: saving the sideloaded file under a completely new filename making the … Read more

How do I ‘rebuild’ the WordPress Media library after transfer to new host?

There’s a few plugins to fix this, but basically it your database still references the images to be “oldsite.com/wp-content/uploads/” and you need it to be “newsite.com/wp-content/uploads” So you have to change all old references. You could use SQL: UPDATE wp_options SET option_value = replace(option_value, ‘http://www.oldsite.com’, ‘http://www.newsite.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’; UPDATE … Read more

Hide old attachments from wp media library

You can adjust the attachment query in the media library popup, through the ajax_query_attachments_args filter. Here are two PHP 5.4+ examples: Example #1: Show only attachments that where uploaded during the last 24 hours: /** * Media Library popup * – Only display attachments uploaded during the last 24 hours: */ add_filter( ‘ajax_query_attachments_args’, function( $args … Read more

Creating a metabox to upload multiple images, Ignoring The Featured Image

Generally speaking, I would take the approach of querying for post attachments, but withhold the attachment that is the post thumbnail. WP provides a simple way of finding the post thumbnail ID with get_post_thumbnail_id (Codex Ref). To modify the code from the other post, I would add the following parameter to the $args array to … Read more

Disable media library tab for non admins in uploader screen

This function will not show media library tab in upload screen function remove_medialibrary_tab($strings) { if ( !current_user_can( ‘administrator’ ) ) { unset($strings[“mediaLibraryTitle”]); return $strings; } else { return $strings; } } add_filter(‘media_view_strings’,’remove_medialibrary_tab’); I found out that switching to media library tab actually call this ajax action query-attachments. So i added another callback function to this … Read more

How to call WP3.5 Media Library manager?

From the article How to use WordPress 3.5 Media Uploader in Theme Options (by codestag.com), as seen in Using the WordPress 3.5 Media Uploader within plugins (by mikejolley.com). Mike Jolley’s article has quite some nice tricks. Important note: if the page where the uploader is going to be used doesn’t already have all media JS … Read more

Is it possible to trigger some JavaScript when Media Popup is opened?

You can use several event handlers. frame.on(‘open’,function() { // Do something }); frame.on(‘close’,function() { // Do something }); frame.on(‘select’,function() { // Do something }); Where frame is a reference to wp.media() frame = wp.media(); frame.on(‘select’,function() { // Do something }); Full example Script en-queued with jQuery and media editor as dependencies. function media_script_enqueue() { wp_enqueue_script( … Read more

Is there a user-facing interface to edit an attachment’s permalink?

This’ll add a slug field to the edit attachment page, which’ll allow you to independently change it when and how you choose to. Drop it into a plugin or your theme’s functions.php; function wpse_12405_edit_attachment_name( $fields, $post ) { $fields[‘post_name’] = array( ‘label’ => __( ‘Slug’ ), ‘value’ => $post->post_name, ); return $fields; } add_filter( ‘attachment_fields_to_edit’, … Read more

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