Skip to content

Instantly share code, notes, and snippets.

View sajdoko's full-sized avatar

Sajmir Doko sajdoko

View GitHub Profile
@sajdoko
sajdoko / snowflakes.html
Created December 1, 2023 13:02
Html snowflakes effect built with Js and Css
<!-- HTML -->
<div class="snowflakes" aria-hidden="true"></div>
<!-- JavaScript -->
<script>
const snowflakesContainer = document.querySelector('.snowflakes');
// Number of snowflakes you want to add
const numberOfSnowflakes = 100;
@sajdoko
sajdoko / functions.php
Created August 22, 2023 12:41
Add Kosovo as a checkout country in WooCommerce
<?php
// Add Kosovo as a checkout country
add_filter('woocommerce_countries', 'snippetpress_add_kosovo');
function snippetpress_add_kosovo($countries) {
// Add Kosovo to the list of countries
$countries['XK'] = __('Kosovo', 'woocommerce');
return $countries;
}
@sajdoko
sajdoko / wp-search-replace.sh
Created April 19, 2023 12:44
Bash script that performs the search and replace on each cPanel user's Wordpress page content using mysql command.
#!/bin/bash
# Loop through each WordPress installation directory under /home/*/public_html/
for dir in /home/*/public_html/; do
# Check if the directory contains a wp-config.php file
if [ -f "${dir}wp-config.php" ]; then
echo -e "Processing ${dir}"
# Get the database credentials from wp-config.php
DB_NAME=$(grep "define( 'DB_NAME'" ${dir}wp-config.php | cut -d "'" -f 4)
DB_USER=$(grep "define( 'DB_USER'" ${dir}wp-config.php | cut -d "'" -f 4)
@sajdoko
sajdoko / functions.php
Created April 11, 2023 14:35
Remove "Add to Cart" button and replace it with a "Request Quote" button based on the user's location.
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
// WooCommerce plugin is active class is loaded
function replace_add_to_cart_button() {
// Output the "Request Quote" button
echo '<a href="/contatti/" class="request-quote-button single_add_to_cart_button button alt wp-element-button">Richiedi un preventivo</a>';
return;
}
if (! class_exists( 'WC_Geolocation' ) ) {
@sajdoko
sajdoko / functions.php
Created February 4, 2021 11:56
Limit page visibility only if customer has bought specific product
/**
* Kontrollon aksesin per pruktet
*/
function sajdoko_to_login_if_not_customer() {
global $post;
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
@sajdoko
sajdoko / update-wp-plugins.sh
Last active December 28, 2020 08:29
Bash script to update WordPress Plugins on a server managed with WHM/cPanel
#!/bin/bash
# $1 group (premium||free)
# $2 plugin slug (all||single-name)
if [ "$1" == "premium" ] ; then
if [ "$2" == "all" ] || [ "$2" == "js_composer" ] ; then
if curl -o js_composer.zip https://serverlocalweb.com/js_composer.zip ; then
shkarkova_js_composer="1"
fi
fi
@sajdoko
sajdoko / example-ajax-enqueue.php
Created November 13, 2019 11:00 — forked from devinsays/example-ajax-enqueue.php
Simple WordPress Ajax Example
<?php
function example_ajax_enqueue() {
// Enqueue javascript on the frontend.
wp_enqueue_script(
'example-ajax-script',
get_template_directory_uri() . '/js/simple-ajax-example.js',
array('jquery')
);
@sajdoko
sajdoko / group.php
Last active December 28, 2020 08:34
Skript qe krijon grupet dhe grupon sitet sipas plugineve
<?php
$host = '';
$dbname = '';
$user = '';
$password = '';
try {
$pdo = new PDO("mysql:host=" . $host . ";dbname=" . $dbname, $user, $password);
} catch (PDOException $e) {
die("ERROR: Could not connect. " . $e->getMessage());
@sajdoko
sajdoko / app.js
Last active June 24, 2020 19:58
Custom HTTP Library (Ajax With Callbacks)
const http = new easyHTTP();
// Get Posts
http.get("https://jsonplaceholder.typicode.com/posts", function(err, posts) {
if (err) {
console.log(err);
} else {
console.log(posts);
}
});
function ImportCSV2Array($filename) {
$row = 0;
$col = 0;
$handle = @fopen($filename, "r");
if ($handle) {
while (($row = fgetcsv($handle, 4096)) !== false) {
if (empty($fields)) {
$fields = $row;
continue;
}