Skip to content

Instantly share code, notes, and snippets.

View w-jerome's full-sized avatar
💻
coding…

Jérôme Wohlschlegel w-jerome

💻
coding…
View GitHub Profile
@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' );
/**
@w-jerome
w-jerome / phpcs-and-wpcs.bash
Last active February 3, 2020 09:42
PHP Code Sniffer - Install "PHP Code Sniffer" and "WordPress Coding Standards" ("phpcs" and "wpcs")
# Step 1: Install PHP Code Sniffer (global)
composer global require squizlabs/php_codesniffer
# path: "/Users/MyUserName/.composer/vendor/squizlabs/php_codesniffer/bin"
# Step 2: Install WordPress Coding Standards (global)
# stock the git in user folder
cd ~
mkdir ~/terminal-tools
@w-jerome
w-jerome / .htaccess
Created November 7, 2019 10:02
Htaccess - Basic config
# Pass the default character set
AddDefaultCharset utf-8
# BEGIN Rewrite rules
RewriteEngine On
RewriteBase /
# Redirection www
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ https://www.site.com/$1 [R=301,L]
@w-jerome
w-jerome / replace.bash
Last active December 2, 2019 14:14
Terminal - Search and replace (sql url domaine replace)
# "www." to "local."
sed 's/www.mysite.fr/local.mysite.fr/g' mysql.sql > mysql-new.sql
# HTTPS to HTTP
sed 's/https:\/\/www.mysite.fr/http:\/\/www.mysite.fr/g' mysql.sql > mysql-new.sql
# If bug "sed: RE error: illegal byte sequence"
LC_CTYPE=C sed 's/www.mysite.fr/local.mysite.fr/g' mysql.sql > mysql-new.sql
@w-jerome
w-jerome / wordpress-blur-image.php
Created October 24, 2019 07:54
WordPress - Create blur image
<?php
class WPMediaBlur {
public function __construct() {
$this->add_media_sizes();
add_action( 'updated_post_meta', array( $this, 'post_updated' ), 10, 4 );
add_action( 'added_post_meta', array( $this, 'post_updated' ), 10, 4 );
}
public function add_media_sizes() {
@w-jerome
w-jerome / disable-comments.php
Created September 4, 2019 17:03
WordPress - Disable Comments
<?php
// Add to existing function.php file
// Disable support for comments and trackbacks in post types
function df_disable_comments_post_types_support() {
$post_types = get_post_types();
foreach ($post_types as $post_type) {
if(post_type_supports($post_type, 'comments')) {
remove_post_type_support($post_type, 'comments');
remove_post_type_support($post_type, 'trackbacks');
@w-jerome
w-jerome / app.js
Last active June 18, 2019 16:43
Javascript - Scroll Utils
var $output = document.querySelector('.js-output');
function debugRender(obj) {
$output.innerHTML = '';
$output.appendChild(document.createTextNode(JSON.stringify(obj, function(key, value) {
if (value === window || (value && typeof value.nodeName === 'string')) {
return '[DOM]';
}
return value;
}, 4)));
@w-jerome
w-jerome / js-scope.js
Last active February 3, 2020 09:48
Javascript - get variable scale
var APP = {
config: {
selector: '.app',
},
};
var app_selector = ((APP || {}).config || {}).selector || '';