Skip to content

Instantly share code, notes, and snippets.

View vishalkakadiya's full-sized avatar
:octocat:

Vishal Kakadiya vishalkakadiya

:octocat:
View GitHub Profile
@vishalkakadiya
vishalkakadiya / Custom-Admin-Settings.php
Last active April 26, 2019 15:31
How to add custom settings in WordPress Admin ?
<?php
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@vishalkakadiya
vishalkakadiya / db.php
Last active June 28, 2019 12:11
HyperDB + Query Monitor
<?php
/**
Details: Basically This plugin is providing support of Query Monitor with HyperDB.
*/
/**
Warning: This plugin file is partially working, you must try this first on development environment and check everything and then only use this for Production.
Warning: USE THIS AT YOUR OWN RISK, Thank You!
*/
@vishalkakadiya
vishalkakadiya / functions.php
Created March 18, 2020 09:24
Bulk replace strings while rendering page in WordPress
<?php
/**
* Some time we get in situation where we have to replace specific string from whole site,
* Like if you are using WooCommerce for donation purpose and you want to display
* `donation` text in place of `order` text then I have ideal way to do this by below code.
*/
/**
* Filters text with its translation.
@vishalkakadiya
vishalkakadiya / gist:b091162b3c640d5f987b323aeea3bfa8
Last active September 26, 2020 05:44
Collapse all files in github's PR while viewing changes tab/section in PR.
// JUST run below code in your browser's console, in the browser's tab where PR is open.
var x = document.getElementsByClassName("js-details-container");
var i;
for (i = 0; i < x.length; i++) {
x[i].className = x[i].className.replace(/\bDetails--on\b/g, "");
x[i].className = x[i].className.replace(/\bopen\b/g, "");
}
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 28, 2020 12:15
Bypass sanitization with FieldManager's TextArea field which will allows to add HTML in metabox/metafield
<?php
/**
* Sometime we need to take input from user with Field Manager's TextArea field, FM is using sanitize_text_field](https://api.fieldmanager.org/source-class-Fieldmanager_Field.html#123)
* So below is the code to bypass or use your own validation logic.
*/
$fm = new \Fieldmanager_TextArea(
array(
'name' => '_vk_videoembed_manual',
'sanitize' => 'validate_embed_field', // Link your own validation function here.
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 28, 2020 12:16
Get list of function names which is hooked available on particular hook.
<?php
/**
* Change `the_content` thing in below function with your hook in filter
* - You can change $wp_filter to $wp_actions to get details of action hooks.
*
* NOTE: THIS IS FOR ONLY DEBUG PURPOSE NOT SEND THIS CODE TO PRODUCTION.
*/
function vk_list_hooks() {
global $wp_filter;
@vishalkakadiya
vishalkakadiya / functions.php
Last active December 28, 2020 12:16 — forked from pbearne/gist:7221162
how to add a tax_query to pre_get_posts in wordpress
<?php
add_action( 'pre_get_posts', array( $this,'function_pre_get_posts' ) );
function function_pre_get_posts(){
// you can't use the query->set here for tax_query
// as tax query has already been made
// so you need to need add youself to any
// existing tax query
$tax_query = array(
'taxonomy' => 'tax_name',
@vishalkakadiya
vishalkakadiya / Info.md
Last active December 31, 2020 11:40
Downgrade and Upgrade Node in MAC

These days if you want to install a different version of node you do it this way:

First search for your desired package:

brew search node

This might give you the follow results:

heroku/brew/heroku-node ✔
@vishalkakadiya
vishalkakadiya / audio-sample.html
Last active May 5, 2021 11:13
Audio(tag) Player - Play/Pause/Restart/Skip Some Seconds
<!--
Just replace your audio file's name with `file_example_MP3_700KB.mp3` given in below code.
Refs:
- https://stackoverflow.com/questions/29593733/i-want-to-stop-skip-30-seconds-on-audio-in-html
- https://developer.mozilla.org/en-US/docs/Web/Guide/Audio_and_video_delivery/Cross-browser_audio_basics
- https://www.w3schools.com/tags/ref_av_dom.asp
-->
<!DOCTYPE html>
@vishalkakadiya
vishalkakadiya / functions.html
Last active May 31, 2021 04:42
Create a Gutenberg block theme
<html>
<body>
<a href="https://developer.wordpress.org/block-editor/how-to-guides/themes/create-block-theme/">https://developer.wordpress.org/block-editor/how-to-guides/themes/create-block-theme/</a>
</body>
</html>