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 / 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 / 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 / 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
const webpack = require("webpack");
//const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
transpileDependencies: ["vuetify"],
outputDir: "../assets/",
configureWebpack: {
plugins: [
new MiniCssExtractPlugin({
@BenBroide
BenBroide / datetime.php
Created July 9, 2019 22:17
Date time from time stamp
<?php
// This will error and break code
$datetime = new DateTime( 1565301395 );
var_dump( $datetime );
// This will work
$datetime = new DateTime();
$datetime->setTimestamp(1565301395);
var_dump( $start_date );
#!/bin/bash
function create_terms( ){
array=("$@")
for tax; do true; done
for term in "${array[@]}"
do
wp term create $tax "$term" --allow-root
done
#!/bin/bash
for post in $(wp post list --field=ID --allow-root)
do
count=$(wp post term list $post 'category' --fields='name' --format="count" --allow-root)
if [ "$count" -gt "1" ]
then
wp post term remove $post category 'uncategorized' --allow-root
fi
done
@BenBroide
BenBroide / wp-scaffold-child-theme-twentynineteen-child.sh
Created March 30, 2019 20:40
WP Cli Generate TwentyNine Child Theme
wp scaffold child-theme twentynineteen-child --parent_theme=twentynineteen
wp theme activate twentynineteen-child
@BenBroide
BenBroide / loop.js
Last active January 21, 2019 00:16
methods : {
async setOtherBookings() {
this.loadingOtherBookings = true;
if (this.booking.other_bookings.length > 0) {
for (let booking_post_id of this.booking.other_bookings) {
await this.loadOtherBooking(booking_post_id).then(response => {
this.addToSummary(response.data);
});
}
<?php
function mml_output_setting_row( $class, $name, $value , $option_key , $data_div, $text ){ ?>
<p> <input type="checkbox" class="<?php echo $class ?>" name="powerpack-plugin-options[<?php echo $name ?>]" value="<?php echo $value ?>" <?php isset( $options['ecom-function'] ) ? checked($options['ecom-function'], 1) : '';?> data-div="<?php echo $data_div ?>"/><?php echo $text ?></p>
<?php }