Skip to content

Instantly share code, notes, and snippets.

View elpuas's full-sized avatar
💻
coding

Alfredo Navas-Fernandini elpuas

💻
coding
View GitHub Profile
@elpuas
elpuas / disbale_gutenberg_by_cpt
Created March 26, 2022 16:25
Disable Gutenberg by Custom Post Type
/**
* Disable Gutenberg by CPT
*
* @param Object $current_status Current status.
* @param string $post_type Post type.
* @author ElPuasDigitalCrafts
*/
function prefix_disable_gutenberg( $current_status, $post_type ) {
if ( 'speakers' === $post_type ) {
return false;
@elpuas
elpuas / acf.php
Created February 16, 2022 20:31 — forked from khleomix/acf.php
Load icon files dynamically as ACF select options
<?php
/**
* Load icons dynamically into the `icon_picker` select field.
*
* @param array $field field options.
* @return array new field choices.
*
* @author JC Palmes
*/
function acf_load_icon_picker_field_choices( $field ) {
@elpuas
elpuas / functions.php
Last active January 18, 2022 13:58 — forked from noahduncan/functions.php
Automatically Sync ACF Fields on dev environments
<?php
/*
Plugin Name: ACF Auto Sync
Plugin URI:
Description: Plugin that automatically syncs the database with local json
Version: 1.0
Author: Noah Duncan <[email protected]>
Updated by: Alfredo Navas <[email protected]>
*/
// Turn debugging on
define('WP_DEBUG', true);
// Tell WordPress to log everything to /wp-content/debug.log
define('WP_DEBUG_LOG', true);
// Turn off the display of error messages on your site
define('WP_DEBUG_DISPLAY', false);
// For good measure, you can also add the follow code, which will hide errors from being displayed on-screen
@elpuas
elpuas / functions.php
Created October 25, 2021 16:42 — forked from guydumais/functions.php
WordPress ➧ Change Locale Dynamically in WordPress
/**
* Change Locale Dynamically in WordPress.
*
* @author Guy Dumais.
* @link https://en.guydumais.digital/change-locale-dynamically-in-wordpress/
*/
// Filters all language attributes in the html tag.
add_filter( 'language_attributes', $af = function( $output, $doctype ) {
@elpuas
elpuas / disable-settings.js
Created October 22, 2021 13:13
Gutenberg Filter to disable block settings ( This can also be done by theme.json, actually is better )
/**
* WordPress dependencies
*/
import { addFilter } from '@wordpress/hooks';
/**
* Change the default setting for the core/button block
*
* @param {object} settings
* @param {string} name
@elpuas
elpuas / getElementAttributes.js
Created October 15, 2021 15:10
Extract Element Attributes if DOM node props is a string.
/**
* Extract Element Attributes when DOM node is a string.
*
* @author Alfredo Navas
* @param {string} elemText String to extract attrs.
* @return {object} The attributes from the string
*/
export default function getElemAttributes(elemText) {
// Regex to pick out start tag from start of element's HTML.
let reStartTag =
@elpuas
elpuas / gf-update-form-fields.php
Last active September 2, 2021 19:15
Update Forms Everywhere
function twentytwentyone_gf_add_placeholder() {
$forms = GFAPI::get_forms();
foreach ( $forms as $form ) {
if ( $form['id'] !== 1 ) { // Or Any Form ID
return;
}
@elpuas
elpuas / gf-update-dropdown-placeholder.php
Created September 2, 2021 19:12
Modified Fields Front End
add_filter( 'gform_pre_render', 'twentytwentyone_gf_add_placeholder' );
add_filter( 'gform_pre_validation', 'twentytwentyone_gf_add_placeholder' );
add_filter( 'gform_pre_submission_filter', 'twentytwentyone_gf_add_placeholder' );
function twentytwentyone_gf_add_placeholder( $form ) {
if ( $form['id'] !== 1 ) {
return;
}
<?php
/**
* Sort forms in Gravity Forms block in alphabetical order.
*
* @param array $forms A collection of active forms on site.
*/
add_filter( 'gform_block_form_forms', function( $forms ) {
usort( $forms, function( $a, $b ) {