Skip to content

Instantly share code, notes, and snippets.

View estevan-ulian's full-sized avatar
🏠
Working from home

Estevan Ulian estevan-ulian

🏠
Working from home
View GitHub Profile
@estevan-ulian
estevan-ulian / x-current-domain-middleware.ts
Last active June 28, 2024 13:16
Creates middleware to pass the site's current domain via headers
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
import { CustomMiddleware } from "./chain";
export function xCurrentDomain(middleware: CustomMiddleware) {
return async (req: NextRequest, ev: NextFetchEvent) => {
const headers = new Headers(req.headers);
headers.set("x-current-domain", req.nextUrl.origin);
const response = NextResponse.next({
request: {
headers,
@estevan-ulian
estevan-ulian / rel-get-items-by-relation.php
Last active April 24, 2024 17:12 — forked from Crocoblock/rel-get-items-by-relation.php
JetEngine Related Items by Sibling Relation Macro
<?php
add_action( 'jet-engine/register-macros', function(){
class Related_Items_By_Sibling_Relation extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'rel_get_items_by_relation';
}
@estevan-ulian
estevan-ulian / elementor_widgets.xml
Created March 19, 2024 15:42
Register Custom Elementor Widgets in wpml translation - jet accordion and jet tricks hotspots
<wpml-config>
<elementor-widgets>
<widget name="jet-accordion">
<fields-in-item items_of="toggles">
<field type="Classic Accordion: Title" editor_type="LINE">item_label</field>
<field type="Classic Accordion: Editor Content" editor_type="VISUAL">item_editor_content</field>
</fields-in-item>
</widget>
<widget name="jet-hotspots">
<fields-in-item items_of="hotspots">
@estevan-ulian
estevan-ulian / jet-engine-cct-api.php
Created February 28, 2024 17:16 — forked from MjHead/jet-engine-cct-api.php
API to interact with JetEngine CCT from directly PHP code
<?php
/**
* JetEngine CCT-related API functions to use in theme or plugin
*
* Theme usage - include get_theme_file_path( 'jet-engine-cct-api.php' );
* Plugin usage - include PLUGIN_PATH . 'path-to-file-inside-plugin/jet-engine-cct-api.php';
*/
/**
@estevan-ulian
estevan-ulian / add_content_footer.php
Last active February 7, 2024 14:48
Este snippet adiciona trechos de código html logo antes da tag </body> em um site Wordpress.
@estevan-ulian
estevan-ulian / only_numbers_mask.js
Created February 7, 2024 14:42
Mascara para receber somente números no valor do input
function onlyNumbersMask (event) {
let value = event.target.value;
let mask = '';
mask = value.replace(/\D/g, '');
event.target.value = mask;
}
@estevan-ulian
estevan-ulian / brl_currency_mask.js
Last active February 22, 2024 11:59
Brazilian currency mask
const brlCurrencyMask = (e) => {
const { value } = e.target;
let mask = "";
mask = value.replace(",", "").replace(".", "").replace(/\D/g, "");
const options = { minimumFractionDigits: 2 };
const result = new Intl.NumberFormat("pt-BR", options).format(
parseFloat(mask) / 100,
);
@estevan-ulian
estevan-ulian / add_head_content.php
Last active December 21, 2023 18:51
Insere meta tags dentro do <head> do site Wordpress em função do id do post/pagina.
<?
add_action('wp_head', 'add_head_content');
function add_head_content(){
global $post;
$post_id = 123;
if($post->ID === $post_id) {
?>
@estevan-ulian
estevan-ulian / gf_form_debug.php
Created October 17, 2023 00:00
Utilizo este hook para debugar formulários e encontrar informações nos campos do Gravity Forms.
<?php
add_action( 'gform_pre_render', 'form_debug' );
function form_debug( $form ) {
foreach ( $form['fields'] as &$field ) {
echo '<pre>';
var_dump($field);
echo '</pre>';
}
return $form;
}
@estevan-ulian
estevan-ulian / valida_cpf_cnpj.php
Last active October 16, 2023 23:54
Este snippet valida se o CPF e/ou CNPJ inserido possuem valores válidos no momento da submissão do formulário Gravity Forms. Os campos devem ter a classe `cpf` e/ou `cnpj`.
<?php
add_filter('gform_validation', 'validar_cpf_e_cnpj');
function validar_cpf_e_cnpj($validation_result) {
$form = $validation_result['form'];
foreach ($form['fields'] as $field) {
$value = rgpost("input_{$field['id']}");
$isActive = isActive($field, $form);
if ($isActive) {