Skip to content

Instantly share code, notes, and snippets.

@waqasy
waqasy / serviceworker.js
Created July 9, 2018 18:08 — forked from ngokevin/serviceworker.js
Service Worker Template - cache-else-network + network-else-cache
var VERSION = 'v1';
var cacheFirstFiles = [
// ADDME: Add paths and URLs to pull from cache first if it has been loaded before. Else fetch from network.
// If loading from cache, fetch from network in the background to update the resource. Examples:
// 'assets/img/logo.png',
// 'assets/models/controller.gltf',
];
@waqasy
waqasy / bsearch-meta-field.php
Created June 15, 2018 09:18 — forked from ajaydsouza/bsearch-meta-field.php
Better Search API Examples
<?php
// Fixes to disregard Hidden products and to add Author Billing field to Better Search plugin queries
function filter_bsearch_posts_join( $join ) {
global $wpdb, $author_search;
$join .= "
INNER JOIN $wpdb->postmeta AS pm ON ($wpdb->posts.ID = pm.post_id)
";
if ( $author_search ) {
$join .= "
INNER JOIN $wpdb->postmeta AS pma ON ($wpdb->posts.ID = pma.post_id)
@waqasy
waqasy / featured-posts-pattern-helper-functions.php
Created June 1, 2018 00:30 — forked from luistinygod/featured-posts-pattern-helper-functions.php
WordPress: Manage featured posts using WordPress menus
@waqasy
waqasy / Convert Custom Taxonomy to Custom Post Type
Created May 28, 2018 20:59 — forked from Strap1/Convert Custom Taxonomy to Custom Post Type
A very hacky and quick way to transfer a Custom Taxonomy to Custom Post Type and transfer associated metadata to Custom Meta Fields. Note: You can use this if it fits your needs, but it is custom to my set up. Use in a testing environment. It's a plugin with no interface, runs on activation and depending on the amount of data, may hit PHP timeou…
<?php
/*
Plugin Name: Convert Custom Taxonomy to Custom Post Type
Plugin URI: N/A
Description: A plugin to convert a Custom Taxonomy to a Custom Post Type and transfer associated metadata.
Version: 0.1
Author: Strap1
Author URI: http:/www.hiphopinenglish.com
/** Convert Taxonomy '%name%' to CPT '%name%' **/
@waqasy
waqasy / custom-post-taxonomy-permalinks.php
Created May 28, 2018 20:17 — forked from kasparsd/custom-post-taxonomy-permalinks.php
Create permalink structure URLs for custom post types that include all parent terms from a custom taxonomy
<?php
/*
Term Archive Pages:
- http://example.com/recipes/dinner/
- http://example.com/recipes/breakfast,brunch/
Single Recipe Pages:
- http://example.com/recipes/dinner/soup-title/
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@waqasy
waqasy / tanggal_regex_php
Created May 24, 2018 10:47 — forked from pujie/tanggal_regex_php
php regex for date (id)
<?php
echo '<h2>yyyy/mm/dd</h2>';
preg_match('/(19[5-9][0-9]|20[0-9][0-9])[\/-](0[1-9]|1[0-2])[\/-](0[1-9]|1[0-9]|2[0-9]|3[01])/','2011/12/30',$match);
foreach($match as $key=>$val){
echo $key . ' => ' . $val . '<br>';
}
echo '<h2>dd/mm/yyyy</h2>';
preg_match('/(0[1-9]|1[0-9]|2[0-9]|3[01])[\/-](0[1-9]|1[0-2])[\/-](19[5-9][0-9]|20[0-9][0-9])/','30/12/2011',$match);
foreach($match as $key=>$val){
@waqasy
waqasy / handle_file_upload.php
Created May 23, 2018 03:56 — forked from ebidel/handle_file_upload.php
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@waqasy
waqasy / handle_file_upload.php
Created May 23, 2018 03:44 — forked from ladyquartermaine/handle_file_upload.php
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@waqasy
waqasy / index.html
Created May 23, 2018 03:35 — forked from poeticninja/index.html
base64 to file blob, very basic example.
<!doctype html>
<html>
<head>
<title>File Upload Page</title>
</head>
<body>
<h1 onClick="sendFormData()">Send it!</h1>
<script type="text/javascript">