Skip to content

Instantly share code, notes, and snippets.

View itzikbenh's full-sized avatar

Isaac Ben Hutta itzikbenh

View GitHub Profile
@itzikbenh
itzikbenh / webpack.config.js
Last active December 8, 2017 00:19
Webpack slow config
module.exports = env => {
const config = {
devServer: {
hot: true,
inline: true,
headers: { 'Access-Control-Allow-Origin': '*' },
port: 8080,
host: 'localhost',
},
entry: {
import Vue from 'vue';
import posts from './components/posts.vue';
window.axios = require('axios');
window.Vue = Vue;
Vue.component('posts', posts);
const app = new Vue({
el: '#app',
@itzikbenh
itzikbenh / app.js
Created October 11, 2017 17:31
Picky class
class Picky {
constructor(element) {
let self = this;
this.$el = element;
this.select = this.$el.querySelector('select');
this.dropdown = this.$el.querySelector('ul');
this.input = this.$el.querySelector('input');
this._open = false;
@itzikbenh
itzikbenh / cron-commands
Created September 8, 2017 00:49
Backup cron
0 * * * * /usr/bin/env bash /root/backup/db-backup.sh &>> /root/backup/backup.log
0 0 * * * /usr/bin/env bash /root/backup/uploads-backup.sh &>> /root/backup/backup.log
@itzikbenh
itzikbenh / admin.js
Created August 26, 2017 23:14
Category Image
$('#update-cat-featured-img, #add-cat-featured-img').click(function(e) {
e.preventDefault();
var custom_uploader = wp.media({
title: 'Featured Image',
button: {
text: 'Insert image'
},
multiple: false // Set this to "add" to allow multiple files to be selected
})
@itzikbenh
itzikbenh / example.md
Created August 2, 2017 01:11
Stripe basic class

NOTE

Always handle errors when you use stripe functions. You don't want to make mistakes when it comes to people's money.

Create a customer

$stripe_client = new Stripe_Client( $user, $stripe_secret, $token );

try {
  $customer = $stripe_client->create_customer();
} catch (Exception $e) {
@itzikbenh
itzikbenh / app.js
Created August 1, 2017 18:09
WordPress - Insert file into tinymce in the frontend via the REST API
let $body = $('body');
let $error_field = $('.file-error');
function hasExtension(file_name, exts) {
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$', "i")).test(file_name);
}
function fileSizeInMB(file_size) {
return (file_size / (1024*1024)).toFixed(2);
@itzikbenh
itzikbenh / functions.php
Created July 31, 2017 22:00
WordPress - show current user attachments
<?php
//Besides administrator show only the current user media files
function show_current_user_attachments( $query ) {
if( ! current_user_can( 'manage_options' ) ) {
$user_id = get_current_user_id();
if ( $user_id ) {
$query['author'] = $user_id;
}
return $query;
@itzikbenh
itzikbenh / errors.php
Last active July 31, 2017 13:00
WordPress simple validator class. Still in the work
<?php if( isset( $_SESSION['errors'] ) ): ?>
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<ul>
<?php foreach ($_SESSION["errors"] as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
@itzikbenh
itzikbenh / company.js
Last active October 11, 2017 12:08
WP repeater field
function generate_key_person_fields(newId) {
return `
<div class="key-person-container">
<div class="form-group-admin-inline">
<label>Name</label><br>
<input type="text" name="key_person[name][${newId}][]" value="" required>
</div>
<div class="form-group-admin-inline">
<label>Title</label><br>