Skip to content

Instantly share code, notes, and snippets.

View vralle's full-sized avatar

Vitaliy Ralle vralle

View GitHub Profile
@vralle
vralle / dynamic-sizes.php
Last active June 29, 2022 15:04
Dynamic SVG sizes for safe-svg WP plugin
<?php
add_action('init', removeSafeSvgOnePixelFix');
function removeSafeSvgOnePixelFix()
{
global $wp_filter;
if (! class_exists('safe_svg')) {
return;
}
@vralle
vralle / README.md
Last active July 30, 2022 10:39
jQuery offcanvas.js (based on Bootstrap Modal.js)

#offcanvas.js

##Usage

The offcanvas plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .offcanvas-open to the <body> to override default scrolling behavior and generates a .offcanvas-backdrop to provide a click area for dismissing shown offcanvas when clicking outside the offcanvas.

<!-- Button trigger offcanvas -->
<button class="btn btn-primary" data-toggle="offcanvas" data-target="#myOffcanvas" data-fade="false">
 Launch offcanvas
@vralle
vralle / admin.js
Last active September 22, 2022 19:57
Adding a Media Button to the WordPress Editor.
jQuery(function($) {
$(document).ready(function(){
$('#insert-my-media').click(open_media_window);
});
function open_media_window() {
if (this.window === undefined) {
this.window = wp.media({
title: 'Insert a media',
library: {type: 'image'},
@vralle
vralle / image-shortcake-admin.js
Last active September 22, 2022 19:59
Image-Shortcake: Fix 'media_send_to_editor' for WP Insert Media
function myTest() {
// Save default function
var defaultSend = wp.media.editor.send.attachment;
// new send function
wp.media.editor.send.attachment = function( props, attachment) {
// If not image, return default function
if ( 'image' !== attachment.type )
return defaultSend( props, attachment)
@vralle
vralle / gallery.php
Last active November 4, 2022 21:08
Custom Gallery Shortcode output
@vralle
vralle / Dockerfile
Last active November 13, 2022 09:03
Install xdebug 3 in Docker container
# https://matthewsetter.com/setup-step-debugging-php-xdebug3-docker/
# ENV XDEBUG_PORT 9000
# ENV XDEBUG_IDEKEY docker
RUN set eux; \
pecl install "xdebug"; \
docker-php-ext-enable xdebug; \
rm -r /tmp/pear; \
{ \
echo "xdebug.mode=debug"; \
@vralle
vralle / index.js
Created January 7, 2022 22:25
Use post meta in gutenberg
// https://make.wordpress.org/core/2020/03/02/general-block-editor-api-updates/
// https://github.com/WordPress/gutenberg/tree/trunk/packages/core-data
import {
PanelRow, TextControl,
} from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { useEntityProp } from '@wordpress/core-data';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { registerPlugin } from '@wordpress/plugins';
@vralle
vralle / PurgeCssMinimizer.js
Last active April 29, 2024 20:49
Webpack plugin using PurgeCSS for each html file separately
/* eslint-disable class-methods-use-this */
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-continue */
/**
* @typedef {import('webpack').WebpackPluginInstance} WebpackPluginInstance
* @typedef {import('webpack').Compiler} Compiler
* @typedef {import('webpack').Compilation} Compilation
* @typedef {import('webpack').Asset} Asset
* @typedef {Record<string, import('webpack').sources.Source>} CompilationAssets
* @typedef {Object} CssOutput