Skip to content

Instantly share code, notes, and snippets.

View widoz's full-sized avatar
🍜
Ramen and Code

Guido Scialfa widoz

🍜
Ramen and Code
View GitHub Profile
@widoz
widoz / ImmutableRecord.ts
Created April 20, 2026 21:27
Immutable Map Wrapper
export class ImmutableRecord< T > {
readonly #map: Readonly< Record< string, T > >;
public constructor( map: Readonly< Record< string, T > > = {} ) {
this.#map = map;
}
public get< F >( key: string, fallback?: F ): T | F | undefined {
return this.#map[ key ] ?? fallback;
}
@widoz
widoz / Units Conversion.scss
Last active April 19, 2026 15:16
Convert Px to Em and Rem relative units
@use "sass:math";
$browser-context: 16;
/*
* Convert pixels to ems.
*/
@function em($pixels, $context: $browser-context) {
@if (math.is-unitless($pixels)) {
<?php
/**
* Add an action that will be executed when a specific module is imported via importmap.
*
* WordPress does not allow modules to depend on scripts. As such, we investigate the `importmap`
* for the presence of a module and execute an action when it is found.
* The action shall take care of registering / enqueueing the appropriate scripts.
*/
function add_action_on_module_import(string $moduleName, callable $action): void
{
@widoz
widoz / Animate Border Bottom on Hover Loop.scss
Last active April 17, 2026 22:07
Render the underline border with loop animation on hover
/*
* Usage
*
* ```
* a {
* @include mixins.animate-border-bottom-on-hover-loop();
* }
* ```
*/
@mixin animate-border-bottom-on-hover-loop() {
<?php
\add_filter('block_editor_settings_all', static function (array $settings): array {
$currentUserRoles = \wp_get_current_user()->roles;
$allowedUserRoles = ['editor', 'administrator'];
$isUserAllowed = (bool)\array_intersect($currentUserRoles, $allowedUserRoles);
if (!$isUserAllowed) {
$settings['canLockBlocks'] = false;
}
@widoz
widoz / Admin Notification.php
Last active April 17, 2026 22:06
Helper function to show a WordPress admin notice
<?php
function notify(string $message, string $noticeType, array $allowedMarkup = []): void
{
$callback = function () use ($message, $noticeType, $allowedMarkup) {
?>
<div class="notice notice-<?= \sanitize_html_class($noticeType) ?>">
<p><?= \wp_kses($message, $allowedMarkup) ?></p>
</div>
<?php
};
<?php
function array_insert_into_position(
$needle,
array &$haystack,
$pos,
$preserve = false,
$recursive = false
): array {
$keys = array_filter(
@widoz
widoz / Reorder List.php
Last active April 17, 2026 22:06
Form Functions
<?php
/**
* Re Order Files
*
* @access private
*
* @param array $list An array $_FILES like to re-order
*
* @return array The re-order array list
*/
@widoz
widoz / Wp Post by Name.php
Last active April 17, 2026 22:10
Wp Post by Name
<?php
/**
* Get post by name
*
* @since 2.0.0
*
* @param string $name The name ( slug ) of the post to retrieve.
* @param string $post_type The post type. Optional. Default to 'post'.
*
* @return WP_Post The post object
@widoz
widoz / WP Screen Reader Text.scss
Last active April 17, 2026 22:06
Wp Screen Reader Text Less Mixin
@mixin screen-reader-text {
& {
clip : rect(1px, 1px, 1px, 1px);
position : absolute !important;
height : 1px;
width : 1px;
overflow : hidden;
&:focus {
background-color : #F1F1F1;