mcguffin / the-paste

Paste Images in WordPress from many applications and upload them to the media library.
https://wordpress.org/plugins/the-paste/
GNU General Public License v3.0
40 stars 11 forks source link

Trying to activate filters unsccessfuly #43

Closed oferlaor closed 11 months ago

oferlaor commented 11 months ago

this doesn't seem to do the trick:

function the_paste_default_filename() {
    return "Pasted";
}
function the_paste_max_embed_image_size() {
    return 1;
}
add_action( 'the_paste_default_filename', 'the_paste_default_filename');
add_action( 'the_paste_max_embed_image_size', 'the_paste_max_embed_image_size');

Is there an example of how to use these two filters?

oferlaor commented 11 months ago

OK, got this to work:

function the_paste_default_filename() {
    return "Pasted<username>-%s";
}

The problem is that both my postname and username values are not in English, which is not a good idea for media. Is there a way to add and on top of the existing parameters?

mcguffin commented 11 months ago

Okay, "Default file name" might be a bit misleading, I admit. Primarily it is the attachment title. The actual filename is generated through sanitize_file_name().

After pasting and confirming the image dialog, the plugin is passing the file object to WordPress to handle the upload. It is exactly what happens when you drop a file from the OS from that point. WordPress only strips out characters that could interfer with the OS – like directory separators, quotes end so on – leaving the rest intact. (I tried this with a chinese filename.) Hooking into sanitize_file_name sounds like a better place to strip out or transform invalid characters.

oferlaor commented 11 months ago

It’s not actually important to fix sanitationJust want more options In the default naming. Namely:1. Post ID 2. Author ID3. Author username (instead of full name)Is it possible?Best regards,Ofer LaOrOn 25 Sep 2023, at 10:59, Jörn Lund @.***> wrote: Okay, "Default file name" might be a bit misleading, I admit. Primarily it is the attachment title. The actual filename is generated through sanitize_file_name(). After pasting and confirming the image dialog, the plugin is passing the file object to WordPress to handle the upload. It is exactly what happens when you drop a file from the OS from that point. WordPress only strips out characters that could interfer with the OS – like directory separators, quotes end so on – leaving the rest intact. (I tried this with a chinese filename.) Hooking into sanitize_file_name sounds like a better place to strip out or transform invalid characters.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>