Hook or function to upload media via url

See media_handle_sideload in Codex: $url = “http://s.wordpress.org/style/images/wp3-logo.png”; $tmp = download_url( $url ); $post_id = 1; $desc = “The WordPress Logo”; // Set variables for storage // fix file filename for query strings preg_match(‘/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/’, $file, $matches); $file_array[‘name’] = basename($matches[0]); $file_array[‘tmp_name’] = $tmp; // If error storing temporarily, unlink if ( is_wp_error( $tmp ) ) { @unlink($file_array[‘tmp_name’]); … Read more

Prevent File Uploads other than images

Your solution will prevent non-image file downloads but uploads will still be allowed. You could use the wp_handle_upload_prefilter hook (https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter) to get to the filename in it’s temp location, inspect it, and set an error. That hook is passed a single array and setting a string to the ‘error’ key will abort the upload processing … Read more

How to change “Publish” button text for specific page

I wanted to change the Publish button’s text in the Block Editor and came across this question. With the answers given it wasn’t changing the text. With the Gutenberg update, I realized it would have to be done with JavaScript. I found this response: Changing text within the Block Editor Which I applied in my … Read more

“upload_mimes” filter not working. Need to allow WOFF and WOFF2

I see a correct implementation at https://wordpress.stackexchange.com/a/323226/24756. Technically, you need to pass down the extension down to filter wp_check_filetype_and_ext as well. And for WOFF/WOFF2, I’d suggest using the following format: $mimes[‘woff’] = ‘font/woff|application/font-woff|application/x-font-woff|application/octet-stream’; $mimes[‘woff2’] = ‘font/woff2|application/octet-stream|font/x-woff2’; For .webp, it can simply be image/webp. Hope it helps.

Front-end Image Upload with Preview – Is this Possible in WP?

Just add this scripts in header <script src=”http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js”></script> <script> var blank=”http://upload.wikimedia.org/wikipedia/commons/c/c0/Blank.gif”; function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $(‘#img_prev’) .attr(‘src’, e.target.result) .height(100); }; reader.readAsDataURL(input.files[0]); } else { var img = input.value; $(‘#img_prev’).attr(‘src’,img).height(200); } $(“#x”).show().css(“margin-right”,”10px”); } $(document).ready(function() { $(“#x”).click(function() { $(“#img_prev”).attr(“src”,blank); $(“#x”).hide(); }); }); </script> … Read more

how to add new .webm mime types

The WebM file format isn’t known to WordPress by default, you have to add it. add_filter( ‘upload_mimes’, ‘custom_mimes’ ); function custom_mimes( $mimes ){ $mimes[‘webm’] = ‘video/webm’; return $mimes; } The .ogg file format is known to WordPress as audio/ogg, if you’re wanting to do video with it, the correct extension is .ogv.

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