media sideload image not working with JPG file

You should check for the special characters in url, sometimes url structures may contain special characters like space, &, ‘ . use str_repalce to replace known special characters or urlencode. media_sideload_image works properly with JPG as well so either url contains special characters. If you can access image through url there is not a permission … Read more

Adding Adobe files to a wordpress site [closed]

Allowing file types outside of WP’s defaults exposes your site to some security risks, and some hosts don’t allow certain filetypes. If your host allows these filetypes, you can use the following function in a plugin or a child theme: function wpse_file_uploads($mime_types){ // photoshop $mime_types[‘psd’] = ‘image/vnd.adobe.photoshop’; // illustrator $mime_types[‘ai’] = ‘application/postscript’; // indesign $mime_types[‘indd’] … Read more

how to use media library [closed]

Take a look at wp_enqueue_media funciton. It enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs. Then you can execute wp.media function: var button = document.querySelector(‘.button’); button.addEventListener(‘click’, function(e) { e.preventDefault(); var frame = wp.media({ title: ‘Frame title’, multiple: false }); frame.on(‘select’, function () { var attachment = frame.state().get(‘selection’).first().toJSON(); alert(attachment.url); }); … Read more

How can I allow upload of ttf or otf font files when hooking `upload_mimes` doesn’t work

This is an imperfect solution which forces the way WordPress detects TTF files to use the file extension and then hooks upload_mimes for exactly our specified MIME type. Part of this answer taken from https://diviengine.com/how-to-fix-sorry-this-file-type-is-not-permitted-for-security-reasons/ First massage the way WordPress detects/reports TTF file types: function divi_engine_font_correct_filetypes( $data, $file, $filename, $mimes, $real_mime ) { if ( … Read more

How to remove some media upload icons from post editor?

If you want to get rid all all media buttons, you can remove the media_buttons action: add_action(‘admin_init’, ‘remove_all_media_buttons’); function remove_all_media_buttons() { remove_all_actions(‘media_buttons’); } Since you only want to remove some buttons, I suggest adding an admin stylesheet: add_action(‘admin_init’, ‘my_admin_stylesheet’); function my_admin_stylesheet() { wp_enqueue_style(‘my_admin’, get_bloginfo(‘template_url’).’/css/my_admin.css’); } In the my_admin.css you can hide the buttons: /* Hide … 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

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