Skip to content

Instantly share code, notes, and snippets.

View gioiliop7's full-sized avatar
:octocat:
Hello

Giorgos Iliopoulos gioiliop7

:octocat:
Hello
View GitHub Profile
@gioiliop7
gioiliop7 / .htaccess
Created January 5, 2023 15:47
[WORDPRESS] [PHP] Allow file download only from admins and their authors
# Protect all files within the uploads folder
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteCond %{HTTP_COOKIE} !.*wordpress_logged_in.*$ [NC]
#RewriteCond %{REQUEST_URI} ^(.*?/?)wp-content/uploads/sites/[0-9]+/user_uploads|answers/.* [NC]
#RewriteRule . http://%{HTTP_HOST}%1/wp-login.php?redirect_to=%{REQUEST_URI} [L,QSA]
RewriteCond %{REQUEST_FILENAME} -f
# RewriteRule needs the path of folder that we have our files. As an example the folder is on uploads folder on wp and named cv_uploads
RewriteRule "^wp-content/uploads/cv_uploads/(.*)$" singledl-file.php?file=$1 [QSA,L]
</IfModule>
@gioiliop7
gioiliop7 / api.js
Created January 5, 2023 15:42
Fetch api call [JS]
export async function apiCall(body, method, url) {
let headers = new Headers();
headers.append("Content-Type", "application/json");
const requestOptions = {
method: method,
headers: headers,
body: JSON.stringify(body),
redirect: "follow",
};
try {