Skip to content

Instantly share code, notes, and snippets.

@w-jerome
w-jerome / email-obfuscation.php
Created May 27, 2024 22:18
[PHP] Email Obfuscation (spam killer)
<?php
function emailObfuscation(string $email) {
return preg_replace_callback('/./', function($m) use ($email) {
return '&#' . ord($m[0]) . ';';
}, $email);
}
echo emailObfuscation('myemail@example.com');
@w-jerome
w-jerome / customer-by-group-and-country.sql
Created August 4, 2022 08:37
Prestashop — Export Customer with SQL
SELECT
c.id_customer,
c.firstname,
c.lastname,
c.email,
c.active,
c.newsletter,
c.optin,
c.date_add,
gl.name as social_title,
@w-jerome
w-jerome / directories.php
Created August 3, 2021 13:35
PHP - Get folders from path
<?php
$path = DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'folder';
$denies = array('..', '.');
$entries = array_diff(scandir($path), $denies);
foreach ($entries as $key => $file_or_folder) {
if (!is_dir($path . DIRECTORY_SEPARATOR . $file_or_folder)) {
unset($entries[$key]);
}
}
@w-jerome
w-jerome / html-module-js.html
Last active February 17, 2021 09:15
HTML/JS - Add javascript module in HTML
<script type="module">
// NOTE: You literally don't need a build process with preact.
import { h, Component, render } from 'https://unpkg.com/preact?module';
const app = h('h1', null, 'Hello World!');
render(app, document.body);
</script>
<script type="module">
// https://www.skypack.dev/
import confetti from 'https://cdn.skypack.dev/canvas-confetti';
@w-jerome
w-jerome / .htaccess
Created December 21, 2020 11:19
Apache - Https and www
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.my-site\.com$ [NC]
RewriteRule ^(.*)$ https://www.my-site.com/$1 [L,R=301]
@w-jerome
w-jerome / .bash
Created November 9, 2020 15:37
WordPress CLI - Change lang
# Installer d'autres langues via wpcli
wp language core install fr_FR
# Changer de langue
wp site switch-language fr_FR
@w-jerome
w-jerome / .htaccess
Last active September 29, 2020 08:42
WordPress - Redirect image upload from local to prod
RewriteEngine On
RewriteBase /
RewriteRule ^(wp-content/uploads/.*) https://www.my-web-site.com/$1 [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
@w-jerome
w-jerome / index.tpl
Last active January 20, 2020 09:39
Prestashop, Smarty - Translate string
{*
* Prestashop 1.6 Documentation
* http://doc.prestashop.com/display/PS16/Module+translation
* https://stackoverflow.com/questions/11340742/pass-a-variable-inside-translation-string-in-prestashop
*}
{* Translate Back-Office Key *}
{l s='This is translation' mod='my_module'}
{* Variables *}
@w-jerome
w-jerome / .htaccess
Created November 19, 2019 15:30
HTML - Boirplate maintenance
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule $ /maintenance.html [R=302,L]
@w-jerome
w-jerome / custom-menu-panel.php
Created November 19, 2019 14:52 — forked from nikolov-tmw/custom-menu-panel.php
This registers a custom meta box for nav menus and renders it. Obviously $my_items would ideally be not hard-coded and instead it would come somewhere from the DB. The custom items add to the menu and save properly, but will probably not be displayed correctly. You might need to hook to the 'wp_setup_nav_menu_item' filter in order to fix the men…
<?php
function my_register_menu_metabox() {
$custom_param = array( 0 => 'This param will be passed to my_render_menu_metabox' );
add_meta_box( 'my-menu-test-metabox', 'Test Menu Metabox', 'my_render_menu_metabox', 'nav-menus', 'side', 'default', $custom_param );
}
add_action( 'admin_head-nav-menus.php', 'my_register_menu_metabox' );
/**