Skip to content

Instantly share code, notes, and snippets.

@sudipto-me
sudipto-me / Link share in the social media
Created August 18, 2018 09:20
This will give an idea how to share links in the social media using php code. I implement this code in one of my project which based on woocommerce. Happy Coding. Peace...
@sudipto-me
sudipto-me / Upload media image from a form in wordpress
Created August 18, 2018 09:38
This snippet gives the code for uploading image from media. This click event will open the media directory of the wordpress and gives u privilege to upload media image. Happy Coding. Peace
$('#similar_product_two_upload_image_button').on('click', function(e) {
e.preventDefault();
var send_attachment_bkp = wp.media.editor.send.attachment;
wp.media.editor.send.attachment = function(props, attachment) {
$('.similar_product_two_upload_src').attr('src', attachment.url);
$('#similar_product_two_upload_image').attr('value', attachment.url);
wp.media.editor.send.attachment = send_attachment_bkp;
}
wp.media.editor.open();
return false;
@sudipto-me
sudipto-me / Rest Api in wordpress
Created September 14, 2018 07:01
This is my first working with wordpress rest api. Here I get a token in the header and a user-id from the url. By checking them I make a response which show the audio list from the uploads folder.
add_action('rest_api_init',function(){
register_rest_route('uploads','/audios/',array(
'methods'=>'GET',
'callback'=>'meditation_upload_file_auth',
));
});
function meditation_upload_file_auth(WP_REST_Request $request) {
$user_id = isset($_GET['userid'])?(int)$_GET['userid']:'';
$user_data = get_user_by('ID',$user_id);
$token = $request->get_header('token');
@sudipto-me
sudipto-me / Make a add more section using js and php
Last active October 27, 2018 13:50
This gist is for a dynamic add more section in js and php. Here I make a dynamic add more section using js and save this value in the database. With it I show the add more sections using php.
<div class="text-center">
<button class="btn btn-success add-more" type="button">Add More Images</button>
<!--This button will add a new section in the dom using js-->
</div>
//js part:
<script>
var $ =jQuery.noConflict();
$(document).ready(function(e){
var count = <?php echo $php_count; ?>;
$('.add-more').click(function(){
@sudipto-me
sudipto-me / Create-Custom-Fields-in-Woocommerce-Checkout-Page.md
Created September 15, 2018 18:09 — forked from fencermonir/Create-Custom-Fields-in-Woocommerce-Checkout-Page.md
Create Custom Fields in Woocommerce Checkout Page and Display them in Orders Details Page in Admin Area

Create Custom Fields in Woocommerce Checkout Page and Display them in Orders Details Page in Admin Area with this WordPress plugin:

<?php


/**
 * Plugin Name: Flowershop - WooCommerceCustomOverrides
 * Plugin URI: http://chillopedia.com
 * Description: Overrides WooCommerce Checkout Form Fields
  • Version: 1.0
function post_to_url($data) {
$fields = '';
foreach($data as $key=>$value){
if(!empty($value)){
$fields .= $key .'='.$value.'&';
}
}
$substr = substr($fields,-1);
if(substr($fields,-1)=='&') {
$fields = substr($fields,0,-1);
/* -----------------------------------------------------------------------------
* REST API SETUP
* -------------------------------------------------------------------------- */
add_action( 'rest_api_init', function () {
register_rest_route( 'users', '/auth/', array(
'methods' => 'POST',
'callback' => 'meditation_user_auth'
) );
} );
/*
* At first retreive the sidebar list and return it in a array
*/
add_action('admin_init','treeservice_select_sidebar');
function treeservice_select_sidebar() {
$sidebar_list = array();
foreach($GLOBALS['wp_registered_sidebars'] as $sidebar) {
$sidebar_list[$sidebar['id']] = $sidebar['id'];
}
return $sidebar_list;
@sudipto-me
sudipto-me / popupclose.js
Created March 16, 2019 20:05
Pop up Close
$('body').on('click', '#myModal', function (e) {
if ($(e.target).attr('class') == 'practice_modal active') {
console.log('Class found');
$('#myModal').toggleClass('active');
} else {
console.log('Class not found');
}
console.log($(e.target).attr('class'));
});
@sudipto-me
sudipto-me / deferjavascript.php
Created March 25, 2019 08:14
To defer javascript files in the website page speed.
/*Defer Parsing of javascript*/
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' defer ";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );