Skip to content

Instantly share code, notes, and snippets.

View manidip's full-sized avatar

Manidip Mandal manidip

  • AurionPro
  • Delhi
View GitHub Profile
@manidip
manidip / wp-taxonomy-dropdown.php
Created May 10, 2018 06:32 — forked from eduardozulian/wp-taxonomy-dropdown.php
Callback function for 'meta_box_cb' argument inside register_taxonomy() that replaces the regular checkboxes with a plain dropdown list
<?php
/**
* Callback function for taxonomy meta boxes
*
* A simple callback function for 'meta_box_cb' argument
* inside register_taxonomy() that replaces the regular
* checkboxes with a plain dropdown list
*
* @param [type] $post [description]
* @param [type] $box [description]
@manidip
manidip / short-number-format.php
Created June 13, 2018 12:12 — forked from RadGH/short-number-format.php
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
@manidip
manidip / wp-upload-image-from-url.php
Created June 14, 2018 06:02 — forked from RadGH/rs_upload_from_url.php
Upload an image to WordPress media gallery from URL
<?php
/**
* Retrieves an image from a URL and uploads it using ld_handle_upload_from_path. See that function for more details.
*
* Note: This function should also work for local file paths as well, but the implementation is slightly different than ld_handle_upload_from_path.
*
* @param $image_url
* @param int $attach_to_post
* @param bool|true $add_to_media
@manidip
manidip / filter-wc-shipping-methods-and-payment-gateways.php
Created June 14, 2018 06:02 — forked from RadGH/filter-wc-shipping-methods-and-payment-gateways.php
Filter woocommerce shipping methods and payment gateway by user role.
<?php
/*
Plugin Name: Homestead Apothecary - Role Based Shipping and Checkout
Plugin URI: http://alchemyandaim.com/
Description: Customizes the availability of shipping methods and checkout gateways based on user role. No settings are available for this plugin, customizations must be made to the plugin directly.
Author: Alchemy + Aim
Author URI: https://alchemyandaim.com/
*/
define( 'HA_RBSC_URL', untrailingslashit( plugin_dir_url( __FILE__ ) ) );
@manidip
manidip / wp-fill-missing-alt-tags.php
Created June 14, 2018 06:03 — forked from RadGH/wp-fill-missing-alt-tags.php
Fill in alt text for images in post content
<?php
/*
If alt text isn't included in image attributes from the_content, it is added in.
And, if alt text is not given, image caption or title will be used instead.
BEFORE:
<img src="http://example.org/image.jpg" alt="This alt text is entered by hand!" width="1500" height="996" />
<img src="http://example.org/image.jpg" alt="" width="1500" height="996" />
<img src="http://example.org/image.jpg" alt='' width="1500" height="996" />
<img src="http://example.org/image.jpg" alt width="1500" height="996" />
@manidip
manidip / wordpress-tinymce.js
Created July 2, 2018 04:29 — forked from RadGH/wordpress-tinymce.js
Get/Set content of a TinyMCE visual or text editor with JavaScript
/*
Based on: http://wordpress.stackexchange.com/questions/42652/#answer-42729
These functions provide a simple way to interact with TinyMCE (wp_editor) visual editor.
This is the same thing that WordPress does, but a tad more intuitive.
Additionally, this works for any editor - not just the "content" editor.
Usage:
@manidip
manidip / gist:dd04a8e47f74616b6269543156343d32
Created July 27, 2018 05:59 — forked from thiamteck/gist:877276
JQuery Datepicker with Month and Year only
$(document).ready(function(){
$(".monthPicker").datepicker({
dateFormat: 'mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
@manidip
manidip / gist:b0dff39c51eb65ae8912485f7f36d95e
Created August 3, 2018 11:57 — forked from subfuzion/gist:1128192
Git Tips: Reset, Clean - Remove untracked files and directories from the working tree when switching branches or checking out different commits.
git reset --hard
git clean -f -d
Description:
============
Git Tips: Remove untracked files and directories from the working
tree when switching branches or checking out different commits.
Explanation:
@manidip
manidip / arrayDifference.php
Created August 9, 2018 12:13 — forked from cjthompson/arrayDifference.php
PHP: Compare two arrays and find the differences between them. Supports items that are arrays by serializing them for comparison. Returns an array of insertions (only in the second array) and deletions (only in the first array).
<?php
/**
* Compare two arrays and return a list of items only in array1 (deletions) and only in array2 (insertions)
*
* @param array $array1 The 'original' array, for comparison. Items that exist here only are considered to be deleted (deletions).
* @param array $array2 The 'new' array. Items that exist here only are considered to be new items (insertions).
* @param array $keysToCompare A list of array key names that should be used for comparison of arrays (ignore all other keys)
* @return array[] array with keys 'insertions' and 'deletions'
*/
public static function arrayDifference(array $array1, array $array2, array $keysToCompare = null) {
@manidip
manidip / script.js
Created August 27, 2018 14:05 — forked from tanmay27vats/script.js
Custom Add to cart WooCommerce, Refresh fragments data, Refresh cart total items, Get product variation
product_add_to_cart : function(){
var ajx_data = {};
var ajx_grab = {};
$(document).on('change','.single-product .variations_form select',function(e){
var $this = $(this);
var pro_id = $(".single-product .variations_form").attr('data-product_id');
var attribute_name = $this.attr('data-attribute_name');
var attribute_value = $this.val();
var post_ajxurl = window.location+"?wc-ajax=get_variation";