Wordpress media-uploader save to a specific location - wordpress

I'm trying to implement a plugin allowing to download an image and save it to a specific location (relative to my plugin path - ie plugins/my_plugin/img) rather than in the default WP location.
I'd like to use the media uploader - but I've not found any way to define/change where media are uploaded.
Is it possible to customize the download path? and if yes, how can it be done?
Thank you.

You can define the upload folder via the Settings --> Media or adding the following line in the wp-config.php:
define( 'UPLOADS', 'wp-content/'.'files' );

Related

How to Upload webp Image in Wordpress?

Google Webpage speed Give guide lines upload Image in webp format. Then Increase page speed.
In Wordpress CMS not accept webp file.
Hi do you ONLY need to upload the .webp images to wordpress? NOT display them?
if you just wanna upload the images, then go to wp-config.php and add one line to it:
define('ALLOW_UNFILTERED_UPLOADS', true);
then you can go to media library and upload the images,
however if you want to also display these images, here are some tools([useful article link][2]) that you may need to use, such as : cache enabler,
if any further questions please leave a comment. :)
Put this code at the end of the config.php file. Your problem will be solved
//** *Enable upload for webp image files.*/
function webp_upload_mimes($existing_mimes) {
$existing_mimes['webp'] = 'image/webp';
return $existing_mimes;
}
add_filter('mime_types', 'webp_upload_mimes');

What is the way to upload bulk images in wordpress?

I have more than 500 images and I want to upload in WordPress media, I tried through FTP, WordPress changed images in different dimensions, and when I installed plugin "ADD TO SERVER " it uploads all the files.
I just want to add original images in the WordPress dashboard. Is there any way to upload bulk files in the WordPress media?
You can do it through FTP but go to settings before and change to import ORIGINAL size instead change dimensions.
You can find it under SETTINGS --> Media.
I have use 1024/1024 as max to avoid overload the server. You can change it on 2K(2048) or 4K(4096).
You can use the intermediate_image_sizes_advanced hook to prevent WordPress from getting the list of image sizes it normally uses.
The following code will feed an empty array to WordPress instead of the registered list of image sizes:
add_filter( 'intermediate_image_sizes_advanced', function(){
return [];
}, 10, 2 );
Running the Add to server plugin again after adding that code to your functions.php should not resize your uploaded images.

Wordpress: Serve images from a CDN

I use a CDN to serve my images, which I upload into Wordpress. My settings were:
It worked perfectly but it doesn't work anymore since I updated to Wordpress 4.5. This are my settings now:
This filter doesn't work either:
function my_cdn_upload_url() {
return 'http://media.mydomain.com';
}
add_filter( 'pre_option_upload_url_path', 'my_cdn_upload_url' );
Does anyone know how should I serve my images from a CDN?
Thank you.
Looks like you upgraded from quite an old WP version, didn't you? Uploads folder and path options were removed in Settings -> Media a long time ago.
So what does your real path for uploads look like? It's not a standard domain.com/wp-content/uploads// correct?
If yes - where do new images get uploaded to after the upgrade?
Try playing around with https://wordpress.org/plugins/custom-upload-dir/ and see if it helps get your images back to CDN.
The easiest way is editing the content of "upload_url_path" in the wp_options table:
upload_url_path > http://media.mydomain.com
Thank you!
The problem with the approaches above are you won't have file write permissions to upload images to your CDN.
Another approach is to upload all of your images to somewhere - e.g. Amazon S3, or keep them on affiliate network CDNs - and then store your image URLs in postmeta for your posts or products.
You then need to alter your theme files to pull the images from the postmeta fields instead of from the featured image or thumbnail fields.
FYI - this approach will massively speed up imports since WordPress will create multiple sizes of images using up CPU and disk space.
I created a plugin to solve this:
https://www.wpintense.com/product/external-images/
There is a hidden admin page where you can find all the options:
http://localhost/wp-admin/options.php
Find the upload_url_path option and set a value.
Note:
After you give it value, then the "Store uploads in this folder" which is the upload_path, and "Full URL path to files" which is the upload_url_path options will also appear on the Media Settings page:
http://localhost/wp-admin/options-media.php
The options only appear on the Media Settings page if a value is already set. This is the code in WordPress Core that defines how it works:
/*
* If upload_url_path is not the default (empty),
* or upload_path is not the default ('wp-content/uploads' or empty),
* they can be edited, otherwise they're locked.
*/
if ( get_option( 'upload_url_path' ) || get_option( 'upload_path' ) && 'wp-content/uploads' !== get_option( 'upload_path' ) ) :
BEST WAY is to use w3 total cache.
It has a built in cdn support and of course you can use it's main functionality , caching , most useful to speedup website.

WordPress Media Manager

Is it possible to include an images folder that is then accessible via the admin section. I am creating a theme and want some background images available for the user, since I can not include them in the uploads folder is there another way?
Include your backgrounds into the images folder of your theme.
Create an options page that lets the user select a background and return the URL of the image.
<?php echo get_template_directory_uri().'/images/backgrounds/BACKGROUNDFILENAME.jpg'; ?>
You could try to in your functions.php create or register new "Attatchment" based posts using the URLS of your theme images or try using this...
https://wordpress.org/plugins/media-library-plus/

How can I edit inner files with /wp-admin/theme-editor.php

How can I edit inner files (/js/ or /css/) with /wp-admin/theme-editor.php in Wordpress?
You need to set file permission for the theme so they can be edited.
From http://codex.wordpress.org/Editing_Files
To edit a file using the built-in WordPress Plugin or Theme Editors,
the permissions for that file must be set to writable (at least 666).
You will also need to change the get_files code in theme-editor.php

Resources