Skip to content

Instantly share code, notes, and snippets.

waqas waqasy

Block or report user

Report or block waqasy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View htaccess rules.txt
METHOD 1
ref: https://stackoverflow.com/a/41996977/1312563
Disabling REST API was not a bad idea, after all. It actually opened a huge hole in all websites!
In wordpress 4.4 there was a way
Here, I've found a possible solution with .htaccess but should be carefully tested in combination with whatever else is in your .htaccess file (e.g., pretty-url rules added by wordpress itself):
# WP REST API BLOCK JSON REQUESTS
# Block/Forbid Requests to: /wp-json/wp/
@waqasy
waqasy / WP-HTML-Compression
Created Dec 21, 2018 — forked from sethbergman/WP-HTML-Compression
Minify HTML for WordPress without a Plugin - Add to function.php
View WP-HTML-Compression
<?php
class WP_HTML_Compression
{
// Settings
protected $compress_css = true;
protected $compress_js = true;
protected $info_comment = true;
protected $remove_comments = true;
// Variables
@waqasy
waqasy / gist:6811b52d74e42ac4921638dfca1fbd7d
Created Dec 11, 2018 — forked from lukaszklis/gist:1247306
WordPress: check if a current page has children, if so display them, if not display all pages on the same level as current page
View gist:6811b52d74e42ac4921638dfca1fbd7d
<?php
// Your functions.php content
function has_children() {
global $post;
$pages = get_pages('child_of=' . $post->ID);
return count($pages);
@waqasy
waqasy / repeatable-fields-metabox.php
Created Oct 21, 2018 — forked from helen/repeatable-fields-metabox.php
Repeating Custom Fields in a Metabox
View repeatable-fields-metabox.php
<?
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {
View checkbox_input.php
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty
@waqasy
waqasy / wp-better-side-nav.php
Created Oct 7, 2018 — forked from MikeNGarrett/wp-better-side-nav.php
Instead of wp_list_pages where all children and grandchildren of the current page are listed out this method lists the parent page, siblings of the current page (in menu order) and when it gets to the current page it lists out the children.
View wp-better-side-nav.php
<?php /* Not as simple as it sounds */ ?>
<div class="side-nav">
<div class="holder">
<ul>
<?php
if (isset($post->post_parent) && $post->post_parent > 0) {
$permalink = get_permalink($post->post_parent);
$parent_title = get_the_title($post->post_parent);
print('<li class="page_item page-parent"><a href="'.$permalink.'">'.$parent_title.'</a></li>');
$parent = $post->post_parent;
@waqasy
waqasy / php-UA.php
Created Jul 13, 2018 — forked from walkergv/php-UA.php
Simple Event Tracking with Measurement Protocol Using cURL and PHP (plus redirect)
View php-UA.php
<?
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://www.google-analytics.com/collect?v=1&tid=[UA-XXXXXXXXX-1]&cid=[RANDOM_INTEGER_OR_GUID]&t=event&ec=[EVENT_CATEGORY]&ea=[EVENT_ACTION]&el=[EVENT_LABEL]',
CURLOPT_USERAGENT => 'Vanity-URL-Tracker',
));
$resp = curl_exec($curl);
curl_close($curl);
header("HTTP/1.1 301 Moved Permanently");
@waqasy
waqasy / serviceworker.js
Created Jul 9, 2018 — forked from ngokevin/serviceworker.js
Service Worker Template - cache-else-network + network-else-cache
View serviceworker.js
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 / time
Created Jul 5, 2018
get PST date time in php
View time
<?php
$timezone = -8; //(GMT -5:00) EST (U.S. & Canada)
$date = new DateTime("now", new DateTimeZone('America/Los_Angeles') );
echo $date->format('j F Y, h:i:s A').'<br>';
echo gmdate("Y/m/j H:i:s", time() + 3600*($timezone+date("I")));
?>
View bsearch-meta-field.php
<?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)
You can’t perform that action at this time.