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

media_handle_upload : undefined function?

So I dont know if its the best way but my problem was the if statement surrounding the require_once on the necessary files that contain the function. Commented out the IF statement and it did the trick. I’ll go have that coffee now 😉 //if (!function_exists(‘wp_generate_attachment_metadata’)){ require_once(ABSPATH . ‘wp-admin/includes/image.php’); require_once(ABSPATH . ‘wp-admin/includes/file.php’); require_once(ABSPATH . ‘wp-admin/includes/media.php’); … Read more

Is there a way to get attachment data?

Don’t forget that attachments are just posts (though they are native posts and those tend to be a special case). Thus simply get_post() on attachment ID should get you typical post object for it. 🙂 Similarly all API functions that work on posts should work on attachments.

wp.media edit attachment screen

Long answer: Peeking into wp-includes/js/media-models.js, I see this: if ( ‘select’ === attributes.frame && MediaFrame.Select ) { frame = new MediaFrame.Select( attributes ); } else if ( ‘post’ === attributes.frame && MediaFrame.Post ) { frame = new MediaFrame.Post( attributes ); } else if ( ‘manage’ === attributes.frame && MediaFrame.Manage ) { frame = new MediaFrame.Manage( … Read more

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