Skip to content

Instantly share code, notes, and snippets.

@thedapifer
thedapifer / ninja-image-upload.php
Created March 13, 2018 09:25 — forked from sudiptoChy/ninja-image-upload.php
Ninja Image Upload WordPress Plugin
<?php
/**
* @package ninja_image_upload
* @version 1.0
*/
/*
Plugin Name: Ninja Image Upload
Plugin URI: http://authlab.io/
Description: This plugin allow users to upload image via a form can be created by shortcode
Version: 1.0
@thedapifer
thedapifer / missing_images.js
Created January 16, 2018 03:53 — forked from johnbocook/missing_images.js
Use jQuery to deal with missing images
// Hide the image on error
$("img").error(function(){
$(this).hide();
});
// Change the missing image to a default image
$('img').error(function(){
$(this).attr('src', 'no-image.jpg');
});
@thedapifer
thedapifer / ajax.upload.js
Created September 23, 2017 07:59 — forked from mklasen/ajax.upload.js
Upload files to WordPress with ajax via REST API
var data = new FormData()
// Add data/files to formdata var
jQuery.ajax({
url: wpApiSettings.root + 'routehere/v1/subroute/save',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce );
},
@thedapifer
thedapifer / upload-a-file.MD
Created September 23, 2017 07:27 — forked from ahmadawais/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:

@thedapifer
thedapifer / 0_reuse_code.js
Created September 10, 2017 19:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console