Skip to content

Instantly share code, notes, and snippets.

View developer-anuragsingh's full-sized avatar

Anurag Singh developer-anuragsingh

  • Cendyn
  • Gurugram
View GitHub Profile
// Validate CF7 text field for name
function custom_name_field_validation_filter($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
//here textbox type name is 'subject'
if($name == 'first-name' || $name == 'last-name') {
$value = $_POST[$name];
if (preg_match('/[\^£$%*()}{#~><>|=_+¬]/', $value)){
$result->invalidate( $tag, "Invalid characters." );
}
@developer-anuragsingh
developer-anuragsingh / Setup phpcs and wpcs in mac M1
Created May 1, 2021 06:57
WordPress Coding Standards in VSCode Macbook M1
Ref - https://www.edmundcwm.com/setting-up-wordpress-coding-standards-in-vs-code/
1. Install PHP CodeSniffer (PHPCS)
composer global require "squizlabs/php_codesniffer=*"
2. Create a Utilities folder
mkdir Utilities
cd Utilities
3. Download WPCS
@developer-anuragsingh
developer-anuragsingh / docker-compose.yml
Created February 18, 2021 18:17
Docker file to setup WordPress, MariaDb, PhpMyAdmin.
# ref - https://pawelgrzybek.com/configure-a-local-wordpress-development-using-docker/
# ref - https://hub.docker.com/_/wordpress
# Step 1. Create Dir where you want to setup you new WordPress project
# Step 2. Create a file named as 'docker-compose.yml'
# Step 3. Copy this file content into that newly created file.
# docker-compose up -d (start all services)
# docker-compose down (stop all services)
# docker-compose kill (forcefully stop all services)
@developer-anuragsingh
developer-anuragsingh / wc-show-cart-contents-total.php
Created February 3, 2021 19:22 — forked from woogists/wc-show-cart-contents-total.php
[Theming Snippets] Show cart contents / total
// Use in conjunction with https://gist.github.com/woogists/c0a86397015b88f4ca722782a724ff6c
<a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
@developer-anuragsingh
developer-anuragsingh / wc-show-cart-contents-total-ajax.php
Created February 3, 2021 19:22 — forked from woogists/wc-show-cart-contents-total-ajax.php
[Theming Snippets] Show cart contents / total Ajax
/**
* Show cart contents / total Ajax
*/
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
function Register_New_Cpt()
{
$cpt_name = 'YOUR_NEW_POST_TYPE';
$all_taxonomy = array('YOUR_NEW_TAXONOMY');
$namespace = 'YOUR_NAMESPACE';
$cpt_name_array = cpt_taxo_naming_convention($cpt_name);
foreach ($all_taxonomy as $single) {
$taxo_name_array = cpt_taxo_naming_convention($single);

SHORTCUTS

Key/Command Description
Tab Auto-complete files and folder names
Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + U Clear the line before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + W Delete the word before the cursor
Ctrl + T Swap the last two characters before the cursor
@developer-anuragsingh
developer-anuragsingh / posts-of-all-terms.php
Created January 8, 2020 07:14
List wordpress posts from all terms of a taxonomy
<?php
// List wordpress posts from all terms of a taxonomy
// Including all terms in wordpress tax_query
// get post type
$post_types = 'POST_TYPE_SLUG';
// get all terms in the taxonomy
$terms = get_terms( 'TERM_SLUG' );
@developer-anuragsingh
developer-anuragsingh / class-my-plugin-admin.php
Created December 17, 2019 02:45
WordPress admin setting page with 'wordpress boilerplate plugin'. Also using 'partials' folder's file to display HTML part of page.
<?php
// file location: ../admin/class-_____-admin.php
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
@developer-anuragsingh
developer-anuragsingh / contact-form-jquery-validation-recaptcha.js
Last active November 16, 2019 09:18
WP Contact Form through Short-code, with Google reCaptcha 3 and jQuery input Validations. Add shortcode [contact-form-recaptcha] to display contact form
jQuery(document).ready(function($) {
grecaptcha.ready(function() {
var SITE_KEY = ajax_obj.site_key; // fetch value from ajax_obj setup with 'wp_localize_script'
grecaptcha.execute(SITE_KEY, {action: 'contact_form'}).then(function(token) {
jQuery('#hidden-field').append('<input type="hidden" name="g-recaptcha-response" value="' + token + '">');
$("#contact-form").validate({