Skip to content

Instantly share code, notes, and snippets.

View mujahidi's full-sized avatar

Mujahid Ishtiaq mujahidi

  • Pakistan
View GitHub Profile
@mujahidi
mujahidi / functions.php
Last active May 30, 2025 18:26
GravityForms - Use custom conditional logic to display other fields which are not supported out of the box by GF
<?php
/**
* Validates the custom mask date field format MM/YYYY.
*/
add_filter('gform_field_validation_8', function($result, $value, $form, $field) {
$date_field_ids = [119, 120, 121]; // Field IDs of the custom date field
if (!in_array($field->id, $date_field_ids)) {
return $result;
}
@mujahidi
mujahidi / functions.php
Created October 16, 2024 19:47
Redirect old /hello-world to /blog/hello-world URL
<?php
add_action('template_redirect', 'redirect_old_post_urls');
function redirect_old_post_urls() {
if (is_404()) {
global $wp;
$request = $wp->request;
$post = get_page_by_path($request, OBJECT, 'post');
@mujahidi
mujahidi / append-param.php
Created March 19, 2024 14:10
Pause video when jQuery SLICK slide changes
<?php
// append custom parameters to YouTube iframe to enable JS API
$custom_parameters = '&amp;rel=0&amp;enablejsapi=1';
// Append custom parameters to the src attribute of the iframe
$modified_iframe = preg_replace('/src="(.*?)"/', 'src="$1' . $custom_parameters . '"', $video_iframe);
// For Vimeo video, make sure to append ?api=1
@mujahidi
mujahidi / functions.php
Created October 19, 2023 15:42
Create Woocommerce custom email notification
<?php
$mailer = WC()->mailer();
$template = '/emails/customer-admin-order-status.php';
//format the email
$subject = 'Order Status Update';
$content = wc_get_template_html( $template, array(
'order' => $order,
@mujahidi
mujahidi / functions.php
Last active July 3, 2023 19:03
Multiple instances of same GF form on the same page
<?php
/**
* Multiple instances of same GF form on the same page
*/
add_filter( 'gform_get_form_filter_1', 'gform_get_form_filter_handler', 10, 2 );
add_filter( 'gform_confirmation_1', 'gform_get_form_filter', 10, 2 );
function gform_get_form_filter_handler( $form_string, $form ){
// if form has been submitted, use the submitted ID, otherwise generate a new unique ID
if ( isset( $_POST['gform_random_id'] ) ) {
$random_id = absint( $_POST['gform_random_id'] ); // Input var okay.
@mujahidi
mujahidi / _mixin.scss
Created April 18, 2023 19:05
SASS mixin
$imagePath: "assets/images";
$breakpoints: (
sm: 576px,
md: 768px,
lg: 992px,
xl: 1200px,
xxl: 1400px,
);
@mujahidi
mujahidi / functions.php
Created April 11, 2023 15:19
READ MORE LESS BUTTON SHORTCODE
<?php
add_shortcode('read_more_less', 'read_more_less_button_handler');
function read_more_less_button_handler( $attrs, $content ){
$title = $attrs['title'];
if( !$title )
$title = "Learn More";
return '
<div class="readmorelessbutton-container">
@mujahidi
mujahidi / index.html
Created July 20, 2022 15:00
MP4 Full Width Video Wrapper
<!-- Change POSTER, MP4_URL, WEBM_URL and OGG_URL -->
<!-- Might need to add some height to main element -->
<div class="video-hero jquery-background-video-wrapper demo-video-wrapper">
<video class="jquery-background-video" autoplay muted loop poster="POSTER">
<source src="MP4_URL" type="video/mp4">
<source src="WEBM_URL" type="video/webm">
<source src="OGG_URL" type="video/ogg">
</video>
<div class="video-hero--content"></div>
</div>
@mujahidi
mujahidi / function.php
Last active July 13, 2022 16:00
Add new fields to WC admin Page Setup
<?php
// Admin -> WC -> Settings -> Advanced -> Page Setup
add_filter( 'woocommerce_settings_pages' , 'add_new_woocommerce_settings_pages' );
function add_new_woocommerce_settings_pages( $settings ){
$new_pages = array();
foreach( $settings as $s ){
if( $s['id'] == 'advanced_page_options' ){
$new_pages[] = array(
@mujahidi
mujahidi / functions.php
Created November 29, 2021 12:53
Jump to specific page in Gravity Forms multi-page form
<?php
// ONLY FOR TESTING
add_filter("gform_pre_render", "gform_skip_page");
function gform_skip_page($form) {
if(!rgpost("is_submit_{$form['id']}") && rgget('form_page'))
GFFormDisplay::$submission[$form['id']]["page_number"] = rgget('form_page');
return $form;
}