Skip to content

Instantly share code, notes, and snippets.

View codetycon's full-sized avatar
🏠
Working from home

codetycon codetycon

🏠
Working from home
  • codetycon
  • Indore India
View GitHub Profile
@codetycon
codetycon / function.php
Created August 21, 2018 17:30
How to remove query parameter from url by parameter name in PHP
/* Function to remove query parameter by name*/
function removeQueryParam($url, $key)
{
return preg_replace('/(?:&|(\?))' . $key . '=[^&]*(?(1)&|)?/i', "$1", $url);
}
//How to use
$url = "https://gist.github.com/?test=false";
$key = "test";
$newURL = removeQueryParam($url,$key);
@codetycon
codetycon / function.php
Created August 21, 2018 17:32
How to add a product thumbnail and product galery from a images URL using php script in WordPress Woocommerce.
<?php
function downloadAndUploadImages($post_id,$post_title,$img,$sku){
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
ini_set('memory_limit','1024M');
$ext = substr(strrchr($img,'.'),1);
// WordPress Upload Directory to Copy to (must be CHMOD to 777)
$uploads = wp_upload_dir();
$copydir = $uploads['path']."/";
// Code to Copy Image to WordPress Upload Directory (Server Must Support file_get_content/fopen/fputs)
@codetycon
codetycon / hideshowpassword.js
Created May 25, 2019 18:24
Show to hide/show password jQuery
jQuery('span.show-password').click(function(){
var passfield = jQuery('input[name="password"]');
if(passfield.attr('type')=='password'){
passfield.attr('type','text');
}else if(passfield.attr('type')=='text'){
passfield.attr('type','password');
}
})
@codetycon
codetycon / uplaodfileusingcurl.php
Created October 29, 2020 14:00
Upload file using PHP curl to API
<?php
function getCurlValue($filepath)
{
$contentType = mime_content_type($filepath);
$filename = basename($filepath);
// PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax