Skip to content

Instantly share code, notes, and snippets.

View VelichkoAlexander's full-sized avatar
🪐
Exploring

Alexander Velichko VelichkoAlexander

🪐
Exploring
  • Ukraine
View GitHub Profile
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 / 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',
<?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 / 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(),
}
}, [] );
//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 / 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 {