Skip to content

Instantly share code, notes, and snippets.

View lxbdr's full-sized avatar

Alex lxbdr

View GitHub Profile
@lxbdr
lxbdr / plugin.php
Last active June 9, 2025 14:37
Check for runtime file when using wp-scripts --hot and enqueue it. Notify the user via console if SCRIPT_DEBUG is not set to true
<?php
// Constants:
// LX_PLUGIN_DIR absolute path to the plugin directory
// LX_PLUGIN_URL URL to the plugin directory without trailing slash
// LX_PLUGIN_VERSION version of the plugin, e.g. '1.0.0'
\add_action( 'enqueue_block_editor_assets', function() {
$runtime_file = LX_PLUGIN_DIR . '/build/runtime.asset.php';
if ( file_exists( $runtime_file ) ) {
@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);