Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrii Kovalenko andrii-kvlnko

View GitHub Profile
@andrii-kvlnko
andrii-kvlnko / gist:3718a4f20762640457ae28a6d47d5341
Created Jun 21, 2022 — 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.
View gist:3718a4f20762640457ae28a6d47d5341
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 Jun 18, 2022 — forked from nfsarmento/nginx-wordpress.conf
Harden wordpress security nginx
View nginx-wordpress.conf
############ 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 Mar 13, 2022
Show registered styles list | Wordpress
View functions.php
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 Mar 4, 2022
Create terms translations WPML
View functions.php
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 Sep 28, 2021
Install certbot nginx
View install.sh
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
Created Sep 17, 2021
WordPress | Add script/style | uploads dir
View index.php
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/howlife/css/main.css', $base_url ),
[],
filemtime( sprintf( '%s/howlife/css/main.css', $base_dir ) )
@andrii-kvlnko
andrii-kvlnko / index.php
Created Sep 15, 2021
WordPress | Polylang | Set languages to all posts
View index.php
add_action( 'wp', function () {
$posts = get_posts(
[
'post_type' => 'post',
'lang' => '',
'paged' => 1,
'posts_per_page' => - 1,
]
);
@andrii-kvlnko
andrii-kvlnko / index.php
Created Sep 2, 2021
Enqueue scripts and styles from upload directory
View index.php
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/howlife/css/main.css', $base_url ),
[],
filemtime( sprintf( '%s/howlife/css/main.css', $base_dir ) )
@andrii-kvlnko
andrii-kvlnko / resize.js
Created Aug 15, 2021 — forked from vishalsrini/resize.js
A simple JavaScript to resize an image and create a blob out of it
View resize.js
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 Aug 2, 2021
Load plugin template part | WordPress
View plugin-template-part.php
$plugin_path = plugin_dir_path( __DIR__ );
$template_path = sprintf( '%stemplate-parts/header/navbar-primary.php', $plugin_path );
include $template_path;