Skip to content

Instantly share code, notes, and snippets.

fumikito / request.php
Created March 2, 2017 08:07
A typical jQuery request to WordPress REST API
View request.php
* Regsiter script
add_action( 'wp_enqueue_scripts', function() {
// Set dependency to wp-api, which has nonce and endpoint root.
wp_enqueue_script( 'api-handler', '/path/to/api-handler.js', [ 'jquery', 'wp-adpi' ], '1.0', true );
} );
moorscode / script_local_fallback.php
Last active July 1, 2020 11:25
Add inline local script fallback for remotely loaded scripts in WordPress
View script_local_fallback.php
* wp_register_script wrapper with local fallback
* @param $handle
* @param $src
* @param $js_test JavaScript code to test for availability of object
* @param bool|false $local_src Load source file if test fails
* @param array $deps
wpscholar /
Last active May 27, 2023 08:24
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
charleslouis / custom-search-acf-wordpress.php
Last active May 29, 2023 16:51
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
View custom-search-acf-wordpress.php
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
AWeg / CopyAsanaTasks.php
Last active May 5, 2020 01:04 — forked from mhdhejazi/CopyAsanaTasks.php
main changes: - Asana has own SSL cert -> had to add to lines of code - copies subtasks and up to 11 subtasks of subtasks - copies tags -> only tagnames not followers/descriptions
View CopyAsanaTasks.php
function asanaRequest($methodPath, $httpMethod = 'GET', $body = null)
$apiKey = 'ASANA_API_KEY_HERE'; /// Get it from
$url = "$methodPath";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);