Use Media upload in custom widget on wordpress 3.5

Check if this works for you: Put this code in jQuery(document).ready( function(){ function media_upload( button_class) { var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; jQuery(‘body’).on(‘click’,button_class, function(e) { var button_id =’#’+jQuery(this).attr(‘id’); /* console.log(button_id); */ var self = jQuery(button_id); var send_attachment_bkp = wp.media.editor.send.attachment; var button = jQuery(button_id); var id = button.attr(‘id’).replace(‘_button’, ”); _custom_media = true; wp.media.editor.send.attachment = function(props, … Read more

Adding upload button in metabox

this is how I do to create upload button in metabox: FILE: template_dir/functions.php add this lines: wp_enqueue_script(‘custom-js’, get_template_directory_uri().’/js/custom-js.js’); // Add the Meta Box function add_custom_meta_box() { add_meta_box( ‘custom_meta_box’, // $id ‘Custom Meta Box’, // $title ‘show_custom_meta_box’, // $callback ‘post’, // $page ‘normal’, // $context ‘high’); // $priority } add_action(‘add_meta_boxes’, ‘add_custom_meta_box’); // Field Array $prefix = … Read more

getting uploaded SVG dimensions on front-end

I agree with Tom J Nowell on the use of SVG, but if the upload is an actual image, you can tap into the attachment attributes using, as you suggested, wp_get_attachment_image_src. Those dimensions are actually already recorded and stored when using the WP media uploader, it’s likely that the plugin you’re using makes use of … Read more

Resizing only featured images while uploading

You can simply set all unused image size attributes to 0 to stop WordPress generating them. Whilst this only applies for default image sizes, you can use filters to remove them. In general, WP stores all those sizes to generate images for in the global $_wp_additional_image_sizes. The following plugin uses a filter to remove sizes … Read more

Prevent image upload unless exact size

Haven’t tested it, but this should work: // check for file upload size // { if( !current_user_can( ‘administrator’) ) add_filter( ‘wp_handle_upload_prefilter’, ‘mdu_validate_image_size’ ); } add_filter(‘wp_handle_upload_prefilter’,’mdu_validate_image_size’); function mdu_validate_image_size( $file ) { if ( mime_content_type($file) == ‘application/zip’ ) { mdu_validate_zip_image_size($file); return $file; } $image = getimagesize($file[‘tmp_name’]); $minimum = array( ‘width’ => ‘800’, ‘height’ => ‘450’ ); $maximum … Read more

How to crop image from image src in a specific size

WordPress has a function solely designed for this purpose. the attachment_url_to_postid() allows you to retrieve an attachment’s ID from it’s URL, which then you can use to get the post’s ID later. If you want to do it by writing a MySQL query, i would however prefer to suggest searching the file’s name in meta_value … Read more

Displaying images with relative paths in the editor

I had a client ask for that and it took a little while to get it but its simple: function change_mce_path_options( $init ) { $init[‘relative_urls’] = true; $init[‘document_base_url’] = get_bloginfo(‘url’); return $init; } add_filter(‘tiny_mce_before_init’, ‘change_mce_path_options’);

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