Skip to content

Instantly share code, notes, and snippets.

@esedic
esedic / backup.txt
Created April 15, 2025 13:53
SSH files backup
tar -czvf - --exclude='mydomain.com/administrator/backups' /var/www/sites/mydomain.com > /local/backup/mydomain_backup.tar.gz
@esedic
esedic / uk_comp.js
Created April 11, 2025 09:21
Uikit Custom Component Example
(function (UIkit) {
if (!UIkit) {
throw new Error('UIkit not found. Make sure UIkit is loaded before this plugin.');
}
UIkit.component('floating-label', {
connected() {
this.initFloatingLabel();
},
methods: {
@esedic
esedic / yt.php
Created March 16, 2025 16:58
Get Youtube video ID from a string with PHP
<?php
abstract class Helper {
public static function getVidId($text) {
if(preg_match('~(?:https?://)?(?:www.)?(?:youtube.com|youtu.be|youtube-nocookie.com)/(?:watch\?v=|embed/)?([^"\?\s]+)~', $introtext, $match)) {
return $match[1]; //
}
}
}
@esedic
esedic / toolbar.less
Created March 12, 2025 16:38
Yootheme - Display Toolbar on Mobile
// YOOtheme > SETTINGS > Custom Code > CSS/LESS:
@media(max-width: @breakpoint-medium-max) {
.tm-toolbar.uk-visible\@m {
display: block !important;
order: -1;
}
.tm-page {
display: flex;
flex-direction: column;
@esedic
esedic / email.php
Created February 24, 2025 11:33
Customizing WordPress User Registration Email
<?php
function custom_registration_email($user_id) {
$user_info = get_userdata($user_id);
$to = $user_info->user_email;
$subject = 'Welcome to our site!';
$message = 'Dear ' . $user_info->display_name . ',<br /><br />';
$message .= 'Thank you for registering on our site. Here is your login information:<br />';
$message .= 'Username: ' . $user_info->user_login . '<br />';
$message .= 'Password: Your chosen password<br /><br />';
@esedic
esedic / config.php
Created February 21, 2025 17:27
Add widget position in Yootheme Pro
<?php
// Create a file config.php with this code in put in child theme
return [
// Set theme configuration values
'theme' => [
'positions' => [
'header-top' => 'Header Top',
@esedic
esedic / wcpricing.php
Created February 19, 2025 17:43
WooCommerce pricing and user roles
<?php
// Set different prices in WooCommerce based on user roles using a hook.
function custom_role_based_pricing( $price, $product ) {
if ( is_user_logged_in() ) {
$user = wp_get_current_user();
// Example: 10% discount for "wholesale" users
if ( in_array( 'wholesale', $user->roles ) ) {
@esedic
esedic / timestamp.php
Last active January 31, 2025 12:12
Set timestamp to Wordpress child theme custom CSS file
<?php
function my_child_theme_enqueue_styles() {
$css_file = get_stylesheet_directory() . '/css/style.css';
$css_url = get_stylesheet_directory_uri() . '/css/style.css';
wp_enqueue_style(
'child-style',
$css_url,
array(), // No dependencies
file_exists($css_file) ? filemtime($css_file) : null // Adds timestamp version
@esedic
esedic / download.html
Created January 28, 2025 12:17
File download methods
<!-- Using the <a> tag's download attribute can trigger a download, but it has limitations -->
<a href="/path/to/file" download>Download</a>
<script>
function download(url) {
const link = document.createElement("a");
link.download = "file name";
link.href = url;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
@esedic
esedic / images.html
Created January 28, 2025 12:15
Display Uploaded Images
<!-- Use the FileReader API's readAsDataURL method to show uploaded images -->
<input type="file" id="uploaded-file" />
<div id="result"></div>
<script>
function readImage() {
const fileReader = new FileReader();
const file = document.getElementById("uploaded-file").files[0];
if (file) {
fileReader.readAsDataURL(file);