Skip to content

Instantly share code, notes, and snippets.

View BenBroide's full-sized avatar

Ben Broide BenBroide

  • New York
View GitHub Profile
@BenBroide
BenBroide / files_names_in_folder_to_json.bash
Created November 4, 2019 05:10
Bash outputting all files names in in Json format
ls -1 | rev | cut -f 2- -d "." | rev | awk ' BEGIN { ORS = ""; print "["; } { print "\/\@"$0"\/\@"; } END { print "]"; }' | sed "s^\"^\\\\\"^g;s^\/\@\/\@^\", \"^g;s^\/\@^\"^g" > icons.txt
@BenBroide
BenBroide / wp-cli-new-multiste.bash
Last active December 24, 2019 17:27
This command will add a new multisite with slug demo-X and a editor role user and output site URL, user name and user pass. You must create manually a site with slug "demo-1" before running the script first time
wp site list --allow-root > sites-list.txt
siteslist=`tail -1 sites-list.txt | head -1`
lastsiteurl=`echo $siteslist | egrep -o 'https?://[^ ]+'`
lasturlclean=`echo ${lastsiteurl::-1}`
lastid=`echo $lasturlclean|grep -Eo '[0-9]+$'`
((lastid++))
newslug="demo-${lastid}"
newsiteurl=`wp site create --slug=$newslug --private --allow-root|awk '{print $5}'`
username="demo${lastid}"
useremail="demo${lastid}@demo.com"
@BenBroide
BenBroide / wp-delete-post-hook.php
Created February 3, 2020 01:33
wp delete post hook
function my_delete_function($post_id) {
global $wpdb;
// our custom code with $post_id
}
// outisde a class
add_action( 'before_delete_post', 'my_delete_function' );
// inside a class
add_action( 'before_delete_post', [ $this, 'my_delete_function' ] );
@BenBroide
BenBroide / react-plugin.php
Last active December 22, 2020 18:58
CRA + WordPress. wp admin. Function plugin
<?php
/**
* Plugin Name: WordPress React Create App
* Description: Load React app in WorePress Admin concept
* Author: Ben Broide
* Text Domain: react-plugin
* Domain Path: /languages
* Version: 0.1.0
*
* @package React_Plugin
@BenBroide
BenBroide / package.json
Created May 28, 2020 08:15
CRA + WordPress. wp admin. Function plugin
{
"homepage": "/wp-content/plugins/wp-create-react-app-concept/react-app/build",
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
@BenBroide
BenBroide / index.js
Created May 28, 2020 08:16
CRA + WordPress. wp admin. Function plugin
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import * as serviceWorker from './serviceWorker'
const reactAppData = window.rpReactPlugin || {}
const { appSelector } = reactAppData
const appAnchorElement = document.querySelector(appSelector)
@BenBroide
BenBroide / index.js
Created May 28, 2020 08:23
CRA + WordPress. Front end. Function plugin
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import * as serviceWorker from './serviceWorker'
const reactAppData = window.rpReactPlugin || {}
const { appSelector } = reactAppData
const appAnchorElement = document.querySelector(appSelector)
@BenBroide
BenBroide / react-plugin.php
Created May 28, 2020 08:24
CRA + WordPress. Front end. Function plugin
<?php
/**
* Plugin Name: WordPress React Create App
* Description: Load React app in WorePress Admin concept
* Author: Ben Broide
* Text Domain: react-plugin
* Domain Path: /languages
* Version: 0.1.0
*
* @package React_Plugin
<?php
/**
* Plugin Name: WordPress React Create App
* Description: Load React app in WorePress Admin concept
* Author: Ben Broide
* Text Domain: react-plugin
* Domain Path: /languages
* Version: 0.1.0
*
* @package React_Plugin
@BenBroide
BenBroide / react-plugin.php
Created May 28, 2020 08:43
CRA + WordPress. Front end. Class plugin
<?php
/**
* Plugin Name: WordPress React Create App
* Description: Load React app in WorePress Admin concept
* Author: Ben Broide
* Text Domain: react-plugin
* Domain Path: /languages
* Version: 0.1.0
*
* @package React_Plugin