Skip to content

Instantly share code, notes, and snippets.

View ashokmhrj's full-sized avatar

Ashok Maharjan ashokmhrj

  • Web Equation
  • Nepal
View GitHub Profile
@ashokmhrj
ashokmhrj / hook.php
Created March 6, 2020 03:30
setting file permission from parent folder permission
<?php function scan_folders( $path = '', $return = array() ) {
$path = $path == ''? dirname( __FILE__ ) : $path;
$lists = @scandir( $path );
if ( ! empty( $lists ) ) {
foreach ( $lists as $f ) {
if ( is_dir( $path . DIRECTORY_SEPARATOR . $f ) && $f != "." && $f != ".." ) {
if ( ! in_array( $path . DIRECTORY_SEPARATOR . $f, $return ) )
$return[] = trailingslashit( $path . DIRECTORY_SEPARATOR . $f );
<?php
/*source: https://stackoverflow.com/questions/26848825/php-sorting-array-by-id-and-parent-id*/
$arr = array(
array('id' => 1, 'parent' => 0, 'title' => 'XXX1', 'children'=>array()),
array('id' => 85, 'parent' => 0, 'title' => 'XXX2', 'children'=>array()),
array('id' => 41, 'parent' => 0, 'title' => 'XXX2', 'children'=>array()),
array('id' => 17, 'parent' => 0, 'title' => 'XXX3', 'children'=>array()),
array('id' => 66, 'parent' => 1, 'title' => 'XXX4', 'children'=>array()),
array('id' => 92, 'parent' => 1, 'title' => 'XXX5', 'children'=>array()),
@ashokmhrj
ashokmhrj / youtube-vimeo-embed-urls.php
Last active February 9, 2020 07:30 — forked from yoanmarchal/youtube-vimeo-embed-urls.php
PHP Function to Convert Youtube and Vimeo URLs to Lightbox-Ready Equivalents
<?php
/* Forked from : https://gist.github.com/yoanmarchal/4030827 */
/**
* Given a string containing any combination of YouTube and Vimeo video URLs in
* a variety of formats (iframe, shortened, etc), each separated by a line break,
* parse the video string and determine it's valid embeddable URL for usage in
* popular JavaScript lightbox plugins.
*
* In addition, this handler grabs both the maximize size and thumbnail versions
@ashokmhrj
ashokmhrj / woocommerce_show_prices_with_or_without_tax.php
Created October 11, 2019 06:17 — forked from webdados/woocommerce_show_prices_with_or_without_tax.php
Show WooCommerce prices with or without tax / VAT depending on user profile / option
<?php
/* WooCommerce prices shown with or without tax depending on client type */
add_filter( 'option_woocommerce_tax_display_shop', 'woocommerce_show_prices_with_or_without_tax' );
add_filter( 'option_woocommerce_tax_display_cart', 'woocommerce_show_prices_with_or_without_tax' );
function woocommerce_show_prices_with_or_without_tax( $option ) {
if ( is_user_logged_in() ) {
//Client type from user_meta or profile or whatever...
//Example: $client_hide_tax = get_user_meta( get_current_user_id(), 'client_type', true ) ? true : false;
//Example to create this field on registration: https://gist.github.com/webdados/c8dbbe7ccdea3463312e5b865ad92d92
@ashokmhrj
ashokmhrj / WP-HTML-Compression
Created October 28, 2018 07:48 — forked from sethbergman/WP-HTML-Compression
Minify HTML for WordPress without a Plugin - Add to function.php
<?php
class WP_HTML_Compression
{
// Settings
protected $compress_css = true;
protected $compress_js = true;
protected $info_comment = true;
protected $remove_comments = true;
// Variables
@ashokmhrj
ashokmhrj / metabox-repeatable-fields.php
Last active March 25, 2024 03:39 — forked from helen/repeatable-fields-metabox.php
Repeating Custom Fields with Image Uploading and drag n drop in a Metabox
<?php
/**
* Repeatable Custom Fields in a Metabox with Image upload
* Drag and Drop option
* Modified by: ashokmhrj
* Extracted from: Helen Hou-Sandi
*/
define('PATH_TO_JS','define path here');
function ask_admin_repeater_script(){
@ashokmhrj
ashokmhrj / show-meta-data-in-admin-list.php
Last active May 6, 2020 15:23
Showing feature image in admin post listing
/**
* WordPress
* Showing feature image in admin post listing
*/
add_filter('manage_posts_columns' , 'ask_custom_columns');
/*add_filter('manage_{post-type-slug}_posts_columns' , 'ask_custom_columns');*/
function ask_custom_columns( $columns ) {
$columns = array(
@ashokmhrj
ashokmhrj / hooks.php
Created April 17, 2018 11:35
Array sort as per heierachical
<?php
/* Array sort as per heierachical */
function sort_terms_hierarchicaly(Array &$cats, Array &$into, $parentId = 0) {
foreach ($cats as $i => $cat) {
if ( $cat->parent == $parentId ) {
$into[$cat->term_id] = $cat;
unset($cats[$i]);
}
@ashokmhrj
ashokmhrj / woo-hooks.php
Last active February 9, 2023 12:16
Woocommerce sale flash in percentage
<?php
/**
* shows percentage in flash sales
*/
add_filter( 'woocommerce_sale_flash', 'ask_percentage_sale', 11, 3 );
function ask_percentage_sale( $text, $post, $product ) {
$discount = 0;
if ( $product->get_type() == 'variable' ) {
$available_variations = $product->get_available_variations();
@ashokmhrj
ashokmhrj / hooks.php
Last active January 17, 2024 16:04
WooCommerce mnicart qty update
<?php
add_action('woocommerce_widget_shopping_cart_before_buttons','ask_woo_mini_cart_before_buttons' );
function ask_woo_mini_cart_before_buttons(){
wp_nonce_field( 'woocommerce-cart' );
?>
<div class="submit-button">
<input type="submit" class="button" name="update_cart" value="<?php esc_attr_e('Uppdatera varukorg', 'tidymerch'); ?>"/>
</div>
<?php