Skip to content

Instantly share code, notes, and snippets.

View pagelab's full-sized avatar
🚀

Márcio Duarte pagelab

🚀
View GitHub Profile
@pagelab
pagelab / functions.php
Last active March 28, 2024 19:21
Add clickable anchor icons with links in all core/paragraph blocks.
<?php
namespace MyPlugin;
add_filter( 'render_block_core/heading', __NAMESPACE__ . '\\add_anchor_icon', 10, 2 );
/**
* Add clickable anchor icons to all core/paragragh blocks.
*
* @param string $block_content The block content about to be appended.
@pagelab
pagelab / convert-css-variables-to-json.py
Last active February 6, 2024 15:21
Script to convert a list of CSS custom properties to the JSON format required by Advanced Themer to make them appear on the Bricks Builder fields (via the “V” symbol).
# Script to convert a list of CSS custom properties to the JSON format required by Advanced Themer to make them appear on the Bricks Builder fields (via the “V” symbol).
# 1. Add a file in a folder with all CSS variables from Core Framework called core-framework-css-variables.css, one per line. Group each section using CSS comments.
# 2. Run the python script to generate the JSON file for Advanced Themer: python3 convert-css-variables-to-json.py
# 3. Add the file to the “Import Framework” option of the Advanced Themer on Bricks → AT - Theme settints → Global CSS Variables → Import Framework.
import re
import json
# Read the CSS file
with open('core-framework-css-variables.css', 'r') as f:
css = f.readlines()
@pagelab
pagelab / bricks-mobile-dropdow-open-nav-element.html
Last active January 25, 2024 16:21
Bricks Builder: invert the default behaviour of the dropdown inside the Nav element (opened when the menu is clicked).
/* Nav element: change based on the breakpoint for the mobile menu. */
/* Note: change the `max-width` value to reflect the Nav element's breakpoint */
@media ( max-width: 768px ) {
.display-sub-menu {
display: block !important;
}
}
<script>
/**
@pagelab
pagelab / bricks-mobile-dropdow-open-nav-nestable.html
Last active January 25, 2024 16:18
Bricks Builder: invert the default behaviour of the dropdown inside the Nav (nestable) element.
<script>
/**
* Nav (nestable) element.
* Invert the default behaviour of the dropdown inside the element.
* Toggles the submenu with two CSS classes (.show-sub-menu and .hide-sub-menu).
*/
// Utility function to add or remove classes from an element.
function toggleClass(element, className) {
if (element.classList.contains(className)) {
@pagelab
pagelab / wp_remote_get_with_cache.php
Created October 19, 2021 00:50 — forked from msaari/wp_remote_get_with_cache.php
wp_remote_get_with_cache – Fetches remote data with dual-layer caching
<?php
/**
* Fetches remote data with dual-layer caching.
*
* Uses wp_remote_get to fetch remote data. The data is cached twice: it's
* stored in a transient and an option. The transient is used as the main cache
* but if the transient has expired and the remote site doesn't respond,
* backup data from the option is returned.
*
@pagelab
pagelab / auto-block-recovery.js
Created June 7, 2023 16:26 — forked from bfintal/auto-block-recovery.js
Encountering lots of broken blocks / block errors in WordPress Gutenberg? Paste this code in your browser developer console while editing your post to recover all the blocks at once.
var recursivelyRecoverInvalidBlockList = blocks => {
const _blocks = [ ...blocks ]
let recoveryCalled = false
const recursivelyRecoverBlocks = willRecoverBlocks => {
willRecoverBlocks.forEach( _block => {
if ( isInvalid( _block ) ) {
recoveryCalled = true
const newBlock = recoverBlock( _block )
for ( const key in newBlock ) {
_block[ key ] = newBlock[ key ]
@pagelab
pagelab / dicas.html
Created February 21, 2023 00:13
Caixa de dicas para o tema Épico utilizando o editor de blocos do WordPress
<!-- wp:group {"style":{"color":{"background":"#ffae0017"},"spacing":{"padding":{"top":"0","right":"0","bottom":"0","left":"0"}},"border":{"left":{"color":"#fcb90033","width":"8px"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group has-background" style="border-left-color:#fcb90033;border-left-width:8px;background-color:#ffae0017;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0">
<!-- wp:columns {"isStackedOnMobile":false,"style":{"spacing":{"padding":{"top":"0px","right":"0px","bottom":"0px","left":"0px"},"blockGap":{"top":"0px","left":"0px"},"margin":{"top":"0px","bottom":"0px"}}}} -->
<div class="wp-block-columns is-not-stacked-on-mobile" style="margin-top:0px;margin-bottom:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
<!-- wp:column {"width":"40px","layout":{"type":"default"}} -->
<div class="wp-block-column" style="flex-basis:40px">
<!-- wp:image {"sizeSlug":"large","linkDestination":"none","className":"is-styl
@pagelab
pagelab / html2docx.bat
Created February 17, 2020 19:39 — forked from arthurattwell/html2docx.bat
Batch file to convert HTML files to Word docx with Pandoc
:: This batch file converts HTML files in a folder to docx.
:: It requires Pandoc, and a list of files to convert
:: named file-list, in which each file is on a separate line,
:: and contains no spaces in the filename.
::
:: Don't show these commands to the user
@ECHO off
:: Set the title of the window
TITLE Convert html to docx
:: This thing that's necessary.
@pagelab
pagelab / wp-mailhog.php
Created August 5, 2019 01:29 — forked from bishless/wp-mailhog.php
Configure WordPress on Valet to use MailHog
<?php
/**
* @link
* @since 1.0.0
* @package TODO
*
* @wordpress-plugin
* Plugin Name: Use MailHog
* Description: Configure WordPress on Valet to use MailHog
* Version: 1.0.0
@pagelab
pagelab / functions.php
Last active August 20, 2022 04:10
Adding a class to external links in content blocks.
<?php
namespace MyPlugin;
// Adds a class to external links in content blocks.
add_filter( 'render_block', __NAMESPACE__ . '\\add_class_external_links', 10, 2 );
/**
* Adds a CSS class to external links in content blocks.
*