Skip to content

Instantly share code, notes, and snippets.

View vanpariyar's full-sized avatar
🏠
Working from home

Ronak J Vanpariya vanpariyar

🏠
Working from home
View GitHub Profile
@vanpariyar
vanpariyar / get_youtube_thumbnail.php
Created March 17, 2020 05:20
Get the thumbnail image of Youtube by Youtube Video URL.
function get_youtube_thumb($video_url)
{
if(preg_match('/src="([^"]+)"/', $video_url, $match))
$video_url = $match[1];
$ytRegExp = "/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/";
preg_match($ytRegExp, $video_url, $ytMatch);
$large = "";
if ($ytMatch && strlen($ytMatch[1]) === 11)
@vanpariyar
vanpariyar / master.yml
Created May 2, 2020 18:28 — forked from christeredvartsen/master.yml
Commit back to the repository from a workflow
name: Commit from workflow
on:
push:
branches:
- master
paths-ignore:
- file.txt
jobs:
build:
runs-on: ubuntu-latest
@vanpariyar
vanpariyar / MYSQL Snippet.sh
Last active May 20, 2020 14:07
MYSQL Snippets very useful.
#MYSQL import DB Snippet easy way.
mysql> use db_name;
mysql> source file_name.sql;
@vanpariyar
vanpariyar / .htaacess
Created June 10, 2020 10:43
Leverage Browser Caching
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
@vanpariyar
vanpariyar / functions.php
Last active June 17, 2020 05:13
Generate Post type dynamically in wordpress
function customiser_init(){
$post_types = array(
array(
'singular_name' => 'Financial',
'plural_name' => 'Financials',
'slug' => 'financials',
'post_type' => 'financials',
'support' => array( 'title', 'author' ),
),
@vanpariyar
vanpariyar / custom_post_type_pagination.php
Last active June 24, 2020 05:00
Get pagination work on custom post type word press by setting the posts_per_page manually
<?php
/**
* We are hardcoding the value of the posts per page for custom post type
* Please only change if you know what you are doing.
*
* IF you found the other way you can change it.
*/
function custom_posts_per_page( $query ) {
if (!is_admin() && is_archive('newsroom') && !is_year())
$query->set( 'posts_per_page', 15 );
@vanpariyar
vanpariyar / get_custom_posts_archive_year.php
Last active June 24, 2020 05:03
How to get custom post type archive year in array format with cache support in WordPress ? ( Ported from the WordPress core )
<?php
/**
* @see the function ported from the WP core.
* @see wp_get_archives() functions for more.
*
* @author Ronak Vanpariya
*
* @param are Optional
*
* @return { array } of the object which having 'years' and 'posts' props.
@vanpariyar
vanpariyar / email-wordpress-customfields.php
Last active July 23, 2020 14:15
send email with ACF email templates wordpress.
<?php
function send_email_to_admin($post_id , $post_type ){
switch ($post_type) {
case 'nominee-entries':
$terms = wp_get_post_terms( $post_id, 'award-category', array( 'fields' => 'names' ) );
$uploaded_file = get_field('uploaded_file', $post_id);
$fields = array(
'%{FIRST-NAME}%' => get_field('first_name', $post_id),
'%{LAST-NAME}%' => get_field('last_name', $post_id),
<?php
/**
* Send Email For OTP
* Using WP_rand ( because it is cryptographically secure then PHP rand ).
*/
$otp = wp_rand( 100000, 999999 );
$timestemp = current_time('timestamp');
/**
* OTP stemp Format( TimeStemp:OtpString ) for Ex. 15000000245455:465478
*/
@vanpariyar
vanpariyar / allow-mathml-in-bbpress.php
Created August 7, 2020 03:54
This is the snippet to allow the add MATHML tags on the BB Press forum reply.
<?php
add_filter( 'bbp_kses_allowed_tags', 'rew_add_mathml') ;
function rew_add_mathml ($allowed) {
$allowed['abs'] = array(
'abs' => true,'and' => true,'annotation' => true,'annotation-xml' => true,'apply' => true,'approx' => true,'arccos' => true,'arccosh' => true,'arccot' => true,'arccoth' => true,'arccsc' => true,'arccsch' => true,'arcsec' => true,'arcsech' => true,'arcsin' => true,'arcsinh' => true,'arctan' => true,'arctanh' => true,'arg' => true,'bind' => true,'bvar' => true,'card' => true,'cartesianproduct' => true,'cbytes' => true,'ceiling' => true,'cerror' => true,'ci' => true,'cn' => true,'codomain' => true,'complexes' => true,'compose' => true,'condition' => true,'conjugate' => true,'cos' => true,'cosh' => true,'cot' => true,'coth' => true,'cs' => true,'csc' => true,'csch' => true,'csymbol' => true,'curl' => true,'declare' => true,'degree' => true,'determinant' => true,'diff' => true,'divergence' => true,'divide' => true,'domain' => true,'domainofapplication' => true,'emptyset' => true,'eq'