Skip to content

Instantly share code, notes, and snippets.

View nfmohit's full-sized avatar

Nahid F Mohit nfmohit

View GitHub Profile
@nfmohit
nfmohit / TemplateList.js
Created January 15, 2022 06:31
Calculates column count and column spacing depending on the container width
/**
* External dependencies
*/
import { useState, useEffect, useRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import Button from '../../ui-components/Button/Button';
@nfmohit
nfmohit / settings.json
Created July 11, 2020 13:16
Preferred VS Code rules for ESLint + Prettier + Stylelint
{
...existing VS Code rules,
/* Require the Prettier configuration file */
"prettier.requireConfig": true,
/* Turn off VSCode Formatting on Save for JS and JSX,
we will do this via ESLint */
<?php
if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {
function woocommerce_template_loop_add_to_cart( $args = array() ) {
global $product;
if ( !$product->is_in_stock() ) {
echo '<a href="' . get_permalink() . '" class="button">Out of Stock</a>';
} else {
<?php
add_action( 'admin_init', function () {
if ( is_network_admin() || is_super_admin() ) return;
$menu_items = [
'themes.php',
'plugins.php',
'options-general.php'
];
<?php
function forminator_entry( $attributes ) {
$atts = shortcode_atts( array(
'form_id' => __( 'Form ID not specified.', 'forminator-entry' ),
'entry_id' => __( 'Entry ID not specified.', 'forminator-entry' ),
), $attributes );
/* Start Object Buffer */
<?php
function preload_assets() {
wp_enqueue_style( 'eicons', 'https://digitalroar.org/elem/assets/lib/eicons/fonts/eicons.woff2' );
wp_enqueue_style( 'forminator-icons-font', 'https://digitalroar.org/formpro/assets/forminator-ui/fonts/forminator-icons-font.woff2' );
}
add_action( 'wp_enqueue_scripts', 'preload_assets' );
function preload_option( $html, $handle ) {
if ( 'eicons' === $handle || 'forminator-icons-font' === $handle ) {
return str_replace( "media='all'", "media='all' rel='preload' as='font'", $html );
@nfmohit
nfmohit / search-filter.js
Created December 21, 2019 08:27
Search through a list and filter
(function($) {
$(document).ready(function(){
$( '#nothing' ).hide();
$( '#search' ).keyup( function() {
// Searched text
var text = $(this).val().toLowerCase();
// Hide all content class element
$( '.faq-wrapper' ).hide();
@nfmohit
nfmohit / woocommerce-login-redirect.php
Created December 5, 2019 08:23
Require users to log in before viewing a WooCommerce page (redirects to the login page, upon login, redirects back to the previous WooCommerce page)
<?php
function woocommerce_login_redirect() {
if ( class_exists( 'WooCommerce' ) ) {
if( is_woocommerce() && ! is_user_logged_in() ) {
auth_redirect();
}
}
}
add_action( 'template_redirect', 'woocommerce_login_redirect' );
@nfmohit
nfmohit / populate-fields-from-url-queries.php
Last active September 9, 2019 02:26
Populate Forminator fields from URL queries
<?php
if ( ! function_exists( 'populate_fields_from_url' ) ) {
add_action(
'forminator_after_form_render',
function( $id, $form_type, $post_id, $form_fields, $form_settings ) {
// Change the number 60 with your Form ID.
if ( 60 === $id ) {
add_action( 'wp_footer', 'populate_fields_from_url', 999 );
}
@nfmohit
nfmohit / remove-postcustom.php
Last active August 5, 2019 01:12
Remove the custom fields metabox from the "document" post type
<?php
function remove_document_postcustom_metabox() {
remove_meta_box( 'postcustom' , 'document' , 'normal' );
}
add_action( 'admin_menu' , 'remove_document_postcustom_metabox' );