Skip to content

Instantly share code, notes, and snippets.

View andrii-kvlnko's full-sized avatar

Andrii Kovalenko andrii-kvlnko

View GitHub Profile
@andrii-kvlnko
andrii-kvlnko / gist:3718a4f20762640457ae28a6d47d5341
Created June 21, 2022 20:08 — forked from ZER0/gist:5267608
Find all the CSS rules applied to a specific element; and check if a CSS property for a specific element is defined in the stylesheet – not inline style. Notice that is not like `getComputedStyle`, that returns the calculated properties for a specific element.
var proto = Element.prototype;
var slice = Function.call.bind(Array.prototype.slice);
var matches = Function.call.bind(proto.matchesSelector ||
proto.mozMatchesSelector || proto.webkitMatchesSelector ||
proto.msMatchesSelector || proto.oMatchesSelector);
// Returns true if a DOM Element matches a cssRule
var elementMatchCSSRule = function(element, cssRule) {
return matches(element, cssRule.selectorText);
};
@andrii-kvlnko
andrii-kvlnko / nginx-wordpress.conf
Created June 18, 2022 18:00 — forked from nfsarmento/nginx-wordpress.conf
Harden wordpress security nginx
############ WordPress ####################
# Disable logging for favicon and robots.txt
location = /favicon.ico {
try_files /favicon.ico @empty;
access_log off;
log_not_found off;
expires max;
}
@andrii-kvlnko
andrii-kvlnko / functions.php
Created March 13, 2022 02:33
Show registered styles list | Wordpress
global $wp_styles;
$styles = ( new Arrayy( $wp_styles->registered ) )
->map( function ( $style ) {
return [
'src' => $style->src,
'handle' => $style->handle,
];
} )
->toArray();
@andrii-kvlnko
andrii-kvlnko / functions.php
Created March 4, 2022 20:07
Create terms translations WPML
add_action( 'wp', function () {
if ( ! isset( $_GET['test-add-product-categories-fr'] ) ) {
return;
}
$categories = [
'Climatiseur' => [
'args' => [
'parent' => 0,
],
@andrii-kvlnko
andrii-kvlnko / install.sh
Created September 28, 2021 06:44
Install certbot nginx
sudo apt update
sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-nginx
sudo certbot --nginx -d example.com
sudo certbot renew --dry-run
@andrii-kvlnko
andrii-kvlnko / index.php
Last active June 21, 2023 21:17
WordPress | Add script/style | uploads dir
add_action( 'wp_enqueue_scripts', function() {
$wp_upload_dir = wp_upload_dir();
$base_url = $wp_upload_dir['baseurl'];
$base_dir = $wp_upload_dir['basedir'];
wp_enqueue_style(
'howlife-style',
sprintf( '%s/example/css/main.css', $base_url ),
[],
filemtime( sprintf( '%s/howlife/css/main.css', $base_dir ) )
@andrii-kvlnko
andrii-kvlnko / index.php
Created September 15, 2021 14:07
WordPress | Polylang | Set languages to all posts
add_action( 'wp', function () {
$posts = get_posts(
[
'post_type' => 'post',
'lang' => '',
'paged' => 1,
'posts_per_page' => - 1,
]
);
@andrii-kvlnko
andrii-kvlnko / index.php
Last active June 21, 2023 21:18
Enqueue scripts and styles from upload directory
add_action( 'wp_enqueue_scripts', function() {
$wp_upload_dir = wp_upload_dir();
$base_url = $wp_upload_dir['baseurl'];
$base_dir = $wp_upload_dir['basedir'];
wp_enqueue_style(
'howlife-style',
sprintf( '%s/example/css/main.css', $base_url ),
[],
filemtime( sprintf( '%s/example/css/main.css', $base_dir ) )
@andrii-kvlnko
andrii-kvlnko / resize.js
Created August 15, 2021 11:50 — forked from vishalsrini/resize.js
A simple JavaScript to resize an image and create a blob out of it
window.resize = (function () {
'use strict';
function Resize() {}
Resize.prototype = {
init: function(outputQuality) {
this.outputQuality = (outputQuality === 'undefined' ? 0.8 : outputQuality);
},
@andrii-kvlnko
andrii-kvlnko / plugin-template-part.php
Created August 2, 2021 23:01
Load plugin template part | WordPress
$plugin_path = plugin_dir_path( __DIR__ );
$template_path = sprintf( '%stemplate-parts/header/navbar-primary.php', $plugin_path );
include $template_path;