Skip to content

Instantly share code, notes, and snippets.

View punit5658's full-sized avatar
🏖️
Work anywhere

Punit Patel punit5658

🏖️
Work anywhere
View GitHub Profile
@punit5658
punit5658 / .htaccess
Created June 7, 2016 05:50
Avoid hackers to access .htaccess file and stop to add edit malicious code
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# Strictly disallow .htaccess file
<files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</files>
@punit5658
punit5658 / mage-dbdump-sales-users
Created January 31, 2017 14:43 — forked from seangreen/mage-dbdump-sales-users
Shell Script to Dump / Import Magento Sales and Customers
#!/bin/bash
# VARIABLES
CONFIG_FILE="./app/etc/local.xml"
DUMP_FILE="./var/db-sales-users.sql"
TABLES="sales_bestsellers_aggregated_daily sales_bestsellers_aggregated_monthly sales_bestsellers_aggregated_yearly sales_billing_agreement sales_billing_agreement_order sales_flat_creditmemo sales_flat_creditmemo_comment sales_flat_creditmemo_grid sales_flat_creditmemo_item sales_flat_invoice sales_flat_invoice_comment sales_flat_invoice_grid sales_flat_invoice_item sales_flat_order sales_flat_order_address sales_flat_order_grid sales_flat_order_item sales_flat_order_payment sales_flat_order_status_history sales_flat_quote sales_flat_quote_address_item sales_flat_quote_item sales_flat_quote_item_option sales_flat_quote_payment sales_flat_quote_shipping_rate
sales_flat_shipment sales_flat_shipment_comment sales_flat_shipment_grid sales_flat_shipment_item sales_flat_shipment_track sales_invoiced_aggregated sales_invoiced_aggregated_order sales_order_aggregated_created sales_order_aggregated_updated sales_order_statu
@punit5658
punit5658 / twitter.php
Last active March 20, 2017 08:01
How to get latest twitt from twitter
<?php define('CONSUMER_KEY', 'gNJIDw6Div95Wm8PqAjn0g');
define('CONSUMER_SECRET', 'tGmL9R0RZGmZsjXDA8V7BhfK9fhyOxScnIh4R0');
function get_bearer_token(){
// Step 1
// step 1.1 - url encode the consumer_key and consumer_secret in accordance with RFC 1738
$encoded_consumer_key = urlencode(CONSUMER_KEY);
$encoded_consumer_secret = urlencode(CONSUMER_SECRET);
// step 1.2 - concatinate encoded consumer, a colon character and the encoded consumer secret
$bearer_token = $encoded_consumer_key.':'.$encoded_consumer_secret;
@punit5658
punit5658 / insert_media.php
Created April 21, 2017 14:59
How to insert media programatically from URL in WordPress?
<?php
$post_data = array('post_title' => $post_title);
$imagesrc = migrate_image($image_url, $post_id, $post_title, $post_data);
function migrate_image($image_url, $post_id, $desc, $post_data)
{
// Need to require these files
if (!function_exists('media_handle_upload')) {
require_once ABSPATH . "wp-admin" . '/includes/image.php';
require_once ABSPATH . "wp-admin" . '/includes/file.php';
@punit5658
punit5658 / .htaccess
Created June 7, 2017 12:51
Redirect URL which contain space
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} "images/case-studies-pdf/Case\sStudy\s-\sDelta\sCourt\s-\sInstallation\sof\sRoof\sAccess\sPoints.pdf"
RewriteRule .* http://site.uk/images/case-studies-pdf/Case-Study-Delta-Court-Installation-of-Roof-Access-Points.pdf [R=301,L]
</IfModule>
@punit5658
punit5658 / csv-export.js
Created August 21, 2017 12:21
Export CSV using jQuery.
jQuery(document).ready(function($) {
var newarr = [];
$table = jQuery('table');
var dyarr = [];
$table.find('tr').each(function(){
$(this).find('td font').each(function(){
dyarr.push( $(this).html() ); // Column
});
newarr.push(dyarr); // Row
@punit5658
punit5658 / magento-product-metabox.php
Last active December 6, 2017 05:52
List Magento Product Name, ID and Sku in WordPress side metabox
<?php
function wpdocs_register_meta_boxes() {
add_meta_box( 'product-list-box', __( 'Product List', 'textdomain' ), 'product_list_callback', 'articles','side' );
}
add_action( 'add_meta_boxes', 'wpdocs_register_meta_boxes' );
function product_list_callback(){ ?>
<select name="product_list[]" multiple>
<?php
global $wpdb, $post;
@punit5658
punit5658 / nginx.conf
Last active May 31, 2018 12:13
Nginx Configuration
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_min_length 512;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
@punit5658
punit5658 / functions.php
Last active September 19, 2018 12:53
WordPress pagination when we have created page same slug as post type
<?php
function pnavigation( $wp_query ) {
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'prev_next' => false,
@punit5658
punit5658 / functions.php
Created November 15, 2018 06:59
Enable SKU search in woocommerce
<?php
/**
* Join posts and postmeta tables
*
* @param string $join
* @param WP_Query $query
*
* @see https://iconicwp.com/blog/add-product-sku-woocommerce-search/
*
* @return string