Skip to content

Instantly share code, notes, and snippets.

View jboulhous's full-sized avatar

Jamal Boulhous jboulhous

  • Morocco, Africa
View GitHub Profile
@jboulhous
jboulhous / wc-bookings-availability-search.php
Created February 25, 2019 09:15 — forked from apintocr/wc-bookings-availability-search.php
WooCommerce Bookings Availability Search
<?php
/**
* WooCommerce Bookings Availability Search
*
* This is almost pseudo code, it only serves to explain the "how to do it" and does not attempt to be "The Way" to do it.
* NOTE: This NEEDS to be refined in order to work as expected.
*
* @author António Pinto <[email protected]>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@jboulhous
jboulhous / dropzonejs-wp-rest-api.js
Last active April 28, 2018 16:06 — forked from soderlind/dropzonejs-wp-rest-api.js
DropzoneJS & WordPress REST API
/*
Uploading images is a two step process (from https://github.com/WP-API/WP-API/issues/1768#issuecomment-160540932):
POST the data to /wp/v2/media - this can either be as the request body, or in multipart format. This will upload the file, and give you a 201 Created response with a Location header. This header points to the post object for the attachment that has just been created.
PUT the post data to the endpoint returned in the Location header (which will look something like /wp/v2/media/{id}).
I do step 2 (PUT), if POST is a success, in myDropzone.on("success", function(file, response){}
*/
// dropzoneWordpressRestApiForm is the configuration for the element that has an id attribute
@jboulhous
jboulhous / upload-a-file.MD
Created April 28, 2018 16:06 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

define([
"underscore",
"backbone",
"marionette",
"vent"
],
/**
* Creates the primary `Marionette.Application` object that runs the admin framework. Provides a central point
* from which all other sub-applications are started, shown, hidden, and stopped.
@jboulhous
jboulhous / slugify.js
Created May 20, 2013 09:17 — forked from mathewbyrne/slugify.js
Make url slug
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
/*
HTTP status code messages
*/
function getStatusCodeMsg (code) {
var msg = false;
switch (code) {
class Backbone.Marionette.StackRegion extends Backbone.Marionette.Region
constructor: ->
super
@views = []
# Return the top view (currently visible)
peek: ->
@views[@views.length - 1] if @views.length
MyApp.module('MyApp.SomeBuilder', function(SomeBuilder, App, Backbone, Marionette, $, _){
'use strict';
// Controller
// ----------
SomeBuilder.Controller = Marionette.Controller.extend({
initialize: function(options){
this.navbarRegion = options.navbarRegion;
this.mainRegion = options.mainRegion;
@jboulhous
jboulhous / gist:4216074
Created December 5, 2012 14:51 — forked from incredimike/variousCountryListFormats.js
Country list as javascript array (alphabetical)
// This needs tidied up before production TODO
var country_list = ["Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua &amp; Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas"
,"Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia &amp; Herzegovina","Botswana","Brazil","British Virgin Islands"
,"Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands","Costa Rica"
,"Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea"
,"Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia","French West Indies","Gabon","Gambia","Georgia","Germany","Ghana"
,"Gibraltar","Greece","Greenland","Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bis