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-cli-generate-posts-with-meta.bash
Created July 15, 2018 17:37
Generate posts with wp-cli with multiple meta fields
wp post generate --format=ids --post_type=listing --count=100 | sed -e "s/ /\n/g" | xargs -n1 -I % sh -c 'echo "Adding fields for %"; wp post meta add % _address "531 east 2";wp post meta add % _country "United States"; wp post meta add % _zip "10000"; wp post meta add % _state "NY";wp post meta add % _house 35';
@BenBroide
BenBroide / update-post-meta.bash
Created February 25, 2018 20:36
WP CLI - update post meta to many posts by wp post list result
POSTIDLIST=($(wp post list --post_type=booking --format=ids));
for POSTID in ${POSTIDLIST[@]}; do
wp post meta set $POSTID _field_name field_value
done
@BenBroide
BenBroide / broken-pdf.js
Created April 21, 2017 13:50
Get all broken PDF files url in page
function urlExists(url, text ){
jQuery.get(url, function (response, status, xhr) {
if (xhr.getResponseHeader("content-type").indexOf("text") > -1){
//console.log( text + ' --> ' + url+ ' --> NOT PDF' );
} else {
//console.log(xhr.getResponseHeader("content-type"));
if( xhr.getResponseHeader("Content-Length") == null){
console.log(xhr.getResponseHeader("Content-Length"));
console.log( text + ' --> ' + url+ ' --> IS PDF' );
@BenBroide
BenBroide / remote-url-file-to-wp-library.com
Last active March 29, 2018 02:43
Save remote file by URL to WordPress Media Library
$get = wp_remote_get( $fileurl );
$mirror = wp_upload_bits( basename( $fileurl ), '', wp_remote_retrieve_body( $get ) );
$attachment = [
'post_status' => 'inherit',
'post_mime_type' => $mirror['type'],
'parent_id' => $this_post_id,
'post_title' => $file_title
];
wp_insert_attachment( $attachment, $mirror['file'], $this_post_id );
@BenBroide
BenBroide / setup-wp-twentyseventeen-child-plugins.sh
Last active October 10, 2017 13:12
Turn c9 WordPress workspace server "ON" and paste this bash code in the c9 ide terminal and click "enter"
#turn workspace server on ( "RUN" button), paste this into c9 terminal, and hit "enter"
SETUP_PATH="setup.sh"
cat >$SETUP_PATH <<'EOF'
#!/bin/bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp core install --url=https://$C9_HOSTNAME --title=QuickWP --admin_user=admin --admin_password=123456 --admin_email=$C9_EMAIL
wp option update my_option '{"site_url": "bar"}' --format=json
wp theme install twentyseventeen
@BenBroide
BenBroide / simple-quick-wp-twentyseventeen.bash
Last active April 23, 2017 18:25
Cloud9 auto setup WordPress TwentySeventeen +Child theme activated with wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
siteurl=$(hostname)
siteurl="${siteurl%-*}"
echo $siteurl
echo "${siteurl%-*}"
wp core install --url=example.com --title=QuickWP --admin_user=admin --admin_password=123456 [email protected]
wp scaffold child-theme twentyseventeen-child --parent_theme=twentyseventeen
# Recives hostname : batz-bar-taxi-coupons-4241432
# returns: batz-bar-taxi-coupons
IFS='-' read -r -a host_name_array <<< "$(hostname)"
unset 'host_name_array[${#host_name_array[@]}-1]'
IFS=$'-'; echo "${host_name_array[*]}" ;
@BenBroide
BenBroide / QuickWpWooCommerece.bash
Last active April 21, 2017 13:53
QuickWpWooCommerece.bash
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp core install --url=example.com --title=QuickWP --admin_user=admin --admin_password=123456 [email protected]
wp scaffold child-theme twentysixteen-child --parent_theme=twentysixteen
wp plugin install woocommerce --activate
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp core install --url=example.com --title=QuickWP --admin_user=admin --admin_password=123456 [email protected]
wp scaffold child-theme twentysixteen-child --parent_theme=twentysixteen
npm install -g bower
cd wp-content/themes/twentysixteen-child/
bower install --save datatables.net
bower install --save datatables.net-dt
wp core update
@BenBroide
BenBroide / Simple_custom_fields.php
Last active October 18, 2016 03:13
Simple custom fields snippet
<?php
function save_postdata( $post_id, $post, $update )
{
$meta_keys = array(
"location" => "text",
);
foreach( $meta_keys as $meta_key => $type )
{
if( isset( $_POST[ $meta_key ] ) )