Skip to content

Instantly share code, notes, and snippets.

View VelichkoAlexander's full-sized avatar
🪐
Exploring

Alexander Velichko VelichkoAlexander

🪐
Exploring
  • Ukraine
View GitHub Profile
@VelichkoAlexander
VelichkoAlexander / reduced-motion.js
Created April 24, 2024 12:49
How we can catch `prefers-reduced-motion` by js
const MEDIA_QUERY = '(prefers-reduced-motion: reduce)';
const CSS_PROPERTY = '--reduced-motion-play-state';
const documentRoot = document.documentElement;
const handleMediaChange = (event) => {
if (event.matches) {
documentRoot.style.setProperty(CSS_PROPERTY, 'paused');
} else {
//To fetch the list of all registered blocks in the JS, we can do something like this:
wp.blocks.getBlockTypes()
//Also, to get a list of blocks for a particular namespace, you may use something like this:
wp.blocks.getBlockTypes().filter((block) => { return block.name.indexOf(NAMESPACE) !== -1});
@VelichkoAlexander
VelichkoAlexander / edit.tsx
Last active March 19, 2025 02:21
How to work with preview state for Gutenberg
import {useSelect, useDispatch} from '@wordpress/data'
//Access the current mode value
const { deviceType } = useSelect( select => {
const { __experimentalGetPreviewDeviceType } = select( 'core/edit-post' );
return {
deviceType: __experimentalGetPreviewDeviceType(),
}
}, [] );
<?php
add_action('save_post', function($id, $post, $update): void {
// Skip if wp rocket is not activated.
if (! function_exists('rocket_clean_domain')) {
return;
}
if (! $update) {
return;
@VelichkoAlexander
VelichkoAlexander / function.php
Last active April 26, 2020 09:12
Create custom post type
add_action( 'init', 'true_register_post_type_init' );
function true_register_post_type_init() {
$labels = [
'name' => 'Functions',
'singular_name' => 'Function', // admin panel Add-> Function
'add_new' => 'Add function',
'add_new_item' => 'Add New function', // <title> tag title
'edit_item' => 'Edit function',
'new_item' => 'New feature',
composer require filp/whoops
composer require symfony/var-dumper
function registerWhoops() {
$whoops = new \Whoops\Run;
$whoops->pushHandler( new \Whoops\Handler\PrettyPageHandler );
$whoops->register();
}
if ( WP_DEBUG ) {
@VelichkoAlexander
VelichkoAlexander / slick-on-mobile.js
Created July 16, 2019 14:09 — forked from ndunk28/slick-on-mobile.js
slick js only on mobile
// slider
$slick_slider = $('.slider');
settings_slider = {
dots: false,
arrows: false
// more settings
}
slick_on_mobile( $slick_slider, settings_slider);
// slick on mobile
@VelichkoAlexander
VelichkoAlexander / sldier.scss
Created July 16, 2019 08:30
Transition for showing slick slider
.slider {
opacity: 0;
visibility: hidden;
transition: opacity 1s ease;
&.slick-initialized {
visibility: visible;
opacity: 1;
}
@VelichkoAlexander
VelichkoAlexander / wp.php
Created May 30, 2019 06:57
Passing a variable to get_template_part
include( locate_template( '/template-parts/case-slider.php', false, false ) );
@VelichkoAlexander
VelichkoAlexander / registration.php
Created August 18, 2018 09:25
Custom registration
<?php
$err = '';
$success = '';
global $wpdb, $PasswordHash, $current_user, $user_ID;
if (isset($_POST['task']) && $_POST['task'] == 'register') {
$first_name = $wpdb->escape(trim($_POST['first_name']));
$last_name = $wpdb->escape(trim($_POST['last_name']));
$email = $wpdb->escape(trim($_POST['email']));