Thumbnails generated from PDF in the “Media” section – how to show them in theme template?

To get the attachment’s icon, you can use wp_get_attachment_image(). For example, let’s say I’ve uploaded a Word doc and it’s got the ID 1234: // Parameter 3 – ‘true’ – tells WP to treat this as an icon. $img_tag = wp_get_attachment_image( 1234, ‘thumbnail’, true ); // $img_tag contains: // <img width=”48″ height=”64″ // src=”http://example.com/wp-includes/images/media/document.png” // … Read more

How can I receive the image id using the media box?

You can also add in a filter that can add the ID as a html5 data attribute to the returned HTML fragment from send_to_editor. public function image_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt){ $dom = new DOMDocument(); @$dom->loadHTML($html); $x = new DOMXPath($dom); foreach($x->query(“//img”) as $node){ $node->setAttribute(“data-id”, $id); } if($dom->getElementsByTagName(“a”)->length == 0){ $newHtml = $dom->saveXML($dom->getElementsByTagName(‘img’)->item(0)); … Read more

How to restrict wp-admin and prevent upload errors

You just need one extra thing for this. Here is the code I typically use to do what you are doing: function pws_block_admin() { if ( // Look for the presence of /wp-admin/ in the url stripos($_SERVER[‘REQUEST_URI’],’/wp-admin/’) !== false && // Allow calls to async-upload.php stripos($_SERVER[‘REQUEST_URI’],’async-upload.php’) === false && // Allow calls to admin-ajax.php stripos($_SERVER[‘REQUEST_URI’],’admin-ajax.php’) … Read more

How can I serve a text file at a custom URL

You can utilize add_rewrite_rule to create a new endpoint like http://example.com/api/files/xyz which processes the request and renders the contents from your server. This allows you to mask the origin of the file but still access it’s content. add_rewrite_rule requires you flush_rewrite_rules but you only need to do that once every time you make a change … Read more

3.5 Media Manager – callout in metaboxes

you can move the wp.media stuff to an external function which accepts the element as a parameter and call it on the click event like this: jQuery(document).ready(function($){ $(‘.media-upload-button’).click(function(e) { e.preventDefault(); upload_image($(this)); return false; }); }); function upload_image(el){ var $ = jQuery; var custom_uploader; var button = $(el); var id = button.attr(‘id’).replace(‘_button’, ”); if (custom_uploader) { … Read more

How to limit characters of the post title?

You could do this : add_action(‘publish_post’, ‘wpse_107434_title_max_char’); function wpse_107434_title_max_char() { global $post; $title = $post->post_title; if (strlen($title) >= 100 ) wp_die( “the title must be 100 characters at most” ); } You can replace strlen() with str_word_count() if you want to set a word limit instead. EDIT: ok with new details you added it seems … Read more