Skip to content

Instantly share code, notes, and snippets.

View odil-io's full-sized avatar
🪐

Odilio Witteveen odil-io

🪐
View GitHub Profile
@odil-io
odil-io / index.js
Created October 20, 2022 12:53
Debugging: Log all Events
function _isEvent(prop) {
if (0 !== prop.indexOf('on')) {
return false;
}
return true;
}
function _getEvents(obj, hasOwnProperty = true) {
const result = [];
@odil-io
odil-io / functions.php
Last active October 12, 2022 13:41
Gutenberg: Prefix The Content with specified Blocks.
<?php
/**
* Prefix the content of Post Type Page with a set of Blocks.
* @see https://wordpress.stackexchange.com/a/323469/218062
*/
function prefix_the_content_with_blocks( $args, $post_type ) {
if ( 'page' === $post_type ) {
$args['template'] = array(
array(
@odil-io
odil-io / functions.php
Created August 2, 2022 07:27
ACF: Populate select-field with Taxonomy names
<?php
/**
* List Taxonomies connected to Post Type in a Select Field type
*
* @param Array $field Field settings.
* @return void
*/
function namespace_get_taxonomy_list( $field ) {
$field['choices'] = array();
@odil-io
odil-io / remove_lazy_load_attr.php
Last active June 24, 2022 07:54
WP: Filter Content
<?php
function remove_lazy_load_attr( $content ) {
// Condition
if ( is_front_page() ) {
// Objectify DOM
$content = mb_convert_encoding( $content, 'HTML-ENTITIES', 'UTF-8' );
$document = new DOMDocument();
### Keybase proof
I hereby claim:
* I am odil-io on github.
* I am odilio (https://keybase.io/odilio) on keybase.
* I have a public key ASCaD7d8M7g2xC5XehCqYz8MrNw6tthUeHbK9rn8kDffNgo
To claim this, I am signing this object:
@odil-io
odil-io / functions.php
Created May 2, 2022 22:26
WP: get sub menu item from specific menu location.
<?php
$items = wp_get_nav_menu_items( 'top' );
if ( $items ) {
echo '<ul class="menu">';
foreach ( $items as $index => $item ) {
if ( ! empty( $item->menu_item_parent ) ) {
echo '<li class="menu-item' . implode( ' ', $item->classes ) . '">';
@odil-io
odil-io / functions.php
Last active August 2, 2022 07:45
PHP: determine legibility on different colors
<?php
$hex = "#A0DAA9"; // accepts abc, aabbcc, #abc and #aabbcc.
// Split HEX value into Red Green and Blue values
list( $r, $g, $b ) = array_map(
function ( $c ) {
return hexdec( str_pad( $c, 2, $c ) );
},
str_split(
@odil-io
odil-io / functions.php
Last active August 2, 2022 07:42
WordPress: Add support to `get_terms()` to limit results to Terms used by Post Type.
<?php
/**
* Terms_clauses
*
* Filter the terms clauses.
*
* @param $clauses array
* @param $taxonomy string
* @param $args array
* @return array
@odil-io
odil-io / composer-show.md
Last active February 7, 2022 10:11
Symfony v4.4.5 isAbsolutePath() complete error message
composer/xdebug-handler             1.4.1   Restarts a process without Xdebug.
pdepend/pdepend                     2.7.1   Official version of pdepend to be handled with Composer
phpcompatibility/php-compatibility  9.3.5   A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.
phpmd/phpmd                         2.8.2   PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known...
psr/container                       1.0.0   Common Container Interface (PHP FIG PSR-11)
psr/log                             1.1.3   Common interface for logging libraries
squizlabs/php_codesniffer           3.5.4   PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined...
symfony/config                      v4.4.5  Symfony Config Component
symfony/dependency-injection        v4.4.5  Symfony DependencyInjection Component
@odil-io
odil-io / functions.php
Created August 19, 2021 09:21
Gutenberg: Add custom font sizes
<?php
function namespace_define_font_sizes() {
add_theme_support(
'editor-font-sizes',
[
[
'name' => __( 'Small', 'namespace' ),
'size' => 16,
'slug' => 'namespace-small',