Skip to content

Instantly share code, notes, and snippets.

View waylay's full-sized avatar
🏠
Working from home

Cristian Ionel waylay

🏠
Working from home
  • WCD
  • Brno, Czech Republic
  • X @waylay
View GitHub Profile
@waylay
waylay / .htaccess
Created October 29, 2020 16:20
Make a site fast using .htaccess
<ifmodule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
@waylay
waylay / find.sh
Last active June 18, 2020 11:25
Find files modified in the last 24h
find . -type f -mtime 0 ! -path '*/cache/*' ! -path '*/vendor/*' ! -path '*/uploads/*' ! -path '*/log/*'
@waylay
waylay / functions.php
Last active September 1, 2019 13:21
Add Login/Username/Logout(as submenu) to main navigation
function add_login_logout_to_menu( $items, $args ) {
if ( $args->theme_location != 'primary' ) {
return $items;
}
if ( !is_user_logged_in() ) {
$items .= '<li><a href="'.wp_login_url().'" title="Login">Login</a></li>';
} else {
$current_user = wp_get_current_user();
$items .= '<li class="menu-item-has-children"><a href="#">'. $current_user->display_name .'</a><ul class="sub-menu">';
@waylay
waylay / login.php
Created August 29, 2019 09:06
WordPress PHP login
<?php
if($_SERVER['REMOTE_ADDR'] == 'x.x.x.x') {
$user_id = 1;
$user = get_user_by( 'id', $user_id );
if( $user && !is_user_logged_in()) {
wp_set_current_user( $user_id, $user->user_login );
wp_set_auth_cookie( $user_id );
do_action( 'wp_login', $user->user_login, $user );
}
}
@waylay
waylay / .htaccess
Created August 22, 2018 15:42
.htaccess HTTPS redirect
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@waylay
waylay / magento_attachments.php
Created September 25, 2017 21:22
Map Magento attachment file to WooCommerce product file
<?php
//SQL
$mydb = new wpdb('root','root','magento','localhost');
$rows = $mydb->get_results("
select p.entity_id, p.sku, f.title, f.uploaded_file
from pml_uni_fileuploader f
inner join pml_catalog_product_entity p
on find_in_set(p.entity_id, f.product_ids)
order by p.entity_id
@waylay
waylay / replace_shortcode_with_output.php
Created July 4, 2017 12:03
Replace shortcode with its output in all posts
function get_replaced_sourcecode_sc( $post ) {
if ( empty($post) ) global $post;
if ( empty($post) || ! isset($post->post_content) ) return false;
$content = $post->post_content;
if (
preg_match_all( '/'. get_shortcode_regex() .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches ) && in_array( 'purehtml', $matches[2] )
) {
foreach ( $matches[2] as $i => $sc ) {
if ( $sc == 'purehtml' )
@waylay
waylay / new-user-db.sql
Created February 15, 2017 14:46
MySQL create new db/user
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE newdatabase;
GRANT ALL PRIVILEGES ON newdatabase.* TO 'newuser'@'localhost';
@waylay
waylay / add-domain.txt
Last active February 15, 2017 15:04
Add new domain or subdomain on DO
1. Networking / Add Domain or Create new A record for subdomain;
2. cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
3. vi /etc/apache2/sites-available/example.com.conf
-----------
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/example.com
ServerName example.com
// assets/scripts/customizer.js
(function($) {
// Primary colour
wp.customize('primary_colour', function(value) {
value.bind(function(to) {
$('head').append('<style>.Primary-bg-c{background-color:'+ to +' !important;}</style>');
$('head').append('<style>.Primary-c{color:'+ to +' !important;}</style>');
$('head').append('<style>.Primary-c--hover:hover{color:'+ to +' !important;}</style>');