Skip to content

Instantly share code, notes, and snippets.

@jprieton
jprieton / delete-products-woocommerce.sql
Created April 13, 2016 16:19
Delete all products in woocommerce with comments
delete from wp_posts where post_type in ('product', 'product_variation', 'shop_order');
delete from wp_postmeta where post_id not in (select ID as post_id from wp_posts);
delete from wp_comments where comment_post_ID not in (select ID as comment_post_ID from wp_posts);
delete from wp_commentmeta where comment_id not in (select comment_ID as comment_id from wp_comments);
@jprieton
jprieton / accept-terms.php
Last active April 14, 2016 14:51
Example of hook pre_jptt_user_register to accept Terms & Conditions
<?php
/**
* To validate if user accepts terms & conditions
*/
add_action( 'pre_jptt_user_register', function () {
$accept_terms = (bool) trim( filter_input( INPUT_POST, 'accept_terms', FILTER_SANITIZE_STRING ) );
if ( !$accept_terms ) {
$error = new WP_Error( 'no_accept_terms', __( "You must accept terms & conditions to continue", TEXT_DOMAIN ) );
@jprieton
jprieton / wp-query-ref.php
Created August 8, 2016 19:52 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'me/favorite', 'add', array(
'methods' => 'GET',
'callback' => 'rest_test',
) );
} );
function wp_send_rest_success( $response = array() ) {
@jprieton
jprieton / behavior.js
Created August 27, 2016 23:11
Mask input type file with Bootstrap
(function ($) {
'use strict';
// Used to mask behavior of input type file
$('.input-group-file').each(function (e, i) {
var inputFile = $(i).find('input[type="file"]');
var inputText = $(i).find('input[type=text]');
var inputLabel = $(i).find('label');
// Bind click to use the label behavior in the input text
<?php
/**
* CLI for create a virtualhost in Wamp
*/
if ( empty( $argv[1] ) ) {
echo "A vhost name is required";
return false;
}
@jprieton
jprieton / optim-img.sh
Last active October 18, 2019 15:52
Image optimization
#!/bin/sh
# find /var/www/html/wp-content/uploads/ -type f -empty -iname "*.jpg" -delete
# find /var/www/html/wp-content/uploads/ -type f -empty -iname "*.jpeg" -delete
# find /var/www/html/wp-content/uploads/ -type f -empty -iname "*.png" -delete
#
# find /var/www/html/wp-content/uploads/ -type f -iname "*.jpg" -exec jpegoptim --strip-all {} \;
# find /var/www/html/wp-content/uploads/ -type f -iname "*.jpeg" -exec jpegoptim --strip-all {} \;
# find /var/www/html/wp-content/uploads/ -type f -iname "*.png" -exec optipng {} \;
#
@jprieton
jprieton / debloat.sh
Created November 15, 2017 19:01
ZTE E10Q Debloat
# Requires root
su
# mount as read-write
mount -o rw,remount,rw /system
# Malware?
rm /system/priv-app/Xfota.apk
rm -r /data/data/com.xbkpnotification
# Malware?
rm /system/priv-app/EMBI.apk
rm -r /data/data/com.syswin.gservices
@jprieton
jprieton / Gruntfile.js
Last active August 2, 2018 17:39
Default Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
lib: {
files: [
{
expand: true,
@jprieton
jprieton / current-user-permission.sh
Created May 9, 2019 02:31
Fix folder permission /var/www
# Add $USER to the www-data group
sudo usermod -a -G www-data $USER
# Change to group
sudo chgrp -R www-data /var/www/html
# Change propetary
sudo chown -R $USER:www-data /var/www/html/
# Update permissions