Skip to content

Instantly share code, notes, and snippets.

View lxbdr's full-sized avatar

Alex lxbdr

View GitHub Profile
@lxbdr
lxbdr / use-photoswipe.ts
Created January 20, 2025 23:18
Photoswipe hook for react
import 'photoswipe/style.css'
import { type PreparedPhotoSwipeOptions } from 'photoswipe'
import PhotoSwipeLightbox from 'photoswipe/lightbox'
import { useEffect } from 'react'
export function usePhotoswipe(
gallerySelector: string,
options: Partial<Omit<PreparedPhotoSwipeOptions, 'gallery' | 'pswpModule'>> = {}
) {
@lxbdr
lxbdr / wp-upload-existing-filename-filter.php
Created February 27, 2020 12:03
Prevent upload in WordPress media library if there is already a file with the same name.
add_filter( 'wp_handle_upload_prefilter', function ( $file ) {
$uploads = wp_upload_dir();
$use_yearmonth = get_option( 'uploads_use_yearmonth_folders' );
if ( boolval( $use_yearmonth ) ) {
// if upload to year month based folders is enabled check current target
$year = date( 'Y' );
$month = date( 'm' );
$target = $uploads['path'] . DIRECTORY_SEPARATOR . $year . DIRECTORY_SEPARATOR . $month . DIRECTORY_SEPARATOR . $file['name'];
} else {
// uploads dir
@lxbdr
lxbdr / set_translations.sql
Created December 16, 2019 14:15
Set WooCommerce products translation status to "translation complete"
/*
Mark WPML translations that need an update
as completed (needs_update=0)
Change PREFIX to wp table prefix
Adjust WHERE conditions where neccessary
*/
UPDATE
PREFIX_icl_translations AS translations
LEFT JOIN
@lxbdr
lxbdr / validateDigistoreSha.js
Created June 14, 2019 10:13
Validate Digistore24 Thank You Page SHA
function validateDigistoreSha() {
const THANKYOU_PAGE_KEY = "XXXXXXXXXXXXXX";
const data = new URLSearchParams(window.location.search);
function hexString(buffer) {
const byteArray = new Uint8Array(buffer);
const hexCodes = [...byteArray].map(value => {
const hexCode = value.toString(16);