Skip to content

Instantly share code, notes, and snippets.

View andreilupu's full-sized avatar
⌨️
Hitting keys

Andrei Lupu andreilupu

⌨️
Hitting keys
View GitHub Profile
@andreilupu
andreilupu / 1-index.js
Last active February 3, 2024 14:38
WordPress Post Title variation which prints a <li> instead of <h{n}>
// register a new post title variation.
// In a production environment I would register a new attribute called "isLiPostTitle" and use that instead of checking the className.
window.wp.blocks.registerBlockVariation(
'core/post-title',
{
name: 'core/post-title-li',
title: 'Post title (li)',
attributes: {
className: 'is-li-title'
},
@andreilupu
andreilupu / buildSCSS.js
Created December 17, 2023 12:30
A simple PoC inspired by Gutenberg's build process of compiling SCSS files in packages/blocks. I'm just exploring a way of build/watch SCSS files in a blocks library. https://github.com/WordPress/gutenberg/blob/cdeca67b63635cca295ba8f4874130c53f394ab0/bin/packages/build-worker.js#L83
/**
* External dependencies
*/
const { promisify } = require( 'util' );
const path = require( 'path' );
const makeDir = require( 'make-dir' );
const fs = require("fs");
const sass = require( 'sass' );
const postcss = require( 'postcss' );
@andreilupu
andreilupu / replace-textdomain.sh
Created January 25, 2018 11:44
A fast bash script to replace all the 'textdomain' strings, from vendor, with the ones provided in `package.json`
#!/bin/bash
#get the textdomain from the package.json file.
#export TEXTDOMAIN
TEXTDOMAIN=$(node -pe "require('./package.json').textdomain")
# if there is a textdomain, apply to the vendor folder.
if [ "$TEXTDOMAIN" != "undefined" ]; then
find "vendor" -type f -name "**.php" -exec sed -i "s/, 'textdomain' )/, '$TEXTDOMAIN' )/g" {} +
fi;
@andreilupu
andreilupu / wp_disable_jquery_warnings.php
Created May 7, 2017 12:12
Add this file in the `/wp-content/mu-plugins/` directory in it will automatically be loaded by WordPress
<?php
function disable_jquerymigrate_warning( $scripts ) {
if ( ! empty( $scripts->registered['jquery'] ) ) {
$scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) );
}
}
add_action( 'wp_default_scripts', 'disable_jquerymigrate_warning' );
<?php
/**
* This shows how the field visibility can be changed conditionally between fields values
**/
function example_add_customify_fold_example_options( $options ) {
$folding_examples_section = array(
'folding_section' => array(
'title' => esc_html__( 'Folding', 'example' ),
'options' => array(
<?php
add_filter( 'gridable_row_options', function ( $options ) {
$options['bg_color'] = array(
'type' => 'color',
'label' => 'Row Background Color',
'default' => 'transparent'
);
@andreilupu
andreilupu / fix_featured_listings_meta.php
Created January 12, 2017 10:45
This code should be runned only once
@andreilupu
andreilupu / pixcare-auto-installer.php
Last active February 22, 2017 14:00
PixCare auto-installer from theme
<?php
/**
* A WordPress theme script which redirects the admin user, after the first theme activation, on a page where
* it forces a plugin installation, in this case, the Pixelgrade Care plugin.
*
* Inspired from
* WooCommerce - https://github.com/woocommerce/woocommerce
* Envato WordPress Theme Setup Wizard - https://github.com/dtbaker/envato-wp-theme-setup-wizard
* Shiny Updates V3 - https://make.wordpress.org/core/2016/07/06/shiny-updates-in-4-6/
*
@andreilupu
andreilupu / WordPress Paginated API results
Last active October 26, 2016 13:33
How to loop the API results which are paginated
<?php
/**
* Let's imagine that we need the issues number from an github organization
* The issues API results are limited to 100 per page so we need to call this recursively
* $offset (int) = the number of pages to skip for the current request
*/
function request_issues_number( $offset = 0 ) {
$page = 1;
if ( ! empty( $offset ) ) {
@andreilupu
andreilupu / tinymce.plugin.example.js
Last active January 10, 2024 11:09
TinyMCE Plugin Example
(function () {
/**
* A TinyMCE plugin example and some events handlings.
*/
tinymce.PluginManager.add('gridable', function ( editor, url ) {
// if your plugin needs a toolbar, save it for a larger scope
var toolbar;
/**