Rewrite rule to load images from production does nothing

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] # If images not found on development site, load from production RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$ RewriteRule ^(.*)$ https://www.example.com/$1 [QSA,L] The problem here is that “If images not found on development site” then the request has already been rewritten to index.php by the preceding RewriteRule (WordPress front-controller), … Read more

Restrict Image Uploads to a Certain File Type

First off, PNGs do not necessarily slow your site down anymore than a JPG. It all depends on how the image is saved or optimized and the file size. Anyway. You have a couple options. Since this site is about coding and we don’t support 3rd party plugins I will give you this first. You … 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

How to get future ID for post which haven’t been created yet?

You are on the correct path on thinking about post-edit.php. http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/post-new.php#L45 See how get_default_post_to_edit is called to return a new post. The second argument tells it to create a post in the database. The function is defined here: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/post.php#L394 Note line 422: $post_id = wp_insert_post( array( ‘post_title’ => __( ‘Auto Draft’ ), ‘post_type’ => $post_type, … Read more