Skip to content

Instantly share code, notes, and snippets.

View imvarunkmr's full-sized avatar

Varun Kumar imvarunkmr

View GitHub Profile
@imvarunkmr
imvarunkmr / disable-linting-rules-sage9.json
Last active January 31, 2018 06:29
Disables certain linting rules in Sage 9
"no-empty-source": null,
"declaration-empty-line-before": null,
"color-hex-case": null,
"block-closing-brace-empty-line-before": null,
"no-missing-end-of-source-newline": null,
@imvarunkmr
imvarunkmr / wp-plugin_header.php
Last active May 9, 2017 12:19
Basic Plugin header
<?php
/*
Plugin Name: WordPress.org Plugin
Plugin URI: https://fullstackwp.com
Description: Basic WordPress Plugin Header Comment
Version: 0.1
Author: Varun Kumar
Author URI: https://fullstackwp.com/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
## ENABLE GZIP COMPRESSION ##
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
@imvarunkmr
imvarunkmr / wp-custom_taxonomies.php
Last active April 29, 2017 11:06
Registering a custom taxonomy
<?php
/**
* Add custom taxonomy for project services
*/
add_action( 'init', 'services', 0);
function services() {
$labels = array(
'name' => _x( 'Services', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Service', 'taxonomy singular name', 'textdomain' ),
@imvarunkmr
imvarunkmr / js-ajax_form_submission.js
Last active April 2, 2017 14:10
Processing an ajax form using jQuery
$('form').submit(function(e) {
// get the form data
formData = $(this).serialize();
formData += '&action=submit_contact_form';
// process the form
$.ajax({
type : 'post',
url : localData.ajax_url,
@imvarunkmr
imvarunkmr / wp-ajax_handlers.php
Last active April 2, 2017 15:45
Ajax handlers for WordPress
<?php
add_action( 'wp_ajax_action_slug', 'action_slug' );
add_action( 'wp_ajax_nopriv_action_slug', 'action_slug' );
function action_slug() {
check_ajax_referer('form_nonce');
$errors = array(); // Array to hold validation errors
$data = array(); // Array to pass back data
<?php
add_action( 'wp_enqueue_scripts', 'slug_add_scripts' );
/**
* Register and enqueue scripts and styles.
*/
function slug_add_scripts() {
// enqueuing a stylesheet
// params - $handle, $src, $deps, $version, $media
<?php
// Using init action hook to register post type on loading
add_action( 'init', 'slug_book_init');
/**
* Register a book post type
*/
function slug_book_init() {
$labels = array(
'name' => _x( 'Books', 'post type general name', 'textdomain' ),
'singular_name' => _x( 'Book', 'post type singular name', 'textdomain' ),
@imvarunkmr
imvarunkmr / wp-query-ref.php
Created February 28, 2016 06:24 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@imvarunkmr
imvarunkmr / wooprodcatimg.php
Last active August 29, 2015 14:21
Woocommerce: Get product category images
$thumbnail_id = get_woocommerce_term_meta( $product_cat->term_id, 'thumbnail_id', true );
// get the image thumbnail for any size
$image = wp_get_attachment_image_src( $thumbnail_id, 'small' );
echo '<img src = "' . $image[0] . '" />';